-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Refine validation of parameters to RangeIndex.__init__ #12295
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
Changes from all 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 |
---|---|---|
|
@@ -23,13 +23,14 @@ class RangeIndex(Int64Index): | |
|
||
Parameters | ||
---------- | ||
start : int (default: 0) | ||
start : int (default: 0), or other RangeIndex instance. | ||
If int and "stop" is not given, interpreted as "stop" instead. | ||
stop : int (default: 0) | ||
step : int (default: 1) | ||
name : object, optional | ||
Name to be stored in the index | ||
copy : bool, default False | ||
Make a copy of input if its a RangeIndex | ||
Unused, accepted for homogeneity with other index types. | ||
|
||
""" | ||
|
||
|
@@ -46,20 +47,17 @@ def __new__(cls, start=None, stop=None, step=None, name=None, dtype=None, | |
|
||
# RangeIndex | ||
if isinstance(start, RangeIndex): | ||
if not copy: | ||
return start | ||
if name is None: | ||
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. the issue is that 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 don't follow you on |
||
name = getattr(start, 'name', None) | ||
start, stop, step = start._start, start._stop, start._step | ||
name = start.name | ||
return cls._simple_new(name=name, | ||
**dict(start._get_data_as_items())) | ||
|
||
# validate the arguments | ||
def _ensure_int(value, field): | ||
try: | ||
new_value = int(value) | ||
except: | ||
new_value = value | ||
|
||
if not com.is_integer(new_value) or new_value != value: | ||
assert(new_value == value) | ||
except (ValueError, AssertionError): | ||
raise TypeError("RangeIndex(...) must be called with integers," | ||
" {value} was passed for {field}".format( | ||
value=type(value).__name__, | ||
|
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.
no, this is not right