-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DEPR: deprecate fastpath keyword in Index constructors #23110
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import operator | ||
from datetime import timedelta | ||
from sys import getsizeof | ||
import warnings | ||
|
||
import numpy as np | ||
|
||
|
@@ -68,10 +69,14 @@ class RangeIndex(Int64Index): | |
_engine_type = libindex.Int64Engine | ||
|
||
def __new__(cls, start=None, stop=None, step=None, | ||
dtype=None, copy=False, name=None, fastpath=False): | ||
dtype=None, copy=False, name=None, fastpath=None): | ||
|
||
if fastpath: | ||
return cls._simple_new(start, stop, step, name=name) | ||
if fastpath is not None: | ||
warnings.warn("The 'fastpath' keyword is deprecated, and will be " | ||
"removed in a future version.", | ||
FutureWarning, stacklevel=2) | ||
if fastpath: | ||
return cls._simple_new(start, stop, step, name=name) | ||
|
||
cls._validate_dtype(dtype) | ||
|
||
|
@@ -174,7 +179,7 @@ def _data(self): | |
|
||
@cache_readonly | ||
def _int64index(self): | ||
return Int64Index(self._data, name=self.name, fastpath=True) | ||
return Int64Index._simple_new(self._data, name=self.name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shallow_copy? ditto below There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not in this case, since it is not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One case below is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And actually, Might be a bit buggy in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are u changing these constructors at all? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not changing anything. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
|
||
def _get_data_as_items(self): | ||
""" return a list of tuples of start, stop, step """ | ||
|
@@ -262,8 +267,8 @@ def tolist(self): | |
@Appender(_index_shared_docs['_shallow_copy']) | ||
def _shallow_copy(self, values=None, **kwargs): | ||
if values is None: | ||
return RangeIndex(name=self.name, fastpath=True, | ||
**dict(self._get_data_as_items())) | ||
return RangeIndex._simple_new( | ||
name=self.name, **dict(self._get_data_as_items())) | ||
else: | ||
kwargs.setdefault('name', self.name) | ||
return self._int64index._shallow_copy(values, **kwargs) | ||
|
@@ -273,8 +278,8 @@ def copy(self, name=None, deep=False, dtype=None, **kwargs): | |
self._validate_dtype(dtype) | ||
if name is None: | ||
name = self.name | ||
return RangeIndex(name=name, fastpath=True, | ||
**dict(self._get_data_as_items())) | ||
return RangeIndex._simple_new( | ||
name=name, **dict(self._get_data_as_items())) | ||
|
||
def _minmax(self, meth): | ||
no_steps = len(self) - 1 | ||
|
@@ -374,7 +379,7 @@ def intersection(self, other): | |
tmp_start = first._start + (second._start - first._start) * \ | ||
first._step // gcd * s | ||
new_step = first._step * second._step // gcd | ||
new_index = RangeIndex(tmp_start, int_high, new_step, fastpath=True) | ||
new_index = RangeIndex._simple_new(tmp_start, int_high, new_step) | ||
|
||
# adjust index to limiting interval | ||
new_index._start = new_index._min_fitting_element(int_low) | ||
|
@@ -552,7 +557,7 @@ def __getitem__(self, key): | |
stop = self._start + self._step * stop | ||
step = self._step * step | ||
|
||
return RangeIndex(start, stop, step, name=self.name, fastpath=True) | ||
return RangeIndex._simple_new(start, stop, step, name=self.name) | ||
|
||
# fall back to Int64Index | ||
return super_getitem(key) | ||
|
@@ -565,12 +570,12 @@ def __floordiv__(self, other): | |
start = self._start // other | ||
step = self._step // other | ||
stop = start + len(self) * step | ||
return RangeIndex(start, stop, step, name=self.name, | ||
fastpath=True) | ||
return RangeIndex._simple_new( | ||
start, stop, step, name=self.name) | ||
if len(self) == 1: | ||
start = self._start // other | ||
return RangeIndex(start, start + 1, 1, name=self.name, | ||
fastpath=True) | ||
return RangeIndex._simple_new( | ||
start, start + 1, 1, name=self.name) | ||
return self._int64index // other | ||
|
||
@classmethod | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the performance implication of using _simple_new vs just Int64Index(...)? If its sufficiently small, we should be using the public constructors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relatively it is a big difference:
but if that will be significant in actual code, I don't know.
But since we are using that in many places, I leave changing
_simple_new
calls to the public constructor for another PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jbrockmendel this leads a bit further, but given that the public constructors (
__init__
) of Index classes are very complex (something we will not be able to change I think), I think that we need to see_simple_new
as kind of a "internal public" method within the pandas code base.