Skip to content

Commit

Permalink
Fix problem with invalidate cache (#6520)
Browse files Browse the repository at this point in the history
# References and relevant issues

closes #6518

# Description
Fix for #6518 with added tests
  • Loading branch information
Czaki committed Dec 14, 2023
1 parent cd50d92 commit 2fdfac5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions napari/layers/labels/_tests/test_labels.py
Expand Up @@ -1567,6 +1567,15 @@ def on_event():
assert event_emitted


def test_invalidate_cache_when_change_slice():
layer = Labels(np.zeros((2, 4, 5), dtype=np.uint8))
assert layer._cached_labels is None
layer._setup_cache(layer._slice.image.raw)
assert layer._cached_labels is not None
layer._set_view_slice()
assert layer._cached_labels is None


class TestLabels:
@staticmethod
def get_objects():
Expand Down
2 changes: 2 additions & 0 deletions napari/layers/labels/labels.py
Expand Up @@ -1007,8 +1007,10 @@ def _raw_to_displayed(
mapped_labels : array
Encoded colors mapped between 0 and 1 to be displayed.
"""

if data_slice is None:
data_slice = tuple(slice(0, size) for size in raw.shape)
self._cached_labels = None
else:
self._setup_cache(raw)

Expand Down

0 comments on commit 2fdfac5

Please sign in to comment.