Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Closed
wants to merge 2 commits into from

Conversation

sim0es
Copy link

@sim0es sim0es commented May 6, 2025

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.

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]
Copy link
Contributor

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?

Copy link
Author

@sim0es sim0es May 12, 2025

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

Copy link
Contributor

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))?

Copy link
Author

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)
Copy link
Contributor

@eendebakpt eendebakpt May 6, 2025

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

numpy/lib/_function_base_impl.py Outdated Show resolved Hide resolved
numpy/lib/tests/test_function_base.py Outdated Show resolved Hide resolved
@melissawm melissawm moved this to Awaiting a code review in NumPy first-time contributor PRs May 22, 2025
@sim0es sim0es closed this Jun 11, 2025
@github-project-automation github-project-automation bot moved this from Awaiting a code review to Completed in NumPy first-time contributor PRs Jun 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging this pull request may close these issues.

BUG: np.unwrap returns incorrect values for bigints
3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.