Skip to content
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

Change in type promotion. Fixes to _signal.py #507

Merged
merged 2 commits into from
Oct 16, 2024
Merged

Change in type promotion. Fixes to _signal.py #507

merged 2 commits into from
Oct 16, 2024

Conversation

tompollard
Copy link
Member

As discussed in #493, numpy v2.0 introduced changes to type promotion rules: https://numpy.org/devdocs/numpy_2_0_migration_guide.html#changes-to-numpy-data-type-promotion

Running pytest with numpy==2.0.2 and NPY_PROMOTION_STATE=weak_and_warn raises the following warning for wfdb/io/_signal.py:

tests/test_record.py::TestRecord::test_1a
  /Users/tompollard/projects/wfdb-python/wfdb/io/_signal.py:2374: UserWarning: result dtype changed due to the removal of value-based promotion from NumPy. Changed from int32 to int16.
    d_signal[d_signal < 0] = d_signal[d_signal < 0] + 65536

The changes in this pull request address these issues by explicitly casting the type. I also make a couple of minor modifications for efficiency (switching to inplace addition). I plan to follow up with several additional fixes to other modules.

Addresses warning when NPY_PROMOTION_STATE=weak_and_warn that result dtype changed due to the removal of value-based promotion from NumPy. Changed from int32 to int16.
Modify the arrays in place.
@cbrnr cbrnr mentioned this pull request Oct 10, 2024
@tompollard tompollard requested a review from bemoody October 10, 2024 15:57
@tompollard
Copy link
Member Author

Thanks Benjamin

@tompollard tompollard merged commit 9c20204 into main Oct 16, 2024
14 checks passed
@tompollard tompollard deleted the tp/493-2 branch October 16, 2024 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants