-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
BUG: Fix unwrap function for object arrays with large numbers. #28911
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
base: main
Are you sure you want to change the base?
Conversation
Implemented special handling for object arrays in np.unwrap to correctly unwrap sequences containing very large numbers (e.g., >10^50). The fix properly implements period-based unwrapping logic for object arrays, ensuring consistent increments that respect the specified period parameter. Fixes numpy#27686.
dd = diff(p, axis=axis) | ||
|
||
if p.dtype == np.object_: | ||
initial_value = p[0] |
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 if p
is empty? Or p
is a 2D array?
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.
the function should work properly if p
is empty or a 2D array. my changes only affected the case where p
is an object
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 happens for np.unwrap(np.array([], dtype=object))
?
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.
you're right. it gives me IndexError: index 0 is out of bounds for axis 0 with size 0
. I'll work on a solution for this
initial_value = p[0] | ||
unwrapped = [initial_value] | ||
for val in p[1:]: | ||
unwrapped.append(unwrapped[-1] + 1) |
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.
Appending in a for loop will be much slower than the current implementation for larger arrays.
Do you know the root cause of the problem for bigints? Perhaps we can modify the algorithm at that point. I checked that the first step (e.g. np.diff(p, axis=axis)
) works fine
Implemented special handling for object arrays in np.unwrap to correctly unwrap sequences containing very large numbers (e.g., >10^50). The fix properly implements period-based unwrapping logic for object arrays, ensuring consistent increments that respect the specified period parameter. Fixes #27686.