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

Filter out doctest warning #8539

Merged
merged 2 commits into from
Dec 11, 2023
Merged

Filter out doctest warning #8539

merged 2 commits into from
Dec 11, 2023

Conversation

max-sixty
Copy link
Collaborator

Trying to fix #8537. Not sure it'll work and can't test locally so seeing if it passes CI

Trying to fix pydata#8537. Not sure it'll work and can't test locally so seeing if it passes CI
@max-sixty
Copy link
Collaborator Author

No luck. Possibly we could add a filter in an autouse fixture for the doctests? Or just skip that test?

@keewis
Copy link
Collaborator

keewis commented Dec 11, 2023

I think the issue is that the warning is emitted at test collection time (when executing one of the conftest.py files), so the filterwarnings does not apply there. It also does not appear to be possible to apply a mark to all doctest tests (otherwise we could have used pytest.mark.filterwarnings("error")).

So I guess the only option we have is using the CLI:

pytest --doctest-modules xarray --ignore xarray/tests -Werror -W "ignore:h5py is running against HDF5 1.14.3:UserWarning"

@keewis keewis mentioned this pull request Dec 11, 2023
4 tasks
@kmuehlbauer
Copy link
Contributor

Seems to be pinning problem over at conda-forge: conda-forge/h5py-feedstock#122 (see latest comments there).

@keewis
Copy link
Collaborator

keewis commented Dec 11, 2023

Seems to be pinning problem over at conda-forge: conda-forge/h5py-feedstock#122 (see latest comments there).

As expected, so there is indeed nothing we can do about this besides silencing the warning.

For now, I've added a ignore to the CLI, but we'll have to come up with a strategy for future cases.

@headtr1ck
Copy link
Collaborator

Did you try adding it to xarray/tests/__init__.py? There are already a few ignores.

@max-sixty
Copy link
Collaborator Author

For now, I've added a ignore to the CLI, but we'll have to come up with a strategy for future cases.

Thanks! Closing

Did you try adding it to xarray/tests/__init__.py? There are already a few ignores.

Good point — maybe we can do it at import time. (though not that different from adding to CLI I guess, since the only time it errors is with our CLI arguments that convert warnings to errors — which I think is great overall)

@max-sixty max-sixty closed this Dec 11, 2023
@keewis
Copy link
Collaborator

keewis commented Dec 11, 2023

Did you try adding it to xarray/tests/__init__.py? There are already a few ignores.

no, I totally missed that. I agree with @max-sixty though that having the ignore in the same place as where we enable raising warnings is a good property, especially since it then will not be ignored in the tests (although right now that's not so useful since we have hundreds if not thousands of warnings). So we might want to migrate those warnings that should only be ignored in doctest?

The downside, though, is that trying to reproduce CI failures means that we have to copy a potentially very long command... so that would be an argument for keeping them in xarray.tests.__init__.

For now, I've added a ignore to the CLI

Thanks! Closing

what I meant was that I modified this PR, so we'd still have to merge it.

@max-sixty max-sixty reopened this Dec 11, 2023
@max-sixty
Copy link
Collaborator Author

what I meant was that I modified this PR, so we'd still have to merge it.

lol, sorry, reopening!

@max-sixty max-sixty enabled auto-merge (squash) December 11, 2023 20:41
@max-sixty max-sixty merged commit 8ad0b83 into pydata:main Dec 11, 2023
50 of 51 checks passed
@max-sixty max-sixty deleted the doctest branch December 11, 2023 21:00
@max-sixty
Copy link
Collaborator Author

max-sixty commented Dec 11, 2023

having the ignore in the same place as where we enable raising warnings is a good property, especially since it then will not be ignored in the tests (although right now that's not so useful since we have hundreds if not thousands of warnings). So we might want to migrate those warnings that should only be ignored in doctest?

I would say it depends on "do we want to oversee the warnings?"

  • for warnings that are temporary and we know we can always ignore ('urllib3.contrib.pyopenssl' module is deprecated, as an example), putting it in the __init__ means we don't have to litter the tests with their ignores. That's often the case with warnings from dependencies, and almost always the case with dependencies of dependencies, where we don't have control.
  • and then for more specific warnings — those in xarray, and those in some close dependencies, it makes sense to have them next to the tests, where we want to oversee them

...probably both of those are better than the CLI. Though I'm not sure the __init__ covers the doctests, does xarray.tests.__init__ get run before doctest collections?

@keewis
Copy link
Collaborator

keewis commented Dec 11, 2023

does xarray.tests.__init__ get run before doctest collections?

Yes, because we import it in xarray/tests/conftest.py

But yes, I agree it is probably better to put them in xarray.tests. I'd argue that we should ignore warnings that are emitted by imports in xarray.tests, and anything else should be ignored in the tests (unless way too many tests would emit these, in which case it might make sense to also do so in xarray.tests).

Either way, we definitely need to point out why we ignore a certain warning (in general a link to the issue / PR with a short explanation should be enough), and maybe also list criteria that allow removing them?

@max-sixty
Copy link
Collaborator Author

Either way, we definitely need to point out why we ignore a certain warning (in general a link to the issue / PR with a short explanation should be enough), and maybe also list criteria that allow removing them?

Agree!

I'd argue that we should ignore warnings that are emitted by imports in xarray.tests, and anything else should be ignored in the tests (unless way too many tests would emit these, in which case it might make sense to also do so in xarray.tests).

I agree with the direction. Though I would put the bar for "way too many tests would emit these" quite low for things we can't control, or that don't show up at runtime (e.g. PendingDeprecationWarning)

In particular, if it means that we silence more of the warnings, that's great — our test suite is hardly too restrictive about showing warnings which we can't do anything about atm...

dcherian added a commit to dcherian/xarray that referenced this pull request Dec 18, 2023
* main: (26 commits)
  Filter null values before plotting (pydata#8535)
  Update concat.py (pydata#8538)
  Add getitem to array protocol (pydata#8406)
  Added option to specify weights in xr.corr() and xr.cov() (pydata#8527)
  Filter out doctest warning (pydata#8539)
  Bump actions/setup-python from 4 to 5 (pydata#8540)
  Point users to where in their code they should make mods for Dataset.dims (pydata#8534)
  Add Cumulative aggregation (pydata#8512)
  dev whats-new
  Whats-new for 2023.12.0 (pydata#8532)
  explicitly skip using `__array_namespace__` for `numpy.ndarray` (pydata#8526)
  Add `eval` method to Dataset (pydata#7163)
  Deprecate ds.dims returning dict (pydata#8500)
  test and fix empty xindexes repr (pydata#8521)
  Remove PR labeler bot (pydata#8525)
  Hypothesis strategy for generating Variable objects (pydata#8404)
  Use numbagg for `rolling` methods (pydata#8493)
  Bump pypa/gh-action-pypi-publish from 1.8.10 to 1.8.11 (pydata#8514)
  fix RTD docs build (pydata#8519)
  Fix type of `.assign_coords` (pydata#8495)
  ...
dcherian added a commit to dcherian/xarray that referenced this pull request Dec 20, 2023
* main: (58 commits)
  Adapt map_blocks to use new Coordinates API (pydata#8560)
  add xeofs to ecosystem.rst (pydata#8561)
  Offer a fixture for unifying DataArray & Dataset tests (pydata#8533)
  Generalize cumulative reduction (scan) to non-dask types (pydata#8019)
  Filter null values before plotting (pydata#8535)
  Update concat.py (pydata#8538)
  Add getitem to array protocol (pydata#8406)
  Added option to specify weights in xr.corr() and xr.cov() (pydata#8527)
  Filter out doctest warning (pydata#8539)
  Bump actions/setup-python from 4 to 5 (pydata#8540)
  Point users to where in their code they should make mods for Dataset.dims (pydata#8534)
  Add Cumulative aggregation (pydata#8512)
  dev whats-new
  Whats-new for 2023.12.0 (pydata#8532)
  explicitly skip using `__array_namespace__` for `numpy.ndarray` (pydata#8526)
  Add `eval` method to Dataset (pydata#7163)
  Deprecate ds.dims returning dict (pydata#8500)
  test and fix empty xindexes repr (pydata#8521)
  Remove PR labeler bot (pydata#8525)
  Hypothesis strategy for generating Variable objects (pydata#8404)
  ...
dcherian added a commit to dcherian/xarray that referenced this pull request Jan 4, 2024
commit 0a0f800
Merge: 33c8033 41d33f5
Author: Deepak Cherian <[email protected]>
Date:   Tue Jan 2 20:42:51 2024 -0700

    Merge branch 'main' into depr-groupby-squeeze-2

commit 33c8033
Author: Deepak Cherian <[email protected]>
Date:   Tue Jan 2 20:40:42 2024 -0700

    Don't skip for resampling

commit d7be352
Author: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date:   Wed Jan 3 03:24:13 2024 +0000

    [pre-commit.ci] auto fixes from pre-commit.com hooks

    for more information, see https://pre-commit.ci

commit d13fa0e
Author: Deepak Cherian <[email protected]>
Date:   Tue Jan 2 20:23:43 2024 -0700

    Apply suggestions from code review

    Co-authored-by: Michael Niklas  <[email protected]>

commit dd6ea53
Author: Deepak Cherian <[email protected]>
Date:   Thu Dec 21 19:29:40 2023 -0700

    Silence more warnings

commit 44e5a41
Author: Deepak Cherian <[email protected]>
Date:   Thu Dec 21 19:21:06 2023 -0700

    minimize test mods

commit 94c1c1f
Author: Deepak Cherian <[email protected]>
Date:   Thu Dec 21 18:55:46 2023 -0700

    Add tests for pydata#8263

commit 0ab4eb6
Author: Deepak Cherian <[email protected]>
Date:   Thu Dec 21 18:47:41 2023 -0700

    Fix typing

commit a064430
Merge: d6a3f2d 03ec3cb
Author: Deepak Cherian <[email protected]>
Date:   Thu Dec 21 18:47:04 2023 -0700

    Merge branch 'main' into depr-groupby-squeeze-2

    * main:
      Fix mypy type ignore (pydata#8564)
      Support for the new compression arguments. (pydata#7551)
      FIX: reverse index output of bottleneck move_argmax/move_argmin functions (pydata#8552)
      Adapt map_blocks to use new Coordinates API (pydata#8560)
      add xeofs to ecosystem.rst (pydata#8561)
      Offer a fixture for unifying DataArray & Dataset tests (pydata#8533)
      Generalize cumulative reduction (scan) to non-dask types (pydata#8019)

commit d6a3f2d
Author: Deepak Cherian <[email protected]>
Date:   Thu Dec 21 18:46:50 2023 -0700

    Fix generator for aggregations

commit 97f1695
Author: Deepak Cherian <[email protected]>
Date:   Tue Dec 19 10:58:11 2023 -0700

    Fix docs

commit 5b33b98
Author: Deepak Cherian <[email protected]>
Date:   Sun Dec 17 20:35:53 2023 -0700

    fix whats-new

commit 80b2b36
Author: Deepak Cherian <[email protected]>
Date:   Sun Dec 17 20:26:17 2023 -0700

    Reduce more warnings

commit 5f6f4ea
Merge: a57d4ae 2971994
Author: Deepak Cherian <[email protected]>
Date:   Sat Dec 16 20:33:13 2023 -0700

    Merge branch 'main' into depr-groupby-squeeze-2

    * main: (26 commits)
      Filter null values before plotting (pydata#8535)
      Update concat.py (pydata#8538)
      Add getitem to array protocol (pydata#8406)
      Added option to specify weights in xr.corr() and xr.cov() (pydata#8527)
      Filter out doctest warning (pydata#8539)
      Bump actions/setup-python from 4 to 5 (pydata#8540)
      Point users to where in their code they should make mods for Dataset.dims (pydata#8534)
      Add Cumulative aggregation (pydata#8512)
      dev whats-new
      Whats-new for 2023.12.0 (pydata#8532)
      explicitly skip using `__array_namespace__` for `numpy.ndarray` (pydata#8526)
      Add `eval` method to Dataset (pydata#7163)
      Deprecate ds.dims returning dict (pydata#8500)
      test and fix empty xindexes repr (pydata#8521)
      Remove PR labeler bot (pydata#8525)
      Hypothesis strategy for generating Variable objects (pydata#8404)
      Use numbagg for `rolling` methods (pydata#8493)
      Bump pypa/gh-action-pypi-publish from 1.8.10 to 1.8.11 (pydata#8514)
      fix RTD docs build (pydata#8519)
      Fix type of `.assign_coords` (pydata#8495)
      ...

commit a57d4ae
Author: Deepak Cherian <[email protected]>
Date:   Fri Dec 1 21:36:04 2023 -0700

    Test one more warning

commit bf8139d
Author: Deepak Cherian <[email protected]>
Date:   Fri Dec 1 21:33:45 2023 -0700

    Update xarray/tests/test_groupby.py

commit 4e9a063
Author: Deepak Cherian <[email protected]>
Date:   Fri Dec 1 21:10:14 2023 -0700

    Set squeeze=None for Dataset too

commit c2e576e
Author: Deepak Cherian <[email protected]>
Date:   Fri Dec 1 20:54:17 2023 -0700

    Fix first, last

commit 6d8e822
Author: Deepak Cherian <[email protected]>
Date:   Fri Dec 1 20:46:21 2023 -0700

    better warning

commit 62c334b
Author: Deepak Cherian <[email protected]>
Date:   Fri Dec 1 20:45:17 2023 -0700

    silence warnings

commit b7805a8
Author: dcherian <[email protected]>
Date:   Tue Aug 15 10:54:25 2023 -0600

    Deprecate `squeeze` in GroupBy.

    Closes pydata#2157
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Doctests failing
4 participants