Conversation
| import pytest | ||
| import xarray as xr | ||
| import zarr | ||
| from numpy.core.numerictypes import issubdtype |
There was a problem hiding this comment.
Simple fix to import from the public API (already used once in this file):
__________________________________________________________________________________ ERROR collecting napari/layers/labels/_tests/test_labels.py ___________________________________________________________________________________
napari/layers/labels/_tests/test_labels.py:14: in <module>
from numpy.core.numerictypes import issubdtype
numpy2-venv/lib/python3.11/site-packages/numpy/core/numerictypes.py:8: in __getattr__
_raise_warning(attr_name, "numerictypes")
numpy2-venv/lib/python3.11/site-packages/numpy/core/_utils.py:10: in _raise_warning
warnings.warn(
E DeprecationWarning: numpy.core.numerictypes is deprecated and has been renamed to numpy._core.numerictypes. The numpy._core namespace contains private NumPy internals and its use is discouraged, as NumPy internals can change without warning in any release. In practice, most real-world usage of numpy.core is to access functionality in the public NumPy API. If that is the case, use the public NumPy API. If not, you are using NumPy internals. If you would still like to access an internal attribute, use numpy._core.numerictypes.issubdtype.
| # calculate distance to line (2D cross-product) | ||
| line_dist = abs( | ||
| unit_lines[..., 0] * point_vectors[..., 1] | ||
| - unit_lines[..., 1] * point_vectors[..., 0] | ||
| ) |
There was a problem hiding this comment.
np.cross is deprecated for 2D inputs. Here is some discussion about alternatives:
numpy/numpy#26620
I think this fix is okay as it seems this function is already restricted to 2D-only.
Below in this file this function is used again, but for 3D input. We might want to use np.linalg.cross instead, but it's only available in numpy 2.0 so ¯_(ツ)_/¯.
| color_cycle_map = getattr(self, f'{attribute}_color_cycle_map') | ||
| color_cycle_keys = [*color_cycle_map] | ||
| props_in_map = np.in1d(color_properties, color_cycle_keys) | ||
| props_in_map = np.isin(color_properties, color_cycle_keys) |
There was a problem hiding this comment.
in1d is deprecated and isin is the suggested replacement. I'm pretty sure for this use it is a drop-in replacement. I believe isin can be slower for certain array dtypes (object), but I'm not sure that's an issue here.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6974 +/- ##
==========================================
- Coverage 92.56% 92.51% -0.06%
==========================================
Files 611 611
Lines 55295 55296 +1
==========================================
- Hits 51182 51155 -27
- Misses 4113 4141 +28 ☔ View full report in Codecov by Sentry. |
|
I assume that running the tests locally with numpy 2 also requires having the following vispy changes in that same env? vispy/vispy#2599 |
|
Yep - there are wheels in the CI artifacts for that branch you can download, or build it locally. |
jni
left a comment
There was a problem hiding this comment.
Nice, thanks for all the individual explanations @aganders3! Made this very easy to go through. 😊
References and relevant issues
I don't see a tracking issue for numpy 2.0 support, but here are some previous PRs I've found:
#6932
#6776
And a zulip thread:
https://napari.zulipchat.com/#narrow/stream/212875-general/topic/handling.20the.20numpy.202.2E0.20release/near/381330412
Description
This fixes a few more numpy-2.0 related issues. I will comment on some of them inline.
I tested locally using a wheel from my vispy PR. I also uninstalled
tensorstoreto skip related tests (see google/tensorstore#165).There are still a few test failures in
napari/layers/image/_tests/test_image.pythat look possibly related to Xarray:I also get a failure on
napari/_qt/widgets/_tests/test_qt_tooltip.py::test_qt_tooltip_label, but I think this may be a macOS thing (it passes if I mouse over it).Other than that, local tests with
pytest napariare all green.