-
Notifications
You must be signed in to change notification settings - Fork 303
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
OverflowError: Python integer 256 out of bounds for uint8 #493
Comments
It looks like the package needs fixing. I assume this is a result of the following change to numpy: https://numpy.org/devdocs/release/1.24.0-notes.html#conversion-of-out-of-bound-python-integers |
No, it's not a 1.24 issue:
|
https://numpy.org/devdocs/numpy_2_0_migration_guide.html#changes-to-numpy-data-type-promotion This is a major change & worries me there are likely to be other things invisibly broken. For the time being, there are two workarounds:
To find problems that need fixing, you can set Here are the warnings on the current test suite:
(there are some DeprecationWarnings too; that's another story...) |
Numpy v2 introduces a breaking change for WFDB https://numpy.org/devdocs/numpy_2_0_migration_guide.html#changes-to-numpy-data-type-promotion. Set an upper bound on the Numpy version until the issue has been addressed.
… (#494) As discussed in #493, numpy v2.0.0 introduces a breaking change for WFDB: https://numpy.org/devdocs/numpy_2_0_migration_guide.html#changes-to-numpy-data-type-promotion. This pull request sets an upper bound on the numpy version as a temporary fix (`numpy = ">=1.10.1,<2.0.0"`).
@bemoody and @tompollard , thanks for the heads up on numpy version, I have "downgraded" numpy and it works. BR. |
I had the same issue and can confirm downgrading to |
May I ask if a more permanent fix (i.e. upgrading to NumPy >= 2) is planned in the near future? One of my packages depends on wfdb, and I cannot upgrade to NumPy >= 2 because of this pin. |
This is definitely an important issue that needs fixing. Help is always appreciated! But I'll try to devote some time to it this week, and at least get a better idea of how much work it'll be to fix. |
Sure, I'm happy to help, but given you are already familiar with the code, and you already listed the warnings, this might not be too difficult. You'd have to specify which dtype you want in these cases, which is something I cannot help with. |
I'm a little worried that the test suite doesn't contain the |
Yes, figuring that out could be tricky. I'm assuming that most of the code has (at some point) been tested using numpy 1.x, with its C-like promotion semantics, and therefore we should assume those semantics are what we want to preserve. But, although I have a high-level understanding of the code, I didn't write most of it. :)
You're right, but I think using "weak_and_warn" mode should help. In my comment above, I saw that it reported a UserWarning on annotation.py lines 2239 and 2240, so it does tell us there's a potential problem there. On the other hand, I'm not sure whether "weak_and_warn" mode is something that the numpy package intends to support in the long term. |
Hi there. My team is also using wfdb extensively and we are planing to bump to numpy 2.1.1 and we just encountered this issue. Is there any plan for a wfdb version package release with numpy upper bound so that we can manage in other tomls whether we use one or another numpy version? Thanks for the work |
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 warnings for wfdb/io/annotation.py: ``` /Users/tompollard/projects/wfdb-python/wfdb/io/annotation.py:2222: UserWarning: result dtype changed due to the removal of value-based promotion from NumPy. Changed from int64 to uint8. while filebytes[bpi, 1] >> 2 == 59: /Users/tompollard/projects/wfdb-python/wfdb/io/annotation.py:2239: UserWarning: result dtype changed due to the removal of value-based promotion from NumPy. Changed from int64 to uint8. label_store = filebytes[bpi, 1] >> 2 tests/test_plot.py::TestPlotInternal::test_get_plot_dims /Users/tompollard/projects/wfdb-python/wfdb/io/annotation.py:2240: UserWarning: result dtype changed due to the removal of value-based promotion from NumPy. Changed from int64 to uint8. sample_diff += int(filebytes[bpi, 0] + 256 * (filebytes[bpi, 1] & 3)) ``` The changes in this pull request address these issues by explicitly casting the type. I plan to follow up with several additional fixes to other modules.
I wanted to mention another point: with a NumPy < 2 pin, it is not (easily) possible to support Python 3.13 (which was released last week), since there are no 3.13 wheels for NumPy 1.x. |
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.
This should now be fixed by #511 (and of course all previous related PRs that fixed issues related to NumPy 2). |
I am breaking the demos in the notebook in individual scripts to get acquainted with the package to learn how it works and adapt it to my needs.
Running demo4 as a separate script with python I get this error traceback:
The same happens with Linux (Ubuntu 22.04).
After changing the highlighted line it works like the notebook.
EDIT:
Python versions
Windows: 3.12.4
Linux: 3.10.12
The text was updated successfully, but these errors were encountered: