Repository: napari/napari

Issue:
[test-bot] Comprehensive tests failing
The Comprehensive Test workflow failed on 2022-12-20 18:07 UTC

The most recent failing test was on macos-latest py3.9 
with commit: 59cd8a5f58e559f5032c40aac4d5dca9c82df4b1

Full run: https://github.com/napari/napari/actions/runs/3742847471

(This post will be updated if another test fails, as long as this issue remains open.)



Discussion:
Pretty sure this is due to the [numpy minor version release](https://pypi.org/project/numpy/1.24.0/) on 2022/12/18. I assume the new version is stricter about casts from nan (or something similar to that).

We can prevent use of that version temporarily to make tests pass again, or probably better fix the tests that now fail.
Likely coming from https://github.com/numpy/numpy/pull/21437, which was included in 1.24.0

I see we explicitly set the extent for all empty non-image layers (e.g. see [`Points._data_extent`](https://github.com/napari/napari/blob/b9e613acdcd088e61634e5dbdc553c942eb5a75d/napari/layers/points/points.py#L704)), to be full of nans. That's intuitively correct to me because if there's no data, then the extent isn't really defined, so I prefer nans over zeros.

But this breaks down with `Layer.corner_pixels`, since that is defined in data space and has integer values. That attribute is only really useful (inside napari) for 2D visualization of multi-scale image layers, but we also try to keep it up-to-date in general (which is where this warning is coming from) and it is part of the public/documented API. When there is no data and the extent is undefined, we'll eventually try to set a nan on an int array, so this warning is rightly issued.

I think the best quick fix is to check for an all-nan extent in `Layer._update_draw`, and just set corner pixels to zeros in this case. We could ignore the warning with a context manager, but that might hide more real failures. I think the best long term fix is to find some way to remove `Layer.corner_pixels` and capture it in slice input/requests instead.

@sofroniewn : as best as I can work out, you decided on nans in https://github.com/napari/napari/pull/1360 . That was over 2 years ago, but curious if you remember any thoughts here?

Resolving patch:
diff --git a/napari/layers/base/base.py b/napari/layers/base/base.py
--- a/napari/layers/base/base.py
+++ b/napari/layers/base/base.py
@@ -1545,12 +1545,16 @@ def _update_draw(
 
         else:
             # The stored corner_pixels attribute must contain valid indices.
-            displayed_extent = self.extent.data[:, displayed_axes]
-            data_bbox_clipped = np.clip(
-                data_bbox_int, displayed_extent[0], displayed_extent[1]
-            )
             corners = np.zeros((2, self.ndim), dtype=int)
-            corners[:, displayed_axes] = data_bbox_clipped
+            # Some empty layers (e.g. Points) may have a data extent that only
+            # contains nans, in which case the integer valued corner pixels
+            # cannot be meaningfully set.
+            displayed_extent = self.extent.data[:, displayed_axes]
+            if not np.all(np.isnan(displayed_extent)):
+                data_bbox_clipped = np.clip(
+                    data_bbox_int, displayed_extent[0], displayed_extent[1]
+                )
+                corners[:, displayed_axes] = data_bbox_clipped
             self.corner_pixels = corners
 
     def _get_source_info(self):


Test patch: