Ensure compatibility with NumPy 2.0#6156
Conversation
|
The two remaining test failures as of opening this PR come from pyvista/pyvista/core/filters/image_data.py Lines 421 to 434 in b8c4dc4 Now, it would be easy to tweak that filter (probably by removing the NumPy version condition, depending on how our CI matrix looks on various OSes), but we seem to have this logic: "linux/mac doesn't threshold correctly on NumPy < 2.0", but now it also doesn't threshold on NumPy 2.0 (at least on my Linux). I have a suspicion that what's really going on is "it only works on Windows, NumPy < 2.0" which would likely have to do with the fact that "Windows NumPy < 2.0" is the only system where the default int size has 32 bits (this was fiiiinally fixed for NumPy 2.0). So I want to take a closer look at this thresholding logic to see what's really going on here. I suspect it's Windows with NumPy < 2.0 that's somehow broken and needs to be special cased... |
|
Ping @MatthewFlamm. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6156 +/- ##
==========================================
- Coverage 97.09% 97.09% -0.01%
==========================================
Files 141 141
Lines 25939 25937 -2
==========================================
- Hits 25185 25183 -2
Misses 754 754 |
See #6100. The issue with This may not be NumPy 2.0 specific. I think I added this condition EDIT: By "I think these checks always passed" , I mean that there is always green checkmark. So, the actual 2.0 tests may have still been failing for these builds, but the workflow was marked nevertheless marked as "succeeded" |
|
Thanks for the tips @user27182. |
I had a look at the CI logs for #6100. The checks from the first few commits show failing tests (i.e. the bug is present) for all macos/linux workflows. And if we look at the NumPy2.0 tests, we can see they also failed here: This confirms that using NumPy 2.0 did not fix this issue, so the condition can be removed. So, the logic could be changed to something like: # Integer scalars won't threshold correctly on some systems. Cast to float in these cases.
has_int_dtype = np.issubdtype(
array_dtype := self.active_scalars.dtype,
int,
) and array_dtype != np.dtype(np.uint8)
if has_int_dtype and platform.system() in ['Darwin', 'Linux']:
self[scalars] = self[scalars].astype(float, casting='safe') |
|
I've now checked a local build with NumPy 1.26.4 and nightly, and I get the exact same warnings (so all the image regression warnings I see are unrelated). Although some warnings could/should be fixed, they don't concern the NumPy version bump, I'll only have to look at the errors (which we've already discussed). |
|
What's the general feeling about fixing unrelated warnings such as these here? Of course only ones that can be fixed trivially. E.g. there's a warning from |
The warnings from |
|
I've opened #6210 to temporarily give an upper version pin for our NumPy dependency. Cross-posting my plan here because it's also relevant to this PR:
Feedback is welcome on either PR :) |
|
This PR is the critical one to prevent additional regressions we need a green CI for other PRs. I would vote for making the numpy check mandatory in this PR if all the fixes are included. This ensures we don't backslide as we figure out the other pieces. |
|
Thanks @MatthewFlamm, that was also precisely my plan :) |
|
I tested removing the check for numpy version as in @adeak do you have time to close this out soon? If not, I can make the changes needed to get this green and mandatory in the CI. To make mandatory in the CI, we need to remove the two |
|
Thanks @MatthewFlamm, I originally made the test mandatory on my branch, I just reverted that so as not to conflict with your numpy nightly PR. I also know the version check removal "works", I just wanted to take a closer look at how it's broken without the check (but I probably won't do that). I can wrap this up on the weekend if that's an acceptable time frame. |
Co-authored-by: user27182 <89109579+user27182@users.noreply.github.com>
| - python-version: "3.12" | ||
| vtk-version: "latest" | ||
| numpy-version: "pre" | ||
| numpy-version: "nightly" |
There was a problem hiding this comment.
Renamed this for clarity. We can name it back when we revert to pre-releases once 2.0 is released (if we want to do that).
|
This is ready for review. |
Warnings: I'm not sure why I don't see some of the chart warnings in a local build. But the remaining warnings seem to be
|
|
Hi @tkoyama010 @banesullivan @MatthewFlamm! Following the merge of this PR, are you expecting to release a new minor version of PyVista that supports Numpy 2.x? Is there any tentative date for that? |
Thanks for pointing this. This is labelled as "bug". So I will make patch release for this :) |
* Fix NumPy 2.0 errors from np.array(..., copy=False) * Update pyvista_ndarray.__array_wrap__() wrapping * Make garbage collection test output more informative * Prevent some warnings during testing * Remove NumPy version cap from pyproject.toml * Make nightly numpy build mandatory * Refactor array casting based on review comment Co-authored-by: user27182 <89109579+user27182@users.noreply.github.com> * Remove spurious NumPy major version check * Prevent glyph color_mode test warnings * Clean up float points in polydata tests --------- Co-authored-by: user27182 <89109579+user27182@users.noreply.github.com> Co-authored-by: Tetsuo Koyama <tkoyama010@gmail.com>

Handle remaining NumPy 2.0 compatibility issues.
pyvista_ndarray.__array_wrap__()scalar return logic should be different -> not yetImageData.image_threshold()special casing and related errorsCloses #5533.