Skip to content

Commit 36a9cbc

Browse files
authored
Raise errors on new warnings from within xarray (#8974)
* Raise an error on new warnings from within xarray
1 parent 214d941 commit 36a9cbc

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

.github/workflows/ci.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,15 @@ jobs:
8181
if [[ "${{ matrix.env }}" == "flaky" ]] ;
8282
then
8383
echo "CONDA_ENV_FILE=ci/requirements/environment.yml" >> $GITHUB_ENV
84-
echo "PYTEST_EXTRA_FLAGS=--run-flaky --run-network-tests" >> $GITHUB_ENV
84+
echo "PYTEST_EXTRA_FLAGS=--run-flaky --run-network-tests -W default" >> $GITHUB_ENV
8585
else
8686
echo "CONDA_ENV_FILE=ci/requirements/${{ matrix.env }}.yml" >> $GITHUB_ENV
8787
fi
88+
if [[ "${{ matrix.env }}" == "min-all-deps" ]] ;
89+
then
90+
# Don't raise on warnings
91+
echo "PYTEST_EXTRA_FLAGS=-W default" >> $GITHUB_ENV
92+
fi
8893
else
8994
if [[ ${{ matrix.python-version }} != "3.12" ]]; then
9095
echo "CONDA_ENV_FILE=ci/requirements/environment.yml" >> $GITHUB_ENV

pyproject.toml

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,53 @@ ban-relative-imports = "all"
282282

283283
[tool.pytest.ini_options]
284284
addopts = ["--strict-config", "--strict-markers"]
285+
286+
# We want to forbid warnings from within xarray in our tests — instead we should
287+
# fix our own code, or mark the test itself as expecting a warning. So this:
288+
# - Converts any warning from xarray into an error
289+
# - Allows some warnings ("default") which the test suite currently raises,
290+
# since it wasn't practical to fix them all before merging this config. The
291+
# arnings are still listed in CI (since it uses `default`, not `ignore`).
292+
#
293+
# We can remove these rules allowing warnings; a valued contribution is removing
294+
# a line, seeing what breaks, and then fixing the library code or tests so that
295+
# it doesn't raise warnings.
296+
#
297+
# While we only raise an error on warnings from within xarray, if dependency
298+
# raises a warning with a stacklevel such that it's interpreted to be raised
299+
# from xarray, please feel free to add a rule switching it to `default` here.
300+
#
301+
# If these settings get in the way of making progress, it's also acceptable to
302+
# temporarily add additional ignores.
303+
285304
filterwarnings = [
286-
"ignore:Using a non-tuple sequence for multidimensional indexing is deprecated:FutureWarning",
305+
"error:::xarray.*",
306+
"default:No index created:UserWarning:xarray.core.dataset",
307+
"default::UserWarning:xarray.tests.test_coding_times",
308+
"default::UserWarning:xarray.tests.test_computation",
309+
"default::UserWarning:xarray.tests.test_dataset",
310+
"default:`ancestors` has been deprecated:DeprecationWarning:xarray.core.treenode",
311+
"default:`iter_lineage` has been deprecated:DeprecationWarning:xarray.core.treenode",
312+
"default:`lineage` has been deprecated:DeprecationWarning:xarray.core.treenode",
313+
"default:coords should be an ndarray:DeprecationWarning:xarray.tests.test_variable",
314+
"default:deallocating CachingFileManager:RuntimeWarning:xarray.backends.*",
315+
"default:deallocating CachingFileManager:RuntimeWarning:xarray.backends.netCDF4_",
316+
"default:deallocating CachingFileManager:RuntimeWarning:xarray.core.indexing",
317+
"default:Failed to decode variable.*NumPy will stop allowing conversion of out-of-bound Python integers to integer arrays:DeprecationWarning",
318+
"default:dropping variables using `drop` is deprecated; use drop_vars:DeprecationWarning:xarray.tests.test_groupby",
319+
"default:The `interpolation` argument to quantile was renamed to `method`:FutureWarning:xarray.*",
320+
"default:invalid value encountered in cast:RuntimeWarning:xarray.core.duck_array_ops",
321+
"default:invalid value encountered in cast:RuntimeWarning:xarray.conventions",
322+
"default:invalid value encountered in cast:RuntimeWarning:xarray.tests.test_units",
323+
"default:invalid value encountered in cast:RuntimeWarning:xarray.tests.test_array_api",
324+
"default:NumPy will stop allowing conversion of:DeprecationWarning",
325+
"default:shape should be provided:DeprecationWarning:xarray.tests.test_variable",
326+
"default:the `pandas.MultiIndex` object:FutureWarning:xarray.tests.test_variable",
327+
"default:Using a non-tuple sequence for multidimensional indexing is deprecated:FutureWarning",
328+
"default:Duplicate dimension names present:UserWarning:xarray.namedarray.core",
329+
"default:::xarray.tests.test_strategies",
287330
]
331+
288332
log_cli_level = "INFO"
289333
markers = [
290334
"flaky: flaky tests",

0 commit comments

Comments
 (0)