From f2cfe95e9f88087bdfa7ed623a565a8930e9ce78 Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Sun, 10 Dec 2023 09:31:15 -0500 Subject: [PATCH 1/2] Point users to where in their code they should make mods for Dataset.dims Its somewhat annoying to get warnings that point to a line within a library where the warning is issued. It really makes it unclear what one needs to change. This points to the user's access of the `dims` attribute. --- xarray/core/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/xarray/core/utils.py b/xarray/core/utils.py index 61372513b2a..82d0784b33f 100644 --- a/xarray/core/utils.py +++ b/xarray/core/utils.py @@ -496,6 +496,7 @@ def _warn(self) -> None: "in order to be more consistent with `DataArray.dims`. To access a mapping from dimension names to lengths, " "please use `Dataset.sizes`.", FutureWarning, + stacklevel=3, ) def __getitem__(self, key: K) -> V: From 0654243249c6a988b5435529eb0fa4d918410ba4 Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Sun, 10 Dec 2023 11:44:55 -0500 Subject: [PATCH 2/2] use emit_user_level_warning --- xarray/core/utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/xarray/core/utils.py b/xarray/core/utils.py index 82d0784b33f..00c84d4c10c 100644 --- a/xarray/core/utils.py +++ b/xarray/core/utils.py @@ -491,12 +491,11 @@ class FrozenMappingWarningOnValuesAccess(Frozen[K, V]): __slots__ = ("mapping",) def _warn(self) -> None: - warnings.warn( + emit_user_level_warning( "The return type of `Dataset.dims` will be changed to return a set of dimension names in future, " "in order to be more consistent with `DataArray.dims`. To access a mapping from dimension names to lengths, " "please use `Dataset.sizes`.", FutureWarning, - stacklevel=3, ) def __getitem__(self, key: K) -> V: