Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove catch_warnings in slicing #5603

Merged
merged 1 commit into from
Mar 6, 2023

Conversation

andy-sweet
Copy link
Member

@andy-sweet andy-sweet commented Mar 3, 2023

Description

This removes use of catch_warnings in slicing because using that context manager has the side of effect of forgetting any previously raised warnings. Using those in slicing means that any warnings raised in slicing are shown every time, whereas the default behavior for Python is to only show the first time per location.

The removal of catch_warnings in Image._update_thumbnail is justified because napari requires scipy >=1.4.1 and because the warning that was catching was removed in scipy 1.4.0 (thanks @jni!).

The one in the Layer.thumbnail setter is a little harder to justify, but here's my reasoning.

  • I protected one common case of warnings, which is non-finite values.
  • Even if we get a warning, it will be shown once by default.
  • Since we depend on scikit-image now, I considered just using its img_to_ubyte instead of our convert_to_uint8, but I think it warns in more cases.

Obviously, we have other usage of catch_warnings that could cause similar problems and this PR doesn't touch those. In general, we should be cautious about using catch_warnings in code paths that are hit frequently.

Type of change

  • Bug-fix (non-breaking change which fixes an issue)

References

Closes #5588.

How has this been tested?

  • all existing tests pass with my change

I manually tested with examples/add_multiscale_image.

@codecov
Copy link

codecov bot commented Mar 3, 2023

Codecov Report

Merging #5603 (196fb16) into main (c43a2e7) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #5603      +/-   ##
==========================================
- Coverage   89.51%   89.51%   -0.01%     
==========================================
  Files         610      610              
  Lines       51200    51195       -5     
==========================================
- Hits        45834    45829       -5     
  Misses       5366     5366              
Impacted Files Coverage Δ
napari/layers/base/base.py 91.65% <100.00%> (-0.03%) ⬇️
napari/layers/image/image.py 95.59% <100.00%> (-0.05%) ⬇️
napari/layers/utils/layer_utils.py 93.00% <100.00%> (+0.02%) ⬆️
napari/components/experimental/chunk/_pool.py 85.71% <0.00%> (-7.94%) ⬇️
napari/_qt/dialogs/qt_package_installer.py 82.14% <0.00%> (+0.39%) ⬆️
napari/utils/theme.py 92.94% <0.00%> (+0.58%) ⬆️
napari/utils/info.py 85.10% <0.00%> (+1.06%) ⬆️
napari/_qt/__init__.py 56.66% <0.00%> (+6.66%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@andy-sweet andy-sweet added the bug Something isn't working label Mar 4, 2023
@Czaki Czaki added the ready to merge Last chance for comments! Will be merged in ~24h label Mar 5, 2023
@andy-sweet andy-sweet merged commit c0be6d6 into napari:main Mar 6, 2023
@andy-sweet andy-sweet deleted the fix-5588-no-catch branch March 6, 2023 15:47
@Czaki Czaki removed the ready to merge Last chance for comments! Will be merged in ~24h label Apr 13, 2023
@Czaki Czaki mentioned this pull request Jun 7, 2023
@andy-sweet andy-sweet added this to the 0.4.18 milestone Jun 14, 2023
@andy-sweet
Copy link
Member Author

This is probably small and contained enough to be brought into 0.4.18, but if it's difficult to cherry pick I think it's OK to drop this too.

Czaki pushed a commit that referenced this pull request Jun 18, 2023
# Description
This removes use of `catch_warnings` in slicing because [using that
context manager has the side of effect of forgetting any previously
raised warnings](python/cpython#73858). Using
those in slicing means that any warnings raised in slicing are shown
every time, whereas [the default behavior for Python is to only show the
first time per
location](https://docs.python.org/3/library/warnings.html#the-warnings-filter).

The removal of `catch_warnings` in `Image._update_thumbnail` is
justified because [napari requires scipy
>=1.4.1](https://github.com/andy-sweet/napari/blob/196fb164ba12402dd10869fa8e4fd62ed8b6de00/setup.cfg#L71)
and because the warning that was catching was [removed in scipy
1.4.0](scipy/scipy#10395) (thanks @jni!).

The one in the `Layer.thumbnail` setter is a little harder to justify,
but here's my reasoning.
- I protected one common case of warnings, which is non-finite values.
- Even if we get a warning, it will be shown once by default.
- Since we depend on scikit-image now, I considered just using its
`img_to_ubyte` instead of our `convert_to_uint8`, but I think it warns
in more cases.

Obviously, we have other usage of `catch_warnings` that could cause
similar problems and this PR doesn't touch those. In general, we should
be cautious about using `catch_warnings` in code paths that are hit
frequently.

## Type of change
- [x] Bug-fix (non-breaking change which fixes an issue)

# References
Closes #5588.

# How has this been tested?
- [x] all existing tests pass with my change

I manually tested with `examples/add_multiscale_image`.
Czaki pushed a commit that referenced this pull request Jun 19, 2023
# Description
This removes use of `catch_warnings` in slicing because [using that
context manager has the side of effect of forgetting any previously
raised warnings](python/cpython#73858). Using
those in slicing means that any warnings raised in slicing are shown
every time, whereas [the default behavior for Python is to only show the
first time per
location](https://docs.python.org/3/library/warnings.html#the-warnings-filter).

The removal of `catch_warnings` in `Image._update_thumbnail` is
justified because [napari requires scipy
>=1.4.1](https://github.com/andy-sweet/napari/blob/196fb164ba12402dd10869fa8e4fd62ed8b6de00/setup.cfg#L71)
and because the warning that was catching was [removed in scipy
1.4.0](scipy/scipy#10395) (thanks @jni!).

The one in the `Layer.thumbnail` setter is a little harder to justify,
but here's my reasoning.
- I protected one common case of warnings, which is non-finite values.
- Even if we get a warning, it will be shown once by default.
- Since we depend on scikit-image now, I considered just using its
`img_to_ubyte` instead of our `convert_to_uint8`, but I think it warns
in more cases.

Obviously, we have other usage of `catch_warnings` that could cause
similar problems and this PR doesn't touch those. In general, we should
be cautious about using `catch_warnings` in code paths that are hit
frequently.

## Type of change
- [x] Bug-fix (non-breaking change which fixes an issue)

# References
Closes #5588.

# How has this been tested?
- [x] all existing tests pass with my change

I manually tested with `examples/add_multiscale_image`.
Czaki pushed a commit that referenced this pull request Jun 21, 2023
# Description
This removes use of `catch_warnings` in slicing because [using that
context manager has the side of effect of forgetting any previously
raised warnings](python/cpython#73858). Using
those in slicing means that any warnings raised in slicing are shown
every time, whereas [the default behavior for Python is to only show the
first time per
location](https://docs.python.org/3/library/warnings.html#the-warnings-filter).

The removal of `catch_warnings` in `Image._update_thumbnail` is
justified because [napari requires scipy
>=1.4.1](https://github.com/andy-sweet/napari/blob/196fb164ba12402dd10869fa8e4fd62ed8b6de00/setup.cfg#L71)
and because the warning that was catching was [removed in scipy
1.4.0](scipy/scipy#10395) (thanks @jni!).

The one in the `Layer.thumbnail` setter is a little harder to justify,
but here's my reasoning.
- I protected one common case of warnings, which is non-finite values.
- Even if we get a warning, it will be shown once by default.
- Since we depend on scikit-image now, I considered just using its
`img_to_ubyte` instead of our `convert_to_uint8`, but I think it warns
in more cases.

Obviously, we have other usage of `catch_warnings` that could cause
similar problems and this PR doesn't touch those. In general, we should
be cautious about using `catch_warnings` in code paths that are hit
frequently.

## Type of change
- [x] Bug-fix (non-breaking change which fixes an issue)

# References
Closes #5588.

# How has this been tested?
- [x] all existing tests pass with my change

I manually tested with `examples/add_multiscale_image`.
Czaki pushed a commit that referenced this pull request Jun 21, 2023
# Description
This removes use of `catch_warnings` in slicing because [using that
context manager has the side of effect of forgetting any previously
raised warnings](python/cpython#73858). Using
those in slicing means that any warnings raised in slicing are shown
every time, whereas [the default behavior for Python is to only show the
first time per
location](https://docs.python.org/3/library/warnings.html#the-warnings-filter).

The removal of `catch_warnings` in `Image._update_thumbnail` is
justified because [napari requires scipy
>=1.4.1](https://github.com/andy-sweet/napari/blob/196fb164ba12402dd10869fa8e4fd62ed8b6de00/setup.cfg#L71)
and because the warning that was catching was [removed in scipy
1.4.0](scipy/scipy#10395) (thanks @jni!).

The one in the `Layer.thumbnail` setter is a little harder to justify,
but here's my reasoning.
- I protected one common case of warnings, which is non-finite values.
- Even if we get a warning, it will be shown once by default.
- Since we depend on scikit-image now, I considered just using its
`img_to_ubyte` instead of our `convert_to_uint8`, but I think it warns
in more cases.

Obviously, we have other usage of `catch_warnings` that could cause
similar problems and this PR doesn't touch those. In general, we should
be cautious about using `catch_warnings` in code paths that are hit
frequently.

## Type of change
- [x] Bug-fix (non-breaking change which fixes an issue)

# References
Closes #5588.

# How has this been tested?
- [x] all existing tests pass with my change

I manually tested with `examples/add_multiscale_image`.
Czaki pushed a commit that referenced this pull request Jun 21, 2023
# Description
This removes use of `catch_warnings` in slicing because [using that
context manager has the side of effect of forgetting any previously
raised warnings](python/cpython#73858). Using
those in slicing means that any warnings raised in slicing are shown
every time, whereas [the default behavior for Python is to only show the
first time per
location](https://docs.python.org/3/library/warnings.html#the-warnings-filter).

The removal of `catch_warnings` in `Image._update_thumbnail` is
justified because [napari requires scipy
>=1.4.1](https://github.com/andy-sweet/napari/blob/196fb164ba12402dd10869fa8e4fd62ed8b6de00/setup.cfg#L71)
and because the warning that was catching was [removed in scipy
1.4.0](scipy/scipy#10395) (thanks @jni!).

The one in the `Layer.thumbnail` setter is a little harder to justify,
but here's my reasoning.
- I protected one common case of warnings, which is non-finite values.
- Even if we get a warning, it will be shown once by default.
- Since we depend on scikit-image now, I considered just using its
`img_to_ubyte` instead of our `convert_to_uint8`, but I think it warns
in more cases.

Obviously, we have other usage of `catch_warnings` that could cause
similar problems and this PR doesn't touch those. In general, we should
be cautious about using `catch_warnings` in code paths that are hit
frequently.

## Type of change
- [x] Bug-fix (non-breaking change which fixes an issue)

# References
Closes #5588.

# How has this been tested?
- [x] all existing tests pass with my change

I manually tested with `examples/add_multiscale_image`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiscale 3D rendering warning should happen once only
3 participants