-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Series(range_obj_outside_i8_bounds) #41579
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 |
---|---|---|
|
@@ -502,7 +502,7 @@ def sanitize_array( | |
data = lib.item_from_zerodim(data) | ||
elif isinstance(data, range): | ||
# GH#16804 | ||
data = np.arange(data.start, data.stop, data.step, dtype="int64") | ||
data = range_to_ndarray(data) | ||
copy = False | ||
|
||
if not is_list_like(data): | ||
|
@@ -569,6 +569,25 @@ def sanitize_array( | |
return subarr | ||
|
||
|
||
def range_to_ndarray(rng: range) -> np.ndarray: | ||
""" | ||
Cast a range object to ndarray. | ||
""" | ||
# GH#30171 perf avoid realizing range as a list in np.array | ||
try: | ||
arr = np.arange(rng.start, rng.stop, rng.step, dtype="int64") | ||
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. isn't this very simliar to maybe_cast_to_integer_array and generate_regular_range 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. maybe_cast_to_integer_array no, thats the crux of #40110 generate_regular_range conceptually, but they take different args so ill have to take a closer look 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 as long as its on the refactor / restructure list |
||
except OverflowError: | ||
# GH#30173 handling for ranges that overflow int64 | ||
if (rng.start >= 0 and rng.step > 0) or (rng.stop >= 0 and rng.step < 0): | ||
try: | ||
arr = np.arange(rng.start, rng.stop, rng.step, dtype="uint64") | ||
except OverflowError: | ||
arr = construct_1d_object_array_from_listlike(list(rng)) | ||
else: | ||
arr = construct_1d_object_array_from_listlike(list(rng)) | ||
return arr | ||
|
||
|
||
def _sanitize_ndim( | ||
result: ArrayLike, data, dtype: DtypeObj | None, index: Index | None | ||
) -> ArrayLike: | ||
|
Uh oh!
There was an error while loading. Please reload this page.