Skip to content

Commit 912638b

Browse files
committed
Use emit_user_level_warning rather than warnings.warn
1 parent 5a4036b commit 912638b

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

xarray/core/alignment.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import functools
44
import operator
5-
import warnings
65
from collections import defaultdict
76
from collections.abc import Callable, Hashable, Iterable, Mapping
87
from contextlib import suppress
@@ -21,7 +20,7 @@
2120
safe_cast_to_index,
2221
)
2322
from xarray.core.types import T_Alignable
24-
from xarray.core.utils import is_dict_like, is_full_slice
23+
from xarray.core.utils import emit_user_level_warning, is_dict_like, is_full_slice
2524
from xarray.core.variable import Variable, as_compatible_data, calculate_dimensions
2625
from xarray.util.deprecation_helpers import CombineKwargDefault
2726

@@ -424,7 +423,7 @@ def align_indexes(self) -> None:
424423
isinstance(self.join, CombineKwargDefault)
425424
and self.join != "exact"
426425
):
427-
warnings.warn(
426+
emit_user_level_warning(
428427
self.join.warning_message(
429428
"This change will result in the following ValueError:"
430429
"cannot be aligned with join='exact' because "
@@ -435,8 +434,7 @@ def align_indexes(self) -> None:
435434
),
436435
recommend_set_options=False,
437436
),
438-
category=FutureWarning,
439-
stacklevel=2,
437+
FutureWarning,
440438
)
441439
if self.join == "exact":
442440
raise ValueError(

xarray/core/concat.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import warnings
43
from collections.abc import Hashable, Iterable
54
from typing import TYPE_CHECKING, Any, Union, overload
65

@@ -19,6 +18,7 @@
1918
merge_collected,
2019
)
2120
from xarray.core.types import T_DataArray, T_Dataset, T_Variable
21+
from xarray.core.utils import emit_user_level_warning
2222
from xarray.core.variable import Variable
2323
from xarray.core.variable import concat as concat_vars
2424
from xarray.util.deprecation_helpers import (
@@ -369,14 +369,13 @@ def process_subset_opt(opt, subset):
369369
if opt == "different":
370370
if isinstance(compat, CombineKwargDefault) and compat != "override":
371371
if not isinstance(opt, CombineKwargDefault):
372-
warnings.warn(
372+
emit_user_level_warning(
373373
compat.warning_message(
374374
"This change will result in the following ValueError: "
375375
f"Cannot specify both {subset}='different' and compat='override'.",
376376
recommend_set_options=False,
377377
),
378-
category=FutureWarning,
379-
stacklevel=2,
378+
FutureWarning,
380379
)
381380

382381
if compat == "override":
@@ -462,13 +461,12 @@ def process_subset_opt(opt, subset):
462461
and opt != "minimal"
463462
and original != concat_over
464463
):
465-
warnings.warn(
464+
emit_user_level_warning(
466465
opt.warning_message(
467466
"This is likely to lead to different results when multiple datasets "
468467
"have matching variables with overlapping values.",
469468
),
470-
category=FutureWarning,
471-
stacklevel=2,
469+
FutureWarning,
472470
)
473471
else:
474472
valid_vars = tuple(getattr(datasets[0], subset))

xarray/core/merge.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import warnings
43
from collections import defaultdict
54
from collections.abc import Hashable, Iterable, Mapping, Sequence, Set
65
from typing import TYPE_CHECKING, Any, NamedTuple, Union
@@ -16,7 +15,13 @@
1615
filter_indexes_from_coords,
1716
indexes_equal,
1817
)
19-
from xarray.core.utils import Frozen, compat_dict_union, dict_equiv, equivalent
18+
from xarray.core.utils import (
19+
Frozen,
20+
compat_dict_union,
21+
dict_equiv,
22+
emit_user_level_warning,
23+
equivalent,
24+
)
2025
from xarray.core.variable import Variable, as_variable, calculate_dimensions
2126
from xarray.util.deprecation_helpers import (
2227
_COMPAT_DEFAULT,
@@ -306,13 +311,12 @@ def merge_collected(
306311
and compat == "no_conflicts"
307312
and len(variables) > 1
308313
):
309-
warnings.warn(
314+
emit_user_level_warning(
310315
compat.warning_message(
311316
"This is likely to lead to different results when "
312317
"combining overlapping variables with the same name.",
313318
),
314-
category=FutureWarning,
315-
stacklevel=2,
319+
FutureWarning,
316320
)
317321
except MergeError:
318322
if compat != "minimal":

0 commit comments

Comments
 (0)