-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
REF: Index.__new__ #38665
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
REF: Index.__new__ #38665
Changes from all commits
0542c4b
c897c60
7e5b6b9
159a65b
86c28e6
cb89ead
8dc0330
6edc9a7
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 |
---|---|---|
|
@@ -46,11 +46,20 @@ class NumericIndex(Index): | |
_can_hold_strings = False | ||
|
||
def __new__(cls, data=None, dtype=None, copy=False, name=None): | ||
cls._validate_dtype(dtype) | ||
name = maybe_extract_name(name, data, cls) | ||
|
||
# Coerce to ndarray if not already ndarray or Index | ||
subarr = cls._ensure_array(data, dtype, copy) | ||
return cls._simple_new(subarr, name=name) | ||
|
||
@classmethod | ||
def _ensure_array(cls, data, dtype, copy: bool): | ||
""" | ||
Ensure we have a valid array to pass to _simple_new. | ||
""" | ||
cls._validate_dtype(dtype) | ||
|
||
if not isinstance(data, (np.ndarray, Index)): | ||
# Coerce to ndarray if not already ndarray or Index | ||
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. can use _ensure_array on L81 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. L81 is inside ensure_array 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. oh i c, i guess i meant can you use the super class version 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. theres really only one line that gets shared, i dont think its worth it (for now at least) |
||
if is_scalar(data): | ||
raise cls._scalar_data_error(data) | ||
|
||
|
@@ -74,7 +83,7 @@ def __new__(cls, data=None, dtype=None, copy=False, name=None): | |
raise ValueError("Index data must be 1-dimensional") | ||
|
||
subarr = np.asarray(subarr) | ||
return cls._simple_new(subarr, name=name) | ||
return subarr | ||
|
||
@classmethod | ||
def _validate_dtype(cls, dtype: Dtype) -> None: | ||
|
Uh oh!
There was an error while loading. Please reload this page.