Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork10.9k
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 ourterms of service andprivacy 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?
Uh oh!
There was an error while loading.Please reload this page.
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.Fixesnumpy#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 ifp
is empty? Orp
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 ifp
is empty or a 2D array. my changes only affected the case wherep
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 fornp.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 meIndexError: 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) |
eendebakptMay 6, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
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.