Skip to content

coerce to dtype after creation#2939

Merged
j9ac9k merged 1 commit intopyqtgraph:masterfrom
pijyoi:fix-numpy2-coerce
Feb 17, 2024
Merged

coerce to dtype after creation#2939
j9ac9k merged 1 commit intopyqtgraph:masterfrom
pijyoi:fix-numpy2-coerce

Conversation

@pijyoi
Copy link
Copy Markdown
Contributor

@pijyoi pijyoi commented Feb 17, 2024

this is a compatibility fix for Numpy 2.0.
creating an array with dtype now fails if the value does not fit within the dtype.

Numpy 1.x behavior

>>> np.array([-1.0], dtype=np.uint32)
array([4294967295], dtype=uint32)
>>> np.array([-1.0]).astype(np.uint32)
array([4294967295], dtype=uint32)

Numpy 2.0 behavior

>>> np.array([-1.0], dtype=np.uint32)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: Python integer -1 out of bounds for uint32
>>> np.array([-1.0]).astype(np.uint32)
array([4294967295], dtype=uint32)

this is a compatibility fix for Numpy 2.0.
creating an array with dtype now fails if the value does not fit within
the dtype.
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Feb 17, 2024

Thanks @pijyoi !

@j9ac9k j9ac9k merged commit d8559ce into pyqtgraph:master Feb 17, 2024
@pijyoi pijyoi deleted the fix-numpy2-coerce branch February 17, 2024 22:21
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