Skip to content

Commit e993e1c

Browse files
authored
Replace DeprecationWarning with FutureWarning (#11112)
When deprecating functionality, xarray has sometimes used ``FutureWarning`` and sometimes used ``DeprecationWarning``. ``DeprecationWarning`` is not intended to be visible to end-users so this PR switches to using ``FutureWarning`` everywhere
1 parent e80c406 commit e993e1c

27 files changed

+81
-80
lines changed

doc/contribute/contributing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ a user passes ``old_arg``, we would instead catch it:
576576
emit_user_level_warning(
577577
"`old_arg` has been deprecated, and in the future will raise an error."
578578
"Please use `new_arg` from now on.",
579-
DeprecationWarning,
579+
FutureWarning,
580580
)
581581
582582
# Still do what the user intended here

doc/get-help/faq.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ How stable is Xarray's API?
423423

424424
Xarray tries very hard to maintain backwards compatibility in our :ref:`api` between released versions.
425425
Whilst we do occasionally make breaking changes in order to improve the library,
426-
we `signpost changes <https://docs.xarray.dev/en/stable/contributing.html#backwards-compatibility>`_ with ``DeprecationWarnings`` for many releases in advance.
426+
we `signpost changes <https://docs.xarray.dev/en/stable/contributing.html#backwards-compatibility>`_ with ``FutureWarnings`` for many releases in advance.
427427
(An exception is bugs - whose behaviour we try to fix as soon as we notice them.)
428428
Our `test-driven development practices <https://docs.xarray.dev/en/stable/contributing.html#test-driven-development-code-writing>`_ helps to ensure any accidental regressions are caught.
429429
This philosophy applies to everything in the `public API <https://docs.xarray.dev/en/stable/getting-started-guide/faq.html#what-parts-of-xarray-are-considered-public-api>`_.

doc/whats-new.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ New Features
2323
Breaking Changes
2424
~~~~~~~~~~~~~~~~
2525

26+
- When deprecating functionality, xarray has sometimes used ``FutureWarning``
27+
and sometimes used ``DeprecationWarning``. ``DeprecationWarning`` is
28+
not intended to be visible to end-users so this version of xarray
29+
switches to using ``FutureWarning`` everywhere (:pull:`11112`).
30+
By `Julia Signell <https://github.com/jsignell>`_.
2631

2732
Deprecations
2833
~~~~~~~~~~~~

properties/test_index_manipulation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ def drop_dims(self, data):
195195
)
196196
)
197197
note(f"> drop_dims: {dims}")
198-
# TODO: dropping a multi-index dimension raises a DeprecationWarning
198+
# TODO: dropping a multi-index dimension raises a FutureWarning
199199
with warnings.catch_warnings():
200-
warnings.simplefilter("ignore", category=DeprecationWarning)
200+
warnings.simplefilter("ignore", category=FutureWarning)
201201
self.dataset = self.dataset.drop_dims(dims)
202202

203203
for dim in dims:

xarray/backends/pydap_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def open(
123123
emit_user_level_warning(
124124
"`output_grid` is deprecated and will be removed in a future version"
125125
" of xarray. Will be set to `None`, the new default. ",
126-
DeprecationWarning,
126+
FutureWarning,
127127
)
128128
output_grid = False # new default behavior
129129

xarray/coding/cftime_offsets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ def cftime_range(
11261126
"""
11271127
emit_user_level_warning(
11281128
"cftime_range() is deprecated, please use xarray.date_range(..., use_cftime=True) instead.",
1129-
DeprecationWarning,
1129+
FutureWarning,
11301130
)
11311131

11321132
return date_range(

xarray/computation/rolling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ def _array_reduce(
707707
f"Reductions are applied along the rolling dimension(s) "
708708
f"'{self.dim}'. Passing the 'dim' kwarg to reduction "
709709
f"operations has no effect.",
710-
DeprecationWarning,
710+
FutureWarning,
711711
stacklevel=3,
712712
)
713713
del kwargs["dim"]

xarray/conventions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def decode_cf_variable(
223223
"Example usage:\n"
224224
" time_coder = xr.coders.CFDatetimeCoder(use_cftime=True)\n"
225225
" ds = xr.open_dataset(decode_times=time_coder)\n",
226-
DeprecationWarning,
226+
FutureWarning,
227227
)
228228
decode_times = CFDatetimeCoder(use_cftime=use_cftime)
229229
elif use_cftime is not None:

xarray/core/dataarray.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1479,7 +1479,7 @@ def chunk(
14791479
utils.emit_user_level_warning(
14801480
"Supplying chunks as dimension-order tuples is deprecated. "
14811481
"It will raise an error in the future. Instead use a dict with dimension names as keys.",
1482-
category=DeprecationWarning,
1482+
category=FutureWarning,
14831483
)
14841484
if len(chunks) != len(self.dims):
14851485
raise ValueError(

xarray/core/dataset.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2561,7 +2561,7 @@ def chunk(
25612561
warnings.warn(
25622562
"None value for 'chunks' is deprecated. "
25632563
"It will raise an error in the future. Use instead '{}'",
2564-
category=DeprecationWarning,
2564+
category=FutureWarning,
25652565
stacklevel=2,
25662566
)
25672567
chunks = {}
@@ -2571,7 +2571,7 @@ def chunk(
25712571
utils.emit_user_level_warning(
25722572
"Supplying chunks as dimension-order tuples is deprecated. "
25732573
"It will raise an error in the future. Instead use a dict with dimensions as keys.",
2574-
category=DeprecationWarning,
2574+
category=FutureWarning,
25752575
)
25762576
chunks_mapping = dict.fromkeys(self.dims, chunks)
25772577
else:
@@ -5899,7 +5899,7 @@ def drop_vars(
58995899
emit_user_level_warning(
59005900
f"Deleting a single level of a MultiIndex is deprecated. Previously, this deleted all levels of a MultiIndex. "
59015901
f"Please also drop the following variables: {other_names!r} to avoid an error in the future.",
5902-
DeprecationWarning,
5902+
FutureWarning,
59035903
)
59045904

59055905
assert_no_index_corrupted(self.xindexes, names_set)
@@ -5990,7 +5990,7 @@ def drop(
59905990
if is_dict_like(labels) and not isinstance(labels, dict):
59915991
emit_user_level_warning(
59925992
"dropping coordinates using `drop` is deprecated; use drop_vars.",
5993-
DeprecationWarning,
5993+
FutureWarning,
59945994
)
59955995
return self.drop_vars(labels, errors=errors)
59965996

@@ -6002,7 +6002,7 @@ def drop(
60026002
if dim is None and (is_scalar(labels) or isinstance(labels, Iterable)):
60036003
emit_user_level_warning(
60046004
"dropping variables using `drop` is deprecated; use drop_vars.",
6005-
DeprecationWarning,
6005+
FutureWarning,
60066006
)
60076007
# for mypy
60086008
if is_scalar(labels):
@@ -6012,14 +6012,14 @@ def drop(
60126012
warnings.warn(
60136013
"dropping labels using list-like labels is deprecated; using "
60146014
"dict-like arguments with `drop_sel`, e.g. `ds.drop_sel(dim=[labels]).",
6015-
DeprecationWarning,
6015+
FutureWarning,
60166016
stacklevel=2,
60176017
)
60186018
return self.drop_sel({dim: labels}, errors=errors, **labels_kwargs)
60196019

60206020
emit_user_level_warning(
60216021
"dropping labels using `drop` is deprecated; use `drop_sel` instead.",
6022-
DeprecationWarning,
6022+
FutureWarning,
60236023
)
60246024
return self.drop_sel(labels, errors=errors)
60256025

@@ -9425,7 +9425,7 @@ def argmin(self, dim: Hashable | None = None, **kwargs) -> Self:
94259425
"dim changes to return a dict of indices of each dimension, for "
94269426
"consistency it will be an error to call Dataset.argmin() with no argument,"
94279427
"since we don't return a dict of Datasets.",
9428-
DeprecationWarning,
9428+
FutureWarning,
94299429
stacklevel=2,
94309430
)
94319431
if (
@@ -9518,7 +9518,7 @@ def argmax(self, dim: Hashable | None = None, **kwargs) -> Self:
95189518
"dim changes to return a dict of indices of each dimension, for "
95199519
"consistency it will be an error to call Dataset.argmin() with no argument,"
95209520
"since we don't return a dict of Datasets.",
9521-
DeprecationWarning,
9521+
FutureWarning,
95229522
stacklevel=2,
95239523
)
95249524
if (

0 commit comments

Comments
 (0)