Repository: napari/napari

Issue:
lots of warnings creeping back into tests
after #1538, the tests summary was clean no warnings.  looks like a lot of warnings have crept back into the tests (particularly from the shapes deprecation warning in #1771).  just a reminder that the `[tool.pytest.ini_options]` section of `pyproject.toml` will let you batch ignore warnings if you know they are negligible.


Discussion:
Was trying to have a look into this, but on all tests producing warnings, if I try to follow the warning message suggestion, I find that there's always an offset of 1 between the `data` or `world` attributes and the `shape` attribute. Is that expected?
```python
ipdb> layer.shape
(40, 20)

ipdb> layer.extent.data
array([[ 0.,  0.],
       [39., 19.]])
ipdb> layer.extent.world
array([[ 0.,  0.],
       [39., 19.]])
```
Yes, I think it's expected. See [this discussion](https://github.com/napari/napari/issues/1686#issuecomment-703171315) for the rationale. So, you can add +/- 1 to the tests as needed to change this. Thank you for chiming in @kir0ul!
Thanks to @kir0ul  and #1938, we're back down to only 9 warnings in our latest linux test. Looks like
- [ ] one is from `shiboken2`
- [x] three are relate to a `pytest.mark.sync_only` which might not exist anymore
- [ ] one is tracks related
- [ ] one is opening png related
- [ ] two are non-orthogonal slicing related
- [ ] one is surface layer related

Would be good to get that list back down to zero!! Below are the full details on those nine.

<details>

```
=============================== warnings summary ===============================
../../root/conda/lib/python3.7/site-packages/shiboken2/files.dir/shibokensupport/__feature__.py:142
  /root/conda/lib/python3.7/site-packages/shiboken2/files.dir/shibokensupport/__feature__.py:142: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
    return original_import(name, *args, **kwargs)
napari/_tests/test_dask_layers.py:90
  /tmp/cirrus-ci-build/napari/_tests/test_dask_layers.py:90: PytestUnknownMarkWarning: Unknown pytest.mark.sync_only - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/mark.html
    @pytest.mark.sync_only
napari/_tests/test_dask_layers.py:124
  /tmp/cirrus-ci-build/napari/_tests/test_dask_layers.py:124: PytestUnknownMarkWarning: Unknown pytest.mark.sync_only - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/mark.html
    @pytest.mark.sync_only
napari/_tests/test_dask_layers.py:169
  /tmp/cirrus-ci-build/napari/_tests/test_dask_layers.py:169: PytestUnknownMarkWarning: Unknown pytest.mark.sync_only - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/mark.html
    @pytest.mark.sync_only
napari/_qt/layer_controls/_tests/test_qt_tracks_layer.py::test_tracks_controls_color_by
  /tmp/cirrus-ci-build/napari/layers/tracks/tracks.py:375: UserWarning: Previous color_by key time not present in new properties. Falling back to track_id
    UserWarning,
napari/components/_tests/test_viewer_labels_io.py::test_open_labels[.png]
  /root/conda/lib/python3.7/importlib/_bootstrap.py:219: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility. Expected 192 from C header, got 216 from PyObject
    return f(*args, **kwds)
napari/components/_tests/test_world_coordinates.py::test_warning_affine_slicing
napari/components/_tests/test_world_coordinates.py::test_warning_affine_slicing
  /tmp/cirrus-ci-build/napari/layers/base/base.py:599: UserWarning: Non-orthogonal slicing is being requested, but is not fully supported. Data is displayed without applying an out-of-slice rotation or shear component.
    category=UserWarning,
napari/layers/surface/_tests/test_surface.py::test_random_3D_timeseries_surface
  /tmp/cirrus-ci-build/napari/layers/surface/surface.py:285: UserWarning: Assigning multiple values per vertex after slicing is
                      not allowed. All dimensions corresponding to vertex_values
                      must be non-displayed dimensions. Data will not be
                      visible.
    visible."""
-- Docs: https://docs.pytest.org/en/stable/warnings.html
----------- coverage: platform linux, python 3.7.9-final-0 -----------
Coverage XML written to file coverage.xml
====== 1453 passed, 5 skipped, 1 xfailed, 9 warnings in 354.00s (0:05:54) ======
```
</details>
Looks like we have a lot of warnings back coming from the new addition below, which we should fix

```python-traceback
  /tmp/cirrus-ci-build/napari/utils/events/dataclass.py:184: DeprecationWarning: elementwise comparison failed; this will raise an error in the future.
    different = np.any(before != after)
```

Resolving patch:
diff --git a/napari/layers/shapes/_shapes_utils.py b/napari/layers/shapes/_shapes_utils.py
--- a/napari/layers/shapes/_shapes_utils.py
+++ b/napari/layers/shapes/_shapes_utils.py
@@ -821,7 +821,7 @@ def generate_tube_meshes(path, closed=False, tube_points=10):
         binormal = binormals[i]
 
         # Add a vertex for each point on the circle
-        v = np.arange(tube_points, dtype=np.float) / tube_points * 2 * np.pi
+        v = np.arange(tube_points, dtype=float) / tube_points * 2 * np.pi
         cx = -1.0 * np.cos(v)
         cy = np.sin(v)
         grid[i] = pos
diff --git a/napari/layers/tracks/tracks.py b/napari/layers/tracks/tracks.py
--- a/napari/layers/tracks/tracks.py
+++ b/napari/layers/tracks/tracks.py
@@ -370,7 +370,7 @@ def properties(self, properties: Dict[str, np.ndarray]):
         if self._color_by not in [*properties.keys(), 'track_id']:
             warn(
                 (
-                    f"Previous color_by key {self._color_by} not present in"
+                    f"Previous color_by key {self._color_by!r} not present in"
                     " new properties. Falling back to track_id"
                 ),
                 UserWarning,


Test patch:
diff --git a/napari/_qt/layer_controls/_tests/test_qt_image_base_layer_.py b/napari/_qt/layer_controls/_tests/test_qt_image_base_layer_.py
--- a/napari/_qt/layer_controls/_tests/test_qt_image_base_layer_.py
+++ b/napari/_qt/layer_controls/_tests/test_qt_image_base_layer_.py
@@ -17,7 +17,7 @@
 _SURF = (
     np.random.random((10, 2)),
     np.random.randint(10, size=(6, 3)),
-    np.arange(100).astype(np.float),
+    np.arange(100).astype(float),
 )
 
 
diff --git a/napari/_qt/layer_controls/_tests/test_qt_tracks_layer.py b/napari/_qt/layer_controls/_tests/test_qt_tracks_layer.py
--- a/napari/_qt/layer_controls/_tests/test_qt_tracks_layer.py
+++ b/napari/_qt/layer_controls/_tests/test_qt_tracks_layer.py
@@ -1,4 +1,5 @@
 import numpy as np
+import pytest
 from qtpy.QtCore import Qt
 
 from napari._qt.layer_controls.qt_tracks_controls import QtTracksControls
@@ -11,7 +12,11 @@
 def test_tracks_controls_color_by(qtbot):
     """Check updating of the color_by combobox."""
     inital_color_by = 'time'
-    layer = Tracks(_TRACKS, properties=_PROPERTIES, color_by=inital_color_by)
+    with pytest.warns(UserWarning) as wrn:
+        layer = Tracks(
+            _TRACKS, properties=_PROPERTIES, color_by=inital_color_by
+        )
+    assert "Previous color_by key 'time' not present" in str(wrn[0].message)
     qtctrl = QtTracksControls(layer)
     qtbot.addWidget(qtctrl)
 
diff --git a/napari/_tests/test_dask_layers.py b/napari/_tests/test_dask_layers.py
--- a/napari/_tests/test_dask_layers.py
+++ b/napari/_tests/test_dask_layers.py
@@ -77,7 +77,7 @@ def get_array():
     # see https://napari.org/tutorials/applications/dask.html for details
     _list = [get_array() for fn in range(20)]
     output['stack'] = da.stack(
-        [da.from_delayed(i, shape=(10, 10, 10), dtype=np.float) for i in _list]
+        [da.from_delayed(i, shape=(10, 10, 10), dtype=float) for i in _list]
     )
     assert output['stack'].shape == (20, 10, 10, 10)
     return output
diff --git a/napari/_tests/test_dtypes.py b/napari/_tests/test_dtypes.py
--- a/napari/_tests/test_dtypes.py
+++ b/napari/_tests/test_dtypes.py
@@ -2,7 +2,7 @@
 import pytest
 
 dtypes = [
-    np.dtype(np.bool),
+    np.dtype(bool),
     np.dtype(np.int8),
     np.dtype(np.uint8),
     np.dtype(np.int16),
diff --git a/napari/_vispy/_tests/test_vispy_big_images.py b/napari/_vispy/_tests/test_vispy_big_images.py
--- a/napari/_vispy/_tests/test_vispy_big_images.py
+++ b/napari/_vispy/_tests/test_vispy_big_images.py
@@ -2,7 +2,6 @@
 import pytest
 
 
-@pytest.mark.filterwarnings("ignore:data shape:UserWarning")
 def test_big_2D_image(make_test_viewer):
     """Test big 2D image with axis exceeding max texture size."""
     viewer = make_test_viewer()
@@ -17,7 +16,6 @@ def test_big_2D_image(make_test_viewer):
         assert np.all(layer._transforms['tile2data'].scale == s)
 
 
-@pytest.mark.filterwarnings("ignore:data shape:UserWarning")
 def test_big_3D_image(make_test_viewer):
     """Test big 3D image with axis exceeding max texture size."""
     viewer = make_test_viewer(ndisplay=3)
@@ -35,7 +33,6 @@ def test_big_3D_image(make_test_viewer):
 @pytest.mark.parametrize(
     "shape", [(2, 4), (256, 4048), (4, 20_000), (20_000, 4)],
 )
-@pytest.mark.filterwarnings("ignore:data shape:UserWarning")
 def test_downsample_value(make_test_viewer, shape):
     """Test getting correct value for downsampled data."""
     viewer = make_test_viewer()
diff --git a/napari/components/_tests/test_world_coordinates.py b/napari/components/_tests/test_world_coordinates.py
--- a/napari/components/_tests/test_world_coordinates.py
+++ b/napari/components/_tests/test_world_coordinates.py
@@ -84,13 +84,15 @@ def test_warning_affine_slicing():
     viewer = ViewerModel()
     np.random.seed(0)
     data = np.random.random((10, 10, 10))
-    viewer.add_image(
-        data,
-        scale=[2, 1, 1],
-        translate=[10, 15, 20],
-        shear=[[1, 0, 0], [0, 1, 0], [10, 0, 1]],
-    )
-    with pytest.warns(None) as recorded_warnings:
+    with pytest.warns(UserWarning) as wrn:
+        viewer.add_image(
+            data,
+            scale=[2, 1, 1],
+            translate=[10, 15, 20],
+            shear=[[1, 0, 0], [0, 1, 0], [10, 0, 1]],
+        )
+    assert 'Non-orthogonal slicing is being requested' in str(wrn[0].message)
+    with pytest.warns(UserWarning) as recorded_warnings:
         viewer.layers[0].refresh()
     # note right now refresh tiggers two `_slice_indices` calls
     assert len(recorded_warnings) == 2
diff --git a/napari/layers/_tests/test_utils.py b/napari/layers/_tests/test_utils.py
--- a/napari/layers/_tests/test_utils.py
+++ b/napari/layers/_tests/test_utils.py
@@ -5,7 +5,7 @@
 from napari.layers.utils.layer_utils import convert_to_uint8
 
 
-@pytest.mark.filterwarnings("ignore::UserWarning:skimage:525")
+@pytest.mark.filterwarnings("ignore:Downcasting uint:UserWarning:skimage")
 @pytest.mark.parametrize("dtype", [np.uint8, np.uint16, np.uint32, np.uint64])
 def test_uint(dtype):
     data = np.arange(50, dtype=dtype)
@@ -16,7 +16,7 @@ def test_uint(dtype):
     assert np.all(img_as_ubyte(data_scaled) == convert_to_uint8(data_scaled))
 
 
-@pytest.mark.filterwarnings("ignore::UserWarning:skimage:525")
+@pytest.mark.filterwarnings("ignore:Downcasting int:UserWarning:skimage")
 @pytest.mark.parametrize("dtype", [np.int8, np.int16, np.int32, np.int64])
 def test_int(dtype):
     data = np.arange(50, dtype=dtype)
@@ -32,7 +32,7 @@ def test_int(dtype):
     )
 
 
-@pytest.mark.parametrize("dtype", [np.float64, np.float32, np.float])
+@pytest.mark.parametrize("dtype", [np.float64, np.float32, float])
 def test_float(dtype):
     data = np.linspace(0, 0.5, 128, dtype=dtype, endpoint=False)
     res = np.arange(128, dtype=np.uint8)
@@ -46,7 +46,7 @@ def test_float(dtype):
 
 
 def test_bool():
-    data = np.zeros((10, 10), dtype=np.bool)
+    data = np.zeros((10, 10), dtype=bool)
     data[2:-2, 2:-2] = 1
     converted = convert_to_uint8(data)
     assert converted.dtype == np.uint8
diff --git a/napari/layers/points/_tests/test_points.py b/napari/layers/points/_tests/test_points.py
--- a/napari/layers/points/_tests/test_points.py
+++ b/napari/layers/points/_tests/test_points.py
@@ -43,21 +43,21 @@ def test_empty_points_with_properties():
     """
     properties = {
         'label': np.array(['label1', 'label2']),
-        'cont_prop': np.array([0], dtype=np.float),
+        'cont_prop': np.array([0], dtype=float),
     }
     pts = Points(properties=properties)
     current_props = {k: v[0] for k, v in properties.items()}
     np.testing.assert_equal(pts.current_properties, current_props)
 
     # verify the property datatype is correct
-    assert pts.properties['cont_prop'].dtype == np.float
+    assert pts.properties['cont_prop'].dtype == float
 
     # add two points and verify the default property was applied
     pts.add([10, 10])
     pts.add([20, 20])
     props = {
         'label': np.array(['label1', 'label1']),
-        'cont_prop': np.array([0, 0], dtype=np.float),
+        'cont_prop': np.array([0, 0], dtype=float),
     }
     np.testing.assert_equal(pts.properties, props)
 
@@ -78,7 +78,7 @@ def test_empty_points_with_properties_list():
     pts.add([20, 20])
     props = {
         'label': np.array(['label1', 'label1']),
-        'cont_prop': np.array([0, 0], dtype=np.float),
+        'cont_prop': np.array([0, 0], dtype=float),
     }
     np.testing.assert_equal(pts.properties, props)
 
@@ -87,7 +87,7 @@ def test_empty_layer_with_face_colorap():
     """ Test creating an empty layer where the face color is a colormap
     See: https://github.com/napari/napari/pull/1069
     """
-    default_properties = {'point_type': np.array([1.5], dtype=np.float)}
+    default_properties = {'point_type': np.array([1.5], dtype=float)}
     layer = Points(
         properties=default_properties,
         face_color='point_type',
@@ -105,7 +105,7 @@ def test_empty_layer_with_edge_colormap():
     """ Test creating an empty layer where the face color is a colormap
     See: https://github.com/napari/napari/pull/1069
     """
-    default_properties = {'point_type': np.array([1.5], dtype=np.float)}
+    default_properties = {'point_type': np.array([1.5], dtype=float)}
     layer = Points(
         properties=default_properties,
         edge_color='point_type',
diff --git a/napari/layers/surface/_tests/test_surface.py b/napari/layers/surface/_tests/test_surface.py
--- a/napari/layers/surface/_tests/test_surface.py
+++ b/napari/layers/surface/_tests/test_surface.py
@@ -1,4 +1,5 @@
 import numpy as np
+import pytest
 
 from napari._tests.utils import check_layer_world_data_extent
 from napari.layers import Surface
@@ -77,8 +78,9 @@ def test_random_3D_timeseries_surface():
 
     # If a values axis is made to be a displayed axis then no data should be
     # shown
-    layer._slice_dims(ndisplay=3, order=[3, 0, 1, 2])
-    assert len(layer._data_view) == 0
+    with pytest.warns(UserWarning):
+        layer._slice_dims(ndisplay=3, order=[3, 0, 1, 2])
+        assert len(layer._data_view) == 0
 
 
 def test_random_3D_multitimeseries_surface():
diff --git a/napari/layers/utils/_tests/test_layer_utils.py b/napari/layers/utils/_tests/test_layer_utils.py
--- a/napari/layers/utils/_tests/test_layer_utils.py
+++ b/napari/layers/utils/_tests/test_layer_utils.py
@@ -100,7 +100,7 @@ def test_guess_continuous():
     continuous_annotation = np.array([1, 2, 3], dtype=np.float32)
     assert guess_continuous(continuous_annotation)
 
-    categorical_annotation_1 = np.array([True, False], dtype=np.bool)
+    categorical_annotation_1 = np.array([True, False], dtype=bool)
     assert not guess_continuous(categorical_annotation_1)
 
     categorical_annotation_2 = np.array([1, 2, 3], dtype=np.int)
diff --git a/napari/layers/vectors/_tests/test_vectors.py b/napari/layers/vectors/_tests/test_vectors.py
--- a/napari/layers/vectors/_tests/test_vectors.py
+++ b/napari/layers/vectors/_tests/test_vectors.py
@@ -50,7 +50,7 @@ def test_empty_vectors_with_properties():
     """Test instantiating Vectors layer with empty coordinate-like 2D data."""
     shape = (0, 2, 2)
     data = np.empty(shape)
-    properties = {'angle': np.array([0.5], dtype=np.float)}
+    properties = {'angle': np.array([0.5], dtype=float)}
     layer = Vectors(data, properties=properties)
     assert np.all(layer.data == data)
     assert layer.data.shape == shape
@@ -64,7 +64,7 @@ def test_empty_layer_with_edge_colormap():
     """
     shape = (0, 2, 2)
     data = np.empty(shape)
-    default_properties = {'angle': np.array([1.5], dtype=np.float)}
+    default_properties = {'angle': np.array([1.5], dtype=float)}
     layer = Vectors(
         data=data,
         properties=default_properties,