From fbea202009367a174c2ace93c5d24b104ef513b2 Mon Sep 17 00:00:00 2001 From: Benoit Bovy Date: Wed, 2 Jul 2025 16:18:04 +0200 Subject: [PATCH 1/3] remove Dimensions without coordinates from text repr --- xarray/core/formatting.py | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/xarray/core/formatting.py b/xarray/core/formatting.py index 14e70b0550c..22ee8d0d91a 100644 --- a/xarray/core/formatting.py +++ b/xarray/core/formatting.py @@ -596,18 +596,6 @@ def dim_summary_limited( return _element_formatter(elements, col_width, max_rows) -def unindexed_dims_repr(dims, coords, max_rows: int | None = None): - unindexed_dims = [d for d in dims if d not in coords] - if unindexed_dims: - dims_start = "Dimensions without coordinates: " - dims_str = _element_formatter( - unindexed_dims, col_width=len(dims_start), max_rows=max_rows - ) - return dims_start + dims_str - else: - return None - - @contextlib.contextmanager def set_numpy_options(*args, **kwargs): original = np.get_printoptions() @@ -711,12 +699,6 @@ def array_repr(arr): coords_repr(arr.coords, col_width=col_width, max_rows=max_rows) ) - unindexed_dims_str = unindexed_dims_repr( - arr.dims, arr.coords, max_rows=max_rows - ) - if unindexed_dims_str: - summary.append(unindexed_dims_str) - display_default_indexes = _get_boolean_with_default( "display_default_indexes", False ) @@ -751,10 +733,6 @@ def dataset_repr(ds): if ds.coords: summary.append(coords_repr(ds.coords, col_width=col_width, max_rows=max_rows)) - unindexed_dims_str = unindexed_dims_repr(ds.dims, ds.coords, max_rows=max_rows) - if unindexed_dims_str: - summary.append(unindexed_dims_str) - summary.append(data_vars_repr(ds.data_vars, col_width=col_width, max_rows=max_rows)) display_default_indexes = _get_boolean_with_default( @@ -788,10 +766,6 @@ def dims_and_coords_repr(ds) -> str: if ds.coords: summary.append(coords_repr(ds.coords, col_width=col_width, max_rows=max_rows)) - unindexed_dims_str = unindexed_dims_repr(ds.dims, ds.coords, max_rows=max_rows) - if unindexed_dims_str: - summary.append(unindexed_dims_str) - return "\n".join(summary) @@ -1115,13 +1089,6 @@ def _datatree_node_repr(node: DataTree, show_inherited: bool) -> str: inherited_coords_repr(node, col_width=col_width, max_rows=max_rows) ) - if show_dims: - unindexed_dims_str = unindexed_dims_repr( - dim_sizes, node.coords, max_rows=max_rows - ) - if unindexed_dims_str: - summary.append(unindexed_dims_str) - if node._data_variables: summary.append( data_vars_repr(node._data_variables, col_width=col_width, max_rows=max_rows) From 131c15f6ba288eba5a4f4053b8d75288e4fdc608 Mon Sep 17 00:00:00 2001 From: Benoit Bovy Date: Wed, 2 Jul 2025 16:26:43 +0200 Subject: [PATCH 2/3] remove Dimension without coordinates refs --- xarray/computation/computation.py | 11 ---- xarray/computation/rolling.py | 7 --- xarray/computation/rolling_exp.py | 6 -- xarray/core/_aggregations.py | 20 ------- xarray/core/accessor_str.py | 71 +---------------------- xarray/core/common.py | 13 ----- xarray/core/dataarray.py | 80 ++------------------------ xarray/core/dataset.py | 36 ------------ xarray/core/datatree.py | 3 - xarray/plot/utils.py | 5 -- xarray/structure/alignment.py | 5 -- xarray/structure/combine.py | 5 -- xarray/structure/concat.py | 1 - xarray/tests/conftest.py | 2 - xarray/tests/test_backends_datatree.py | 8 --- xarray/tests/test_dask.py | 4 +- xarray/tests/test_dataarray.py | 1 - xarray/tests/test_dataset.py | 2 - xarray/tests/test_datatree.py | 10 ---- xarray/tests/test_formatting.py | 53 ++--------------- xarray/tests/test_sparse.py | 5 +- 21 files changed, 12 insertions(+), 336 deletions(-) diff --git a/xarray/computation/computation.py b/xarray/computation/computation.py index 14b1ae6e240..1d9c0583cc6 100644 --- a/xarray/computation/computation.py +++ b/xarray/computation/computation.py @@ -345,7 +345,6 @@ def cross( >>> xr.cross(a, b, dim="dim_0") Size: 24B array([-3, 6, -3]) - Dimensions without coordinates: dim_0 Vector cross-product with 3 dimensions but zeros at the last axis yields the same results as with 2 dimensions: @@ -355,7 +354,6 @@ def cross( >>> xr.cross(a, b, dim="dim_0") Size: 24B array([ 0, 0, -3]) - Dimensions without coordinates: dim_0 Multiple vector cross-products. Note that the direction of the cross product vector is defined by the right-hand rule: @@ -397,7 +395,6 @@ def cross( >>> c.to_dataset(dim="cartesian") Size: 24B Dimensions: (dim_0: 1) - Dimensions without coordinates: dim_0 Data variables: x (dim_0) int64 8B -3 y (dim_0) int64 8B 6 @@ -526,7 +523,6 @@ def dot( array([[0, 1], [2, 3], [4, 5]]) - Dimensions without coordinates: a, b >>> da_b Size: 96B @@ -538,36 +534,30 @@ def dot( [[ 8, 9], [10, 11]]]) - Dimensions without coordinates: a, b, c >>> da_c Size: 48B array([[0, 1, 2], [3, 4, 5]]) - Dimensions without coordinates: c, d >>> xr.dot(da_a, da_b, dim=["a", "b"]) Size: 16B array([110, 125]) - Dimensions without coordinates: c >>> xr.dot(da_a, da_b, dim=["a"]) Size: 32B array([[40, 46], [70, 79]]) - Dimensions without coordinates: b, c >>> xr.dot(da_a, da_b, da_c, dim=["b", "c"]) Size: 72B array([[ 9, 14, 19], [ 93, 150, 207], [273, 446, 619]]) - Dimensions without coordinates: a, d >>> xr.dot(da_a, da_b) Size: 16B array([110, 125]) - Dimensions without coordinates: c >>> xr.dot(da_a, da_b, dim=...) Size: 8B @@ -715,7 +705,6 @@ def where(cond, x, y, keep_attrs=None): Size: 32B array([[1, 2], [0, 0]]) - Dimensions without coordinates: x, y See Also -------- diff --git a/xarray/computation/rolling.py b/xarray/computation/rolling.py index e7718560559..5ac9c30e4a4 100644 --- a/xarray/computation/rolling.py +++ b/xarray/computation/rolling.py @@ -392,7 +392,6 @@ def construct( [nan, 4., 5.], [ 4., 5., 6.], [ 5., 6., 7.]]]) - Dimensions without coordinates: a, b, window_dim >>> rolling = da.rolling(b=3, center=True) >>> rolling.construct("window_dim") @@ -406,7 +405,6 @@ def construct( [ 4., 5., 6.], [ 5., 6., 7.], [ 6., 7., nan]]]) - Dimensions without coordinates: a, b, window_dim """ @@ -536,20 +534,17 @@ def reduce( [nan, 4., 5.], [ 4., 5., 6.], [ 5., 6., 7.]]]) - Dimensions without coordinates: a, b, window_dim >>> rolling.reduce(np.sum) Size: 64B array([[nan, nan, 3., 6.], [nan, nan, 15., 18.]]) - Dimensions without coordinates: a, b >>> rolling = da.rolling(b=3, min_periods=1) >>> rolling.reduce(np.nansum) Size: 64B array([[ 0., 1., 3., 6.], [ 4., 9., 15., 18.]]) - Dimensions without coordinates: a, b """ keep_attrs = self._get_keep_attrs(keep_attrs) @@ -1144,7 +1139,6 @@ def construct( Size: 192B array([[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]]) - Dimensions without coordinates: year, month See Also -------- @@ -1299,7 +1293,6 @@ def reduce( Size: 32B array([[ 1, 5], [ 9, 13]]) - Dimensions without coordinates: a, b """ wrapped_func = self._reduce_method(func) return wrapped_func(self, keep_attrs=keep_attrs, **kwargs) diff --git a/xarray/computation/rolling_exp.py b/xarray/computation/rolling_exp.py index 010cf1fe31a..cbb131a39b3 100644 --- a/xarray/computation/rolling_exp.py +++ b/xarray/computation/rolling_exp.py @@ -108,7 +108,6 @@ def mean(self, keep_attrs: bool | None = None) -> T_DataWithCoords: >>> da.rolling_exp(x=2, window_type="span").mean() Size: 40B array([1. , 1. , 1.69230769, 1.9 , 1.96694215]) - Dimensions without coordinates: x """ import numbagg @@ -146,7 +145,6 @@ def sum(self, keep_attrs: bool | None = None) -> T_DataWithCoords: >>> da.rolling_exp(x=2, window_type="span").sum() Size: 40B array([1. , 1.33333333, 2.44444444, 2.81481481, 2.9382716 ]) - Dimensions without coordinates: x """ import numbagg @@ -179,7 +177,6 @@ def std(self) -> T_DataWithCoords: >>> da.rolling_exp(x=2, window_type="span").std() Size: 40B array([ nan, 0. , 0.67936622, 0.42966892, 0.25389527]) - Dimensions without coordinates: x """ import numbagg @@ -209,7 +206,6 @@ def var(self) -> T_DataWithCoords: >>> da.rolling_exp(x=2, window_type="span").var() Size: 40B array([ nan, 0. , 0.46153846, 0.18461538, 0.06446281]) - Dimensions without coordinates: x """ dim_order = self.obj.dims import numbagg @@ -237,7 +233,6 @@ def cov(self, other: T_DataWithCoords) -> T_DataWithCoords: >>> da.rolling_exp(x=2, window_type="span").cov(da**2) Size: 40B array([ nan, 0. , 1.38461538, 0.55384615, 0.19338843]) - Dimensions without coordinates: x """ dim_order = self.obj.dims @@ -267,7 +262,6 @@ def corr(self, other: T_DataWithCoords) -> T_DataWithCoords: >>> da.rolling_exp(x=2, window_type="span").corr(da.shift(x=1)) Size: 40B array([ nan, nan, nan, 0.4330127 , 0.48038446]) - Dimensions without coordinates: x """ dim_order = self.obj.dims diff --git a/xarray/core/_aggregations.py b/xarray/core/_aggregations.py index 6b1029791ea..d365581e58f 100644 --- a/xarray/core/_aggregations.py +++ b/xarray/core/_aggregations.py @@ -1198,7 +1198,6 @@ def cumsum( Group: / Dimensions: (time: 6) - Dimensions without coordinates: time Data variables: foo (time) float64 48B 1.0 3.0 6.0 6.0 8.0 8.0 @@ -1208,7 +1207,6 @@ def cumsum( Group: / Dimensions: (time: 6) - Dimensions without coordinates: time Data variables: foo (time) float64 48B 1.0 3.0 6.0 6.0 8.0 nan """ @@ -1303,7 +1301,6 @@ def cumprod( Group: / Dimensions: (time: 6) - Dimensions without coordinates: time Data variables: foo (time) float64 48B 1.0 2.0 6.0 0.0 0.0 0.0 @@ -1313,7 +1310,6 @@ def cumprod( Group: / Dimensions: (time: 6) - Dimensions without coordinates: time Data variables: foo (time) float64 48B 1.0 2.0 6.0 0.0 0.0 nan """ @@ -2412,7 +2408,6 @@ def cumsum( >>> ds.cumsum() Size: 48B Dimensions: (time: 6) - Dimensions without coordinates: time Data variables: da (time) float64 48B 1.0 3.0 6.0 6.0 8.0 8.0 @@ -2421,7 +2416,6 @@ def cumsum( >>> ds.cumsum(skipna=False) Size: 48B Dimensions: (time: 6) - Dimensions without coordinates: time Data variables: da (time) float64 48B 1.0 3.0 6.0 6.0 8.0 nan """ @@ -2510,7 +2504,6 @@ def cumprod( >>> ds.cumprod() Size: 48B Dimensions: (time: 6) - Dimensions without coordinates: time Data variables: da (time) float64 48B 1.0 2.0 6.0 0.0 0.0 0.0 @@ -2519,7 +2512,6 @@ def cumprod( >>> ds.cumprod(skipna=False) Size: 48B Dimensions: (time: 6) - Dimensions without coordinates: time Data variables: da (time) float64 48B 1.0 2.0 6.0 0.0 0.0 nan """ @@ -5012,7 +5004,6 @@ def cumsum( >>> ds.groupby("labels").cumsum() Size: 48B Dimensions: (time: 6) - Dimensions without coordinates: time Data variables: da (time) float64 48B 1.0 2.0 3.0 3.0 4.0 1.0 @@ -5021,7 +5012,6 @@ def cumsum( >>> ds.groupby("labels").cumsum(skipna=False) Size: 48B Dimensions: (time: 6) - Dimensions without coordinates: time Data variables: da (time) float64 48B 1.0 2.0 3.0 3.0 4.0 nan """ @@ -5116,7 +5106,6 @@ def cumprod( >>> ds.groupby("labels").cumprod() Size: 48B Dimensions: (time: 6) - Dimensions without coordinates: time Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 4.0 1.0 @@ -5125,7 +5114,6 @@ def cumprod( >>> ds.groupby("labels").cumprod(skipna=False) Size: 48B Dimensions: (time: 6) - Dimensions without coordinates: time Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 4.0 nan """ @@ -6510,7 +6498,6 @@ def cumsum( >>> ds.resample(time="3ME").cumsum() Size: 48B Dimensions: (time: 6) - Dimensions without coordinates: time Data variables: da (time) float64 48B 1.0 2.0 5.0 5.0 2.0 2.0 @@ -6519,7 +6506,6 @@ def cumsum( >>> ds.resample(time="3ME").cumsum(skipna=False) Size: 48B Dimensions: (time: 6) - Dimensions without coordinates: time Data variables: da (time) float64 48B 1.0 2.0 5.0 5.0 2.0 nan """ @@ -6614,7 +6600,6 @@ def cumprod( >>> ds.resample(time="3ME").cumprod() Size: 48B Dimensions: (time: 6) - Dimensions without coordinates: time Data variables: da (time) float64 48B 1.0 2.0 6.0 0.0 2.0 2.0 @@ -6623,7 +6608,6 @@ def cumprod( >>> ds.resample(time="3ME").cumprod(skipna=False) Size: 48B Dimensions: (time: 6) - Dimensions without coordinates: time Data variables: da (time) float64 48B 1.0 2.0 6.0 0.0 2.0 nan """ @@ -9297,7 +9281,6 @@ def cumsum( array([1., 2., 5., 5., 2., 2.]) Coordinates: labels (time) >> da.str.len() Size: 40B array([4, 4, 2, 2, 5]) - Dimensions without coordinates: dim_0 It also implements ``+``, ``*``, and ``%``, which operate as elementwise versions of the corresponding ``str`` methods. These will automatically @@ -164,7 +163,6 @@ class StringAccessor(Generic[T_DataArray]): array([['first1', 'first2', 'first3'], ['second1', 'second2', 'second3'], ['third1', 'third2', 'third3']], dtype='>> da1 = xr.DataArray(["a", "b", "c", "d"], dims=["X"]) >>> reps = xr.DataArray([3, 4], dims=["Y"]) @@ -174,7 +172,6 @@ class StringAccessor(Generic[T_DataArray]): ['bbb', 'bbbb'], ['ccc', 'cccc'], ['ddd', 'dddd']], dtype='>> da1 = xr.DataArray(["%s_%s", "%s-%s", "%s|%s"], dims=["X"]) >>> da2 = xr.DataArray([1, 2], dims=["Y"]) @@ -189,7 +186,6 @@ class StringAccessor(Generic[T_DataArray]): [['1|0.1', '1|0.2'], ['2|0.1', '2|0.2']]], dtype='>> da2 = xr.DataArray([1, 2, 3], dims=["Y"]) >>> da1 % {"a": da2} Size: 8B - array([' Size: 24B\narray([1, 2, 3])\nDimensions without coordinates: Y'], + array([' Size: 24B\narray([1, 2, 3])'], dtype=object) - Dimensions without coordinates: X """ __slots__ = ("_obj",) @@ -492,7 +487,6 @@ def cat(self, *others, sep: str | bytes | Any = "") -> T_DataArray: [['4 a 3.4 test', '4, a, 3.4, , test'], ['4 bb 3.4 test', '4, bb, 3.4, , test'], ['4 cccc 3.4 test', '4, cccc, 3.4, , test']]], dtype=' Size: 192B array([['a-bab-abc', 'a_bab_abc'], ['abcd--abcdef', 'abcd__abcdef']], dtype=' T_DataArray: Size: 224B array(['temperature', 'PRESSURE', 'PreCipiTation', 'daily rainfall'], dtype='>> capitalized = da.str.capitalize() >>> capitalized Size: 224B array(['Temperature', 'Pressure', 'Precipitation', 'Daily rainfall'], dtype=' T_DataArray: >>> da Size: 88B array(['Temperature', 'PRESSURE'], dtype='>> lowered = da.str.lower() >>> lowered Size: 88B array(['temperature', 'pressure'], dtype=' T_DataArray: >>> da Size: 132B array(['temperature', 'PRESSURE', 'HuMiDiTy'], dtype='>> swapcased = da.str.swapcase() >>> swapcased Size: 132B array(['TEMPERATURE', 'pressure', 'hUmIdItY'], dtype=' T_DataArray: >>> da Size: 132B array(['temperature', 'PRESSURE', 'HuMiDiTy'], dtype='>> titled = da.str.title() >>> titled Size: 132B array(['Temperature', 'Pressure', 'Humidity'], dtype=' T_DataArray: >>> da Size: 88B array(['temperature', 'HuMiDiTy'], dtype='>> uppered = da.str.upper() >>> uppered Size: 88B array(['TEMPERATURE', 'HUMIDITY'], dtype=' T_DataArray: >>> da Size: 88B array(['TEMPERATURE', 'HuMiDiTy'], dtype='>> casefolded = da.str.casefold() >>> casefolded Size: 88B array(['temperature', 'humidity'], dtype='>> da = xr.DataArray(["ß", "İ"], dims="x") >>> da Size: 8B array(['ß', 'İ'], dtype='>> casefolded = da.str.casefold() >>> casefolded Size: 16B array(['ss', 'i̇'], dtype=' T_DataArray: >>> da Size: 40B array(['H2O', 'NaCl-'], dtype='>> isalnum = da.str.isalnum() >>> isalnum Size: 2B array([ True, False]) - Dimensions without coordinates: x """ return self._apply(func=lambda x: x.isalnum(), dtype=bool) @@ -889,12 +865,10 @@ def isalpha(self) -> T_DataArray: >>> da Size: 60B array(['Mn', 'H2O', 'NaCl-'], dtype='>> isalpha = da.str.isalpha() >>> isalpha Size: 3B array([ True, False, False]) - Dimensions without coordinates: x """ return self._apply(func=lambda x: x.isalpha(), dtype=bool) @@ -913,12 +887,10 @@ def isdecimal(self) -> T_DataArray: >>> da Size: 36B array(['2.3', '123', '0'], dtype='>> isdecimal = da.str.isdecimal() >>> isdecimal Size: 3B array([False, True, True]) - Dimensions without coordinates: x """ return self._apply(func=lambda x: x.isdecimal(), dtype=bool) @@ -937,12 +909,10 @@ def isdigit(self) -> T_DataArray: >>> da Size: 80B array(['123', '1.2', '0', 'CO2', 'NaCl'], dtype='>> isdigit = da.str.isdigit() >>> isdigit Size: 5B array([ True, False, True, False, False]) - Dimensions without coordinates: x """ return self._apply(func=lambda x: x.isdigit(), dtype=bool) @@ -962,12 +932,10 @@ def islower(self) -> T_DataArray: >>> da Size: 156B array(['temperature', 'HUMIDITY', 'pREciPiTaTioN'], dtype='>> islower = da.str.islower() >>> islower Size: 3B array([ True, False, False]) - Dimensions without coordinates: x """ return self._apply(func=lambda x: x.islower(), dtype=bool) @@ -986,12 +954,10 @@ def isnumeric(self) -> T_DataArray: >>> da Size: 100B array(['123', '2.3', 'H2O', 'NaCl-', 'Mn'], dtype='>> isnumeric = da.str.isnumeric() >>> isnumeric Size: 5B array([ True, False, False, False, False]) - Dimensions without coordinates: x """ return self._apply(func=lambda x: x.isnumeric(), dtype=bool) @@ -1010,12 +976,10 @@ def isspace(self) -> T_DataArray: >>> da Size: 16B array(['', ' ', '\\t', '\\n'], dtype='>> isspace = da.str.isspace() >>> isspace Size: 4B array([False, True, True, True]) - Dimensions without coordinates: x """ return self._apply(func=lambda x: x.isspace(), dtype=bool) @@ -1042,12 +1006,10 @@ def istitle(self) -> T_DataArray: Size: 360B array(['The Evolution Of Species', 'The Theory of relativity', 'the quantum mechanics of atoms'], dtype='>> istitle = da.str.istitle() >>> istitle Size: 3B array([ True, False, False]) - Dimensions without coordinates: title """ return self._apply(func=lambda x: x.istitle(), dtype=bool) @@ -1066,12 +1028,10 @@ def isupper(self) -> T_DataArray: >>> da Size: 156B array(['TEMPERATURE', 'humidity', 'PreCIpiTAtioN'], dtype='>> isupper = da.str.isupper() >>> isupper Size: 3B array([ True, False, False]) - Dimensions without coordinates: x """ return self._apply(func=lambda x: x.isupper(), dtype=bool) @@ -1114,20 +1074,17 @@ def count( >>> da Size: 108B array(['jjklmn', 'opjjqrs', 't-JJ99vwx'], dtype='>> da.str.count("jj") Size: 24B array([1, 1, 0]) - Dimensions without coordinates: x Enable case-insensitive matching by setting case to false: >>> counts = da.str.count("jj", case=False) >>> counts Size: 24B array([1, 1, 1]) - Dimensions without coordinates: x Using regex: >>> pat = "JJ[0-9]{2}[a-z]{3}" @@ -1135,7 +1092,6 @@ def count( >>> counts Size: 24B array([0, 0, 1]) - Dimensions without coordinates: x Using an array of strings (the pattern will be broadcast against the array): @@ -1146,7 +1102,6 @@ def count( array([[1, 0], [1, 0], [0, 1]]) - Dimensions without coordinates: x, y """ pat = self._re_compile(pat=pat, flags=flags, case=case) @@ -1178,12 +1133,10 @@ def startswith(self, pat: str | bytes | Any) -> T_DataArray: >>> da Size: 48B array(['$100', '£23', '100'], dtype='>> startswith = da.str.startswith("$") >>> startswith Size: 3B array([ True, False, False]) - Dimensions without coordinates: x """ pat = self._stringify(pat) func = lambda x, y: x.startswith(y) @@ -1214,12 +1167,10 @@ def endswith(self, pat: str | bytes | Any) -> T_DataArray: >>> da Size: 48B array(['10C', '10c', '100F'], dtype='>> endswith = da.str.endswith("C") >>> endswith Size: 3B array([ True, False, False]) - Dimensions without coordinates: x """ pat = self._stringify(pat) func = lambda x, y: x.endswith(y) @@ -1264,7 +1215,6 @@ def pad( >>> da Size: 112B array(['PAR184', 'TKO65', 'NBO9139', 'NZ39'], dtype='>> filled Size: 128B array(['00PAR184', '000TKO65', '0NBO9139', '0000NZ39'], dtype='>> filled Size: 128B array(['PAR18400', 'TKO65000', 'NBO91390', 'NZ390000'], dtype='>> filled Size: 128B array(['0PAR1840', '0TKO6500', 'NBO91390', '00NZ3900'], dtype=' Self: [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]]) - Dimensions without coordinates: x, y >>> a.where(a.x + a.y < 4) Size: 200B @@ -1175,7 +1172,6 @@ def where(self, cond: Any, other: Any = dtypes.NA, drop: bool = False) -> Self: [10., 11., nan, nan, nan], [15., nan, nan, nan, nan], [nan, nan, nan, nan, nan]]) - Dimensions without coordinates: x, y >>> a.where(a.x + a.y < 5, -1) Size: 200B @@ -1184,7 +1180,6 @@ def where(self, cond: Any, other: Any = dtypes.NA, drop: bool = False) -> Self: [10, 11, 12, -1, -1], [15, 16, -1, -1, -1], [20, -1, -1, -1, -1]]) - Dimensions without coordinates: x, y >>> a.where(a.x + a.y < 4, drop=True) Size: 128B @@ -1192,7 +1187,6 @@ def where(self, cond: Any, other: Any = dtypes.NA, drop: bool = False) -> Self: [ 5., 6., 7., nan], [10., 11., nan, nan], [15., nan, nan, nan]]) - Dimensions without coordinates: x, y >>> a.where(lambda x: x.x + x.y < 4, lambda x: -x) Size: 200B @@ -1201,7 +1195,6 @@ def where(self, cond: Any, other: Any = dtypes.NA, drop: bool = False) -> Self: [ 10, 11, -12, -13, -14], [ 15, -16, -17, -18, -19], [-20, -21, -22, -23, -24]]) - Dimensions without coordinates: x, y >>> a.where(a.x + a.y < 4, drop=True) Size: 128B @@ -1209,7 +1202,6 @@ def where(self, cond: Any, other: Any = dtypes.NA, drop: bool = False) -> Self: [ 5., 6., 7., nan], [10., 11., nan, nan], [15., nan, nan, nan]]) - Dimensions without coordinates: x, y See Also -------- @@ -1305,11 +1297,9 @@ def isnull(self, keep_attrs: bool | None = None) -> Self: >>> array Size: 24B array([ 1., nan, 3.]) - Dimensions without coordinates: x >>> array.isnull() Size: 3B array([False, True, False]) - Dimensions without coordinates: x """ from xarray.computation.apply_ufunc import apply_ufunc @@ -1348,11 +1338,9 @@ def notnull(self, keep_attrs: bool | None = None) -> Self: >>> array Size: 24B array([ 1., nan, 3.]) - Dimensions without coordinates: x >>> array.notnull() Size: 3B array([ True, False, True]) - Dimensions without coordinates: x """ from xarray.computation.apply_ufunc import apply_ufunc @@ -1387,7 +1375,6 @@ def isin(self, test_elements: Any) -> Self: >>> array.isin([1, 3]) Size: 3B array([ True, False, True]) - Dimensions without coordinates: x See Also -------- diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index 0bfb0b7ab1c..2355feeb783 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -372,7 +372,6 @@ class DataArray( lat (x, y) float64 32B 42.25 42.21 42.63 42.59 * time (time) datetime64[ns] 24B 2014-09-06 2014-09-07 2014-09-08 reference_time datetime64[ns] 8B 2014-09-05 - Dimensions without coordinates: x, y Attributes: description: Ambient temperature. units: degC @@ -1055,7 +1054,6 @@ def reset_coords( lon (x) int64 40B 10 11 12 13 14 lat (y) int64 40B 20 21 22 23 24 Pressure (x, y) int64 200B 50 51 52 53 54 55 56 57 ... 68 69 70 71 72 73 74 - Dimensions without coordinates: x, y Return Dataset with target coordinate as a data variable rather than a coordinate variable: @@ -1065,7 +1063,6 @@ def reset_coords( Coordinates: lon (x) int64 40B 10 11 12 13 14 lat (y) int64 40B 20 21 22 23 24 - Dimensions without coordinates: x, y Data variables: Pressure (x, y) int64 200B 50 51 52 53 54 55 56 ... 68 69 70 71 72 73 74 Temperature (x, y) int64 200B 0 1 2 3 4 5 6 7 8 ... 17 18 19 20 21 22 23 24 @@ -1082,7 +1079,6 @@ def reset_coords( Coordinates: lon (x) int64 40B 10 11 12 13 14 lat (y) int64 40B 20 21 22 23 24 - Dimensions without coordinates: x, y """ if names is None: names = set(self.coords) - set(self._indexes) @@ -1504,7 +1500,6 @@ def isel( [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]]) - Dimensions without coordinates: x, y >>> tgt_x = xr.DataArray(np.arange(0, 5), dims="points") >>> tgt_y = xr.DataArray(np.arange(0, 5), dims="points") @@ -1512,7 +1507,6 @@ def isel( >>> da Size: 40B array([ 0, 6, 12, 18, 24]) - Dimensions without coordinates: points """ indexers = either_dict_or_kwargs(indexers, indexers_kwargs, "isel") @@ -1659,7 +1653,6 @@ def sel( Coordinates: x (points) int64 40B 0 1 2 3 4 y (points) int64 40B 0 1 2 3 4 - Dimensions without coordinates: points """ ds = self._to_temp_dataset().sel( indexers=indexers, @@ -1703,18 +1696,15 @@ def head( [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]]) - Dimensions without coordinates: x, y >>> da.head(x=1) Size: 40B array([[0, 1, 2, 3, 4]]) - Dimensions without coordinates: x, y >>> da.head({"x": 2, "y": 2}) Size: 32B array([[0, 1], [5, 6]]) - Dimensions without coordinates: x, y """ ds = self._to_temp_dataset().head(indexers, **indexers_kwargs) return self._from_temp_dataset(ds) @@ -1746,7 +1736,6 @@ def tail( [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]]) - Dimensions without coordinates: x, y >>> da.tail(y=1) Size: 40B @@ -1755,13 +1744,11 @@ def tail( [14], [19], [24]]) - Dimensions without coordinates: x, y >>> da.tail({"x": 2, "y": 2}) Size: 32B array([[18, 19], [23, 24]]) - Dimensions without coordinates: x, y """ ds = self._to_temp_dataset().tail(indexers, **indexers_kwargs) return self._from_temp_dataset(ds) @@ -2596,7 +2583,6 @@ def swap_dims( Coordinates: x (z) >> da Size: 40B array([0, 1, 2, 3, 4]) - Dimensions without coordinates: x Add new dimension of length 2: @@ -2670,7 +2655,6 @@ def expand_dims( Size: 80B array([[0, 1, 2, 3, 4], [0, 1, 2, 3, 4]]) - Dimensions without coordinates: y, x >>> da.expand_dims(dim={"y": 2}, axis=1) Size: 80B @@ -2679,7 +2663,6 @@ def expand_dims( [2, 2], [3, 3], [4, 4]]) - Dimensions without coordinates: x, y Add a new dimension with coordinates from array: @@ -2692,7 +2675,6 @@ def expand_dims( [0, 1, 2, 3, 4]]) Coordinates: * y (y) int64 40B 0 1 2 3 4 - Dimensions without coordinates: x """ if isinstance(dim, int): raise TypeError("dim should be Hashable or sequence/mapping of Hashables") @@ -3173,7 +3155,6 @@ def drop_vars( [ 9, 10, 11]]) Coordinates: * y (y) int64 24B 70 80 90 - Dimensions without coordinates: x Removing a list of variables: @@ -3183,7 +3164,6 @@ def drop_vars( [ 3, 4, 5], [ 6, 7, 8], [ 9, 10, 11]]) - Dimensions without coordinates: x, y >>> da.drop_vars(lambda x: x.coords) Size: 96B @@ -3191,7 +3171,6 @@ def drop_vars( [ 3, 4, 5], [ 6, 7, 8], [ 9, 10, 11]]) - Dimensions without coordinates: x, y """ if callable(names): names = names(self) @@ -3341,14 +3320,12 @@ def drop_isel( [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]]) - Dimensions without coordinates: X, Y >>> da.drop_isel(X=[0, 4], Y=2) Size: 96B array([[ 5, 6, 8, 9], [10, 11, 13, 14], [15, 16, 18, 19]]) - Dimensions without coordinates: X, Y >>> da.drop_isel({"X": 3, "Y": 3}) Size: 128B @@ -3356,7 +3333,6 @@ def drop_isel( [ 5, 6, 7, 9], [10, 11, 12, 14], [20, 21, 22, 24]]) - Dimensions without coordinates: X, Y """ dataset = self._to_temp_dataset() dataset = dataset.drop_isel(indexers=indexers, **indexers_kwargs) @@ -3413,7 +3389,6 @@ def dropna( Coordinates: lat (Y) float64 32B -20.0 -20.25 -20.5 -20.75 lon (X) float64 32B 10.0 10.25 10.5 10.75 - Dimensions without coordinates: Y, X >>> da.dropna(dim="Y", how="any") Size: 64B @@ -3422,7 +3397,6 @@ def dropna( Coordinates: lat (Y) float64 16B -20.0 -20.75 lon (X) float64 32B 10.0 10.25 10.5 10.75 - Dimensions without coordinates: Y, X Drop values only if all values along the dimension are NaN: @@ -3434,7 +3408,6 @@ def dropna( Coordinates: lat (Y) float64 24B -20.0 -20.5 -20.75 lon (X) float64 32B 10.0 10.25 10.5 10.75 - Dimensions without coordinates: Y, X """ ds = self._to_temp_dataset().dropna(dim, how=how, thresh=thresh) return self._from_temp_dataset(ds) @@ -3674,7 +3647,6 @@ def ffill(self, dim: Hashable, limit: int | None = None) -> Self: Coordinates: lat (Y) float64 40B -20.0 -20.25 -20.5 -20.75 -21.0 lon (X) float64 24B 10.0 10.25 10.5 - Dimensions without coordinates: Y, X Fill all NaN values: @@ -3688,7 +3660,6 @@ def ffill(self, dim: Hashable, limit: int | None = None) -> Self: Coordinates: lat (Y) float64 40B -20.0 -20.25 -20.5 -20.75 -21.0 lon (X) float64 24B 10.0 10.25 10.5 - Dimensions without coordinates: Y, X Fill only the first of consecutive NaN values: @@ -3702,7 +3673,6 @@ def ffill(self, dim: Hashable, limit: int | None = None) -> Self: Coordinates: lat (Y) float64 40B -20.0 -20.25 -20.5 -20.75 -21.0 lon (X) float64 24B 10.0 10.25 10.5 - Dimensions without coordinates: Y, X """ from xarray.core.missing import ffill @@ -3758,7 +3728,6 @@ def bfill(self, dim: Hashable, limit: int | None = None) -> Self: Coordinates: lat (Y) float64 40B -20.0 -20.25 -20.5 -20.75 -21.0 lon (X) float64 24B 10.0 10.25 10.5 - Dimensions without coordinates: Y, X Fill all NaN values: @@ -3772,7 +3741,6 @@ def bfill(self, dim: Hashable, limit: int | None = None) -> Self: Coordinates: lat (Y) float64 40B -20.0 -20.25 -20.5 -20.75 -21.0 lon (X) float64 24B 10.0 10.25 10.5 - Dimensions without coordinates: Y, X Fill only the first of consecutive NaN values: @@ -3786,7 +3754,6 @@ def bfill(self, dim: Hashable, limit: int | None = None) -> Self: Coordinates: lat (Y) float64 40B -20.0 -20.25 -20.5 -20.75 -21.0 lon (X) float64 24B 10.0 10.25 10.5 - Dimensions without coordinates: Y, X """ from xarray.core.missing import bfill @@ -4537,7 +4504,6 @@ def from_dict(cls, d: Mapping[str, Any]) -> Self: >>> da Size: 24B array([1, 2, 3]) - Dimensions without coordinates: t >>> d = { ... "coords": { @@ -4658,12 +4624,10 @@ def broadcast_equals(self, other: Self) -> bool: >>> a Size: 16B array([1, 2]) - Dimensions without coordinates: X >>> b Size: 32B array([[1, 1], [2, 2]]) - Dimensions without coordinates: X, Y .equals returns True if two DataArrays have the same values, dimensions, and coordinates. .broadcast_equals returns True if the results of broadcasting two DataArrays against each other have the same values, dimensions, and coordinates. @@ -4714,21 +4678,17 @@ def equals(self, other: Self) -> bool: >>> a Size: 24B array([1, 2, 3]) - Dimensions without coordinates: X >>> b Size: 24B array([1, 2, 3]) - Dimensions without coordinates: X Attributes: units: m >>> c Size: 24B array([1, 2, 3]) - Dimensions without coordinates: Y >>> d Size: 24B array([3, 2, 1]) - Dimensions without coordinates: X >>> a.equals(b) True @@ -4769,19 +4729,16 @@ def identical(self, other: Self) -> bool: >>> a Size: 24B array([1, 2, 3]) - Dimensions without coordinates: X Attributes: units: m >>> b Size: 24B array([1, 2, 3]) - Dimensions without coordinates: X Attributes: units: m >>> c Size: 24B array([1, 2, 3]) - Dimensions without coordinates: X Attributes: units: ft @@ -5004,7 +4961,6 @@ def shift( >>> arr.shift(x=1) Size: 24B array([nan, 5., 6.]) - Dimensions without coordinates: x """ variable = self.variable.shift( shifts=shifts, fill_value=fill_value, **shifts_kwargs @@ -5053,7 +5009,6 @@ def roll( >>> arr.roll(x=1) Size: 24B array([7, 5, 6]) - Dimensions without coordinates: x """ ds = self._to_temp_dataset().roll( shifts=shifts, roll_coords=roll_coords, **shifts_kwargs @@ -5376,7 +5331,6 @@ def rank( >>> arr.rank("x") Size: 24B array([1., 2., 3.]) - Dimensions without coordinates: x """ ds = self._to_temp_dataset().rank(dim, pct=pct, keep_attrs=keep_attrs) @@ -5430,7 +5384,6 @@ def differentiate( [ 9, 10, 11]]) Coordinates: * x (x) float64 32B 0.0 0.1 1.1 1.2 - Dimensions without coordinates: y >>> >>> da.differentiate("x") Size: 96B @@ -5440,7 +5393,6 @@ def differentiate( [30. , 30. , 30. ]]) Coordinates: * x (x) float64 32B 0.0 0.1 1.1 1.2 - Dimensions without coordinates: y """ ds = self._to_temp_dataset().differentiate(coord, edge_order, datetime_unit) return self._from_temp_dataset(ds) @@ -5489,12 +5441,10 @@ def integrate( [ 9, 10, 11]]) Coordinates: * x (x) float64 32B 0.0 0.1 1.1 1.2 - Dimensions without coordinates: y >>> >>> da.integrate("x") Size: 24B array([5.4, 6.6, 7.8]) - Dimensions without coordinates: y """ ds = self._to_temp_dataset().integrate(coord, datetime_unit) return self._from_temp_dataset(ds) @@ -5546,7 +5496,6 @@ def cumulative_integrate( [ 9, 10, 11]]) Coordinates: * x (x) float64 32B 0.0 0.1 1.1 1.2 - Dimensions without coordinates: y >>> >>> da.cumulative_integrate("x") Size: 96B @@ -5556,7 +5505,6 @@ def cumulative_integrate( [5.4 , 6.6 , 7.8 ]]) Coordinates: * x (x) float64 32B 0.0 0.1 1.1 1.2 - Dimensions without coordinates: y """ ds = self._to_temp_dataset().cumulative_integrate(coord, datetime_unit) return self._from_temp_dataset(ds) @@ -6177,33 +6125,26 @@ def argmin( array([[ 1, 2, 1], [ 2, -5, 1], [ 2, 1, 1]]) - Dimensions without coordinates: y, z >>> array.argmin(dim="x") Size: 72B array([[1, 0, 0], [1, 1, 1], [0, 0, 1]]) - Dimensions without coordinates: y, z >>> array.argmin(dim=["x"]) {'x': Size: 72B array([[1, 0, 0], [1, 1, 1], - [0, 0, 1]]) - Dimensions without coordinates: y, z} + [0, 0, 1]])} >>> array.min(dim=("x", "z")) Size: 24B array([ 1, -5, 1]) - Dimensions without coordinates: y >>> array.argmin(dim=["x", "z"]) {'x': Size: 24B - array([0, 1, 0]) - Dimensions without coordinates: y, 'z': Size: 24B - array([2, 1, 1]) - Dimensions without coordinates: y} + array([0, 1, 0]), 'z': Size: 24B + array([2, 1, 1])} >>> array.isel(array.argmin(dim=["x", "z"])) Size: 24B array([ 1, -5, 1]) - Dimensions without coordinates: y """ result = self.variable.argmin(dim, axis, keep_attrs, skipna) if isinstance(result, dict): @@ -6278,33 +6219,26 @@ def argmax( array([[3, 3, 2], [3, 5, 2], [2, 3, 3]]) - Dimensions without coordinates: y, z >>> array.argmax(dim="x") Size: 72B array([[0, 1, 1], [0, 1, 0], [0, 1, 0]]) - Dimensions without coordinates: y, z >>> array.argmax(dim=["x"]) {'x': Size: 72B array([[0, 1, 1], [0, 1, 0], - [0, 1, 0]]) - Dimensions without coordinates: y, z} + [0, 1, 0]])} >>> array.max(dim=("x", "z")) Size: 24B array([3, 5, 3]) - Dimensions without coordinates: y >>> array.argmax(dim=["x", "z"]) {'x': Size: 24B array([0, 1, 0]) - Dimensions without coordinates: y, 'z': Size: 24B - array([0, 1, 2]) - Dimensions without coordinates: y} + array([0, 1, 2])} >>> array.isel(array.argmax(dim=["x", "z"])) Size: 24B array([3, 5, 3]) - Dimensions without coordinates: y """ result = self.variable.argmax(dim, axis, keep_attrs, skipna) if isinstance(result, dict): @@ -6374,11 +6308,9 @@ def query( >>> da Size: 40B array([0, 1, 2, 3, 4]) - Dimensions without coordinates: x >>> da.query(x="a > 2") Size: 16B array([3, 4]) - Dimensions without coordinates: x """ ds = self._to_dataset_whole(shallow_copy=True) @@ -6884,7 +6816,6 @@ def groupby( [ 9, 11, 13]]) Coordinates: * letters (letters) object 16B 'a' 'b' - Dimensions without coordinates: y Grouping by multiple variables @@ -6907,7 +6838,6 @@ def groupby( Coordinates: * x_bins (x_bins) interval[int64, right] 32B (5, 15] (15, 25] * letters (letters) object 16B 'a' 'b' - Dimensions without coordinates: y See Also diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 6de626a159b..79cc716da72 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -316,7 +316,6 @@ class Dataset( * instrument (instrument) Self: Dimensions: (dim_0: 2, dim_1: 3, x: 2) Coordinates: * x (x) Self: Dimensions: (dim_0: 2, dim_1: 3, x: 2) Coordinates: * x (x) Self: Dimensions: (dim_0: 2, dim_1: 3, x: 2) Coordinates: * x (x) Self: Dimensions: (dim_0: 2, dim_1: 3, x: 2) Coordinates: * x (x) Self: Dimensions: (dim_0: 2, dim_1: 3, x: 2) Coordinates: * x (x) >> dataset.expand_dims(dim="time") Size: 8B Dimensions: (time: 1) - Dimensions without coordinates: time Data variables: temperature (time) float64 8B 25.0 @@ -4416,7 +4408,6 @@ def expand_dims( >>> dataset_1d Size: 24B Dimensions: (x: 3) - Dimensions without coordinates: x Data variables: temperature (x) float64 24B 25.0 26.5 24.8 @@ -4425,7 +4416,6 @@ def expand_dims( >>> dataset_1d.expand_dims(dim="time", axis=0) Size: 24B Dimensions: (time: 1, x: 3) - Dimensions without coordinates: time, x Data variables: temperature (time, x) float64 24B 25.0 26.5 24.8 @@ -4436,7 +4426,6 @@ def expand_dims( >>> dataset_2d Size: 96B Dimensions: (y: 3, x: 4) - Dimensions without coordinates: y, x Data variables: temperature (y, x) float64 96B 0.5488 0.7152 0.6028 ... 0.7917 0.5289 @@ -4445,7 +4434,6 @@ def expand_dims( >>> dataset_2d.expand_dims(dim="time", axis=2) Size: 96B Dimensions: (y: 3, x: 4, time: 1) - Dimensions without coordinates: y, x, time Data variables: temperature (y, x, time) float64 96B 0.5488 0.7152 0.6028 ... 0.7917 0.5289 @@ -5247,7 +5235,6 @@ def to_stacked_array( Dimensions: (x: 2, y: 3) Coordinates: * y (y) >> dataset.drop_vars(lambda x: x.indexes) Size: 96B Dimensions: (time: 1, latitude: 2, longitude: 2) - Dimensions without coordinates: time, latitude, longitude Data variables: temperature (time, latitude, longitude) float64 32B 25.5 26.3 27.1 28.0 humidity (time, latitude, longitude) float64 32B 65.0 63.8 58.2 59.6 @@ -5952,7 +5937,6 @@ def drop_sel( Dimensions: (x: 2, y: 3) Coordinates: * y (y) >> ds.drop_sel(y=["a", "c"]) @@ -5960,7 +5944,6 @@ def drop_sel( Dimensions: (x: 2, y: 1) Coordinates: * y (y) >> ds.drop_sel(y="b") @@ -5968,7 +5951,6 @@ def drop_sel( Dimensions: (x: 2, y: 2) Coordinates: * y (y) Self: Dimensions: (x: 2, y: 3) Coordinates: * y (y) >> ds.drop_isel(y=[0, 2]) @@ -6030,7 +6011,6 @@ def drop_isel(self, indexers=None, **indexers_kwargs) -> Self: Dimensions: (x: 2, y: 1) Coordinates: * y (y) >> ds.drop_isel(y=1) @@ -6038,7 +6018,6 @@ def drop_isel(self, indexers=None, **indexers_kwargs) -> Self: Dimensions: (x: 2, y: 2) Coordinates: * y (y) >> ds Size: 64B Dimensions: (dim_0: 2, dim_1: 3, x: 2) - Dimensions without coordinates: dim_0, dim_1, x Data variables: foo (dim_0, dim_1) float64 48B 1.764 0.4002 0.9787 2.241 1.868 -0.9773 bar (x) int64 16B -1 2 >>> ds.map(np.fabs) Size: 64B Dimensions: (dim_0: 2, dim_1: 3, x: 2) - Dimensions without coordinates: dim_0, dim_1, x Data variables: foo (dim_0, dim_1) float64 48B 1.764 0.4002 0.9787 2.241 1.868 0.9773 bar (x) float64 16B 1.0 2.0 @@ -7688,13 +7665,11 @@ def diff( >>> ds.diff("x") Size: 24B Dimensions: (x: 3) - Dimensions without coordinates: x Data variables: foo (x) int64 24B 0 1 0 >>> ds.diff("x", 2) Size: 16B Dimensions: (x: 2) - Dimensions without coordinates: x Data variables: foo (x) int64 16B 1 -1 @@ -7784,7 +7759,6 @@ def shift( >>> ds.shift(x=2) Size: 40B Dimensions: (x: 5) - Dimensions without coordinates: x Data variables: foo (x) object 40B nan nan 'a' 'b' 'c' """ @@ -8583,7 +8557,6 @@ def filter_by_attrs(self, **kwargs) -> Self: lat (x, y) float64 32B 42.25 42.21 42.63 42.59 * time (time) datetime64[ns] 24B 2014-09-06 2014-09-07 2014-09-08 reference_time datetime64[ns] 8B 2014-09-05 - Dimensions without coordinates: x, y Data variables: precipitation (x, y, time) float64 96B 5.68 9.256 0.7104 ... 4.615 7.805 @@ -8598,7 +8571,6 @@ def filter_by_attrs(self, **kwargs) -> Self: lat (x, y) float64 32B 42.25 42.21 42.63 42.59 * time (time) datetime64[ns] 24B 2014-09-06 2014-09-07 2014-09-08 reference_time datetime64[ns] 8B 2014-09-05 - Dimensions without coordinates: x, y Data variables: temperature (x, y, time) float64 96B 29.11 18.2 22.83 ... 16.15 26.63 precipitation (x, y, time) float64 96B 5.68 9.256 0.7104 ... 4.615 7.805 @@ -8938,7 +8910,6 @@ def pad( >>> ds.pad(x=(1, 2)) Size: 64B Dimensions: (x: 8) - Dimensions without coordinates: x Data variables: foo (x) float64 64B nan 0.0 1.0 2.0 3.0 4.0 nan nan """ @@ -9437,7 +9408,6 @@ def eval( >>> ds Size: 80B Dimensions: (x: 5) - Dimensions without coordinates: x Data variables: a (x) int64 40B 0 1 2 3 4 b (x) float64 40B 0.0 0.25 0.5 0.75 1.0 @@ -9445,12 +9415,10 @@ def eval( >>> ds.eval("a + b") Size: 40B array([0. , 1.25, 2.5 , 3.75, 5. ]) - Dimensions without coordinates: x >>> ds.eval("c = a + b") Size: 120B Dimensions: (x: 5) - Dimensions without coordinates: x Data variables: a (x) int64 40B 0 1 2 3 4 b (x) float64 40B 0.0 0.25 0.5 0.75 1.0 @@ -9532,14 +9500,12 @@ def query( >>> ds Size: 80B Dimensions: (x: 5) - Dimensions without coordinates: x Data variables: a (x) int64 40B 0 1 2 3 4 b (x) float64 40B 0.0 0.25 0.5 0.75 1.0 >>> ds.query(x="a > 2") Size: 32B Dimensions: (x: 2) - Dimensions without coordinates: x Data variables: a (x) int64 16B 3 4 b (x) float64 16B 0.75 1.0 @@ -9911,7 +9877,6 @@ def groupby( Dimensions: (letters: 2, y: 3) Coordinates: * letters (letters) object 16B 'a' 'b' - Dimensions without coordinates: y Data variables: foo (letters, y) int64 48B 9 11 13 9 11 13 @@ -9932,7 +9897,6 @@ def groupby( Coordinates: * x_bins (x_bins) interval[int64, right] 32B (5, 15] (15, 25] * letters (letters) object 16B 'a' 'b' - Dimensions without coordinates: y Data variables: foo (y, x_bins, letters) float64 96B 0.0 nan nan 3.0 ... nan nan 5.0 diff --git a/xarray/core/datatree.py b/xarray/core/datatree.py index afef2f20094..da6c7cb2e44 100644 --- a/xarray/core/datatree.py +++ b/xarray/core/datatree.py @@ -407,14 +407,12 @@ def map( # type: ignore[override] >>> ds Size: 64B Dimensions: (dim_0: 2, dim_1: 3, x: 2) - Dimensions without coordinates: dim_0, dim_1, x Data variables: foo (dim_0, dim_1) float64 48B 1.764 0.4002 0.9787 2.241 1.868 -0.9773 bar (x) int64 16B -1 2 >>> ds.map(np.fabs) Size: 64B Dimensions: (dim_0: 2, dim_1: 3, x: 2) - Dimensions without coordinates: dim_0, dim_1, x Data variables: foo (dim_0, dim_1) float64 48B 1.764 0.4002 0.9787 2.241 1.868 0.9773 bar (x) float64 16B 1.0 2.0 @@ -593,7 +591,6 @@ def _to_dataset_view(self, rebuild_dims: bool, inherit: bool) -> DatasetView: # >>> ds # Size: 0B # Dimensions: (x: 2) - # Dimensions without coordinates: x # Data variables: # *empty* # diff --git a/xarray/plot/utils.py b/xarray/plot/utils.py index fc4ca1532e5..c51cd3ec204 100644 --- a/xarray/plot/utils.py +++ b/xarray/plot/utils.py @@ -1508,28 +1508,23 @@ def values(self) -> DataArray | None: >>> _Normalize(a).values Size: 40B array([3, 1, 1, 3, 5]) - Dimensions without coordinates: dim_0 >>> _Normalize(a, width=(18, 36, 72)).values Size: 40B array([45., 18., 18., 45., 72.]) - Dimensions without coordinates: dim_0 >>> a = xr.DataArray([0.5, 0, 0, 0.5, 2, 3]) >>> _Normalize(a).values Size: 48B array([0.5, 0. , 0. , 0.5, 2. , 3. ]) - Dimensions without coordinates: dim_0 >>> _Normalize(a, width=(18, 36, 72)).values Size: 48B array([27., 18., 18., 27., 54., 72.]) - Dimensions without coordinates: dim_0 >>> _Normalize(a * 0, width=(18, 36, 72)).values Size: 48B array([36., 36., 36., 36., 36., 36.]) - Dimensions without coordinates: dim_0 """ if self.data is None: diff --git a/xarray/structure/alignment.py b/xarray/structure/alignment.py index b05271dfdf5..52fdcbb6f4d 100644 --- a/xarray/structure/alignment.py +++ b/xarray/structure/alignment.py @@ -1237,24 +1237,20 @@ def broadcast( >>> a Size: 24B array([1, 2, 3]) - Dimensions without coordinates: x >>> b Size: 16B array([5, 6]) - Dimensions without coordinates: y >>> a2, b2 = xr.broadcast(a, b) >>> a2 Size: 48B array([[1, 1], [2, 2], [3, 3]]) - Dimensions without coordinates: x, y >>> b2 Size: 48B array([[5, 6], [5, 6], [5, 6]]) - Dimensions without coordinates: x, y Fill out the dimensions of all data variables in a dataset: @@ -1263,7 +1259,6 @@ def broadcast( >>> ds2 Size: 96B Dimensions: (x: 3, y: 2) - Dimensions without coordinates: x, y Data variables: a (x, y) int64 48B 1 1 2 2 3 3 b (x, y) int64 48B 5 6 5 6 5 6 diff --git a/xarray/structure/combine.py b/xarray/structure/combine.py index 63c3e4cc166..742de12cf5b 100644 --- a/xarray/structure/combine.py +++ b/xarray/structure/combine.py @@ -497,7 +497,6 @@ def combine_nested( >>> x1y1 Size: 64B Dimensions: (x: 2, y: 2) - Dimensions without coordinates: x, y Data variables: temperature (x, y) float64 32B 1.764 0.4002 0.9787 2.241 precipitation (x, y) float64 32B 1.868 -0.9773 0.9501 -0.1514 @@ -526,7 +525,6 @@ def combine_nested( >>> combined Size: 256B Dimensions: (x: 4, y: 4) - Dimensions without coordinates: x, y Data variables: temperature (x, y) float64 128B 1.764 0.4002 -0.1032 ... 0.04576 -0.1872 precipitation (x, y) float64 128B 1.868 -0.9773 0.761 ... 0.1549 0.3782 @@ -541,7 +539,6 @@ def combine_nested( >>> t1temp Size: 40B Dimensions: (t: 5) - Dimensions without coordinates: t Data variables: temperature (t) float64 40B -0.8878 -1.981 -0.3479 0.1563 1.23 @@ -549,7 +546,6 @@ def combine_nested( >>> t1precip Size: 40B Dimensions: (t: 5) - Dimensions without coordinates: t Data variables: precipitation (t) float64 40B 1.202 -0.3873 -0.3023 -1.049 -1.42 @@ -562,7 +558,6 @@ def combine_nested( >>> combined Size: 160B Dimensions: (t: 10) - Dimensions without coordinates: t Data variables: temperature (t) float64 80B -0.8878 -1.981 -0.3479 ... -0.4381 -1.253 precipitation (t) float64 80B 1.202 -0.3873 -0.3023 ... -0.8955 0.3869 diff --git a/xarray/structure/concat.py b/xarray/structure/concat.py index 2f1f3c28b02..39d912f3ada 100644 --- a/xarray/structure/concat.py +++ b/xarray/structure/concat.py @@ -214,7 +214,6 @@ def concat( Coordinates: x (new_dim) >> xr.concat([da.isel(x=0), da.isel(x=1)], pd.Index([-90, -100], name="new_dim")) Size: 48B diff --git a/xarray/tests/conftest.py b/xarray/tests/conftest.py index 0725559fa09..dd471ced78c 100644 --- a/xarray/tests/conftest.py +++ b/xarray/tests/conftest.py @@ -178,7 +178,6 @@ def create_test_datatree(): Group: / │ Dimensions: (y: 3, x: 2) - │ Dimensions without coordinates: y, x │ Data variables: │ a (y) int64 24B 6 7 8 │ set0 (x) int64 16B 9 10 @@ -191,7 +190,6 @@ def create_test_datatree(): │ └── Group: /set1/set2 ├── Group: /set2 │ │ Dimensions: (x: 2) - │ │ Dimensions without coordinates: x │ │ Data variables: │ │ a (x) int64 16B 2 3 │ │ b (x) float64 16B 0.1 0.2 diff --git a/xarray/tests/test_backends_datatree.py b/xarray/tests/test_backends_datatree.py index 518758a0efb..078a6ae0c35 100644 --- a/xarray/tests/test_backends_datatree.py +++ b/xarray/tests/test_backends_datatree.py @@ -79,17 +79,14 @@ def unaligned_datatree_nc(tmp_path_factory): Group: / │ Dimensions: (lat: 1, lon: 2) - │ Dimensions without coordinates: lat, lon │ Data variables: │ root_variable (lat, lon) float64 16B ... └── Group: /Group1 │ Dimensions: (lat: 1, lon: 2) - │ Dimensions without coordinates: lat, lon │ Data variables: │ group_1_var (lat, lon) float64 16B ... └── Group: /Group1/subgroup1 Dimensions: (lat: 2, lon: 2) - Dimensions without coordinates: lat, lon Data variables: subgroup1_var (lat, lon) float64 32B ... """ @@ -128,7 +125,6 @@ def unaligned_datatree_zarr_factory( """Creates a zarr store with the following unaligned group hierarchy: Group: / │ Dimensions: (y: 3, x: 2) - │ Dimensions without coordinates: y, x │ Data variables: │ a (y) int64 24B ... │ set0 (x) int64 16B ... @@ -144,7 +140,6 @@ def unaligned_datatree_zarr_factory( │ b int64 8B ... └── Group: /Group2 Dimensions: (y: 2, x: 2) - Dimensions without coordinates: y, x Data variables: a (y) int64 16B ... b (x) float64 16B ... @@ -364,17 +359,14 @@ def test_open_groups_to_dict(self, tmpdir) -> None: and `DataTree.from_dict`. Group: / │ Dimensions: (lat: 1, lon: 2) - │ Dimensions without coordinates: lat, lon │ Data variables: │ root_variable (lat, lon) float64 16B ... └── Group: /Group1 │ Dimensions: (lat: 1, lon: 2) - │ Dimensions without coordinates: lat, lon │ Data variables: │ group_1_var (lat, lon) float64 16B ... └── Group: /Group1/subgroup1 Dimensions: (lat: 1, lon: 2) - Dimensions without coordinates: lat, lon Data variables: subgroup1_var (lat, lon) float64 16B ... """ diff --git a/xarray/tests/test_dask.py b/xarray/tests/test_dask.py index eefa3c2b4f8..a8164cd6906 100644 --- a/xarray/tests/test_dask.py +++ b/xarray/tests/test_dask.py @@ -673,8 +673,7 @@ def test_dataarray_repr(self): Size: 8B {data!r} Coordinates: - y (x) int64 8B dask.array - Dimensions without coordinates: x""" + y (x) int64 8B dask.array""" ) assert expected == repr(a) assert kernel_call_count == 0 # should not evaluate dask array @@ -689,7 +688,6 @@ def test_dataset_repr(self): Dimensions: (x: 1) Coordinates: y (x) int64 8B dask.array - Dimensions without coordinates: x Data variables: a (x) int64 8B dask.array""" ) diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index 45c169bb931..ead3066ea73 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -109,7 +109,6 @@ def test_repr(self) -> None: Coordinates: * x (x) uint64 24B 0 1 2 other uint64 8B 0 - Dimensions without coordinates: time Attributes: foo: bar""" ) diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index 3e0734c8a1a..5ccf1baf21c 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -294,7 +294,6 @@ def test_repr(self) -> None: * dim3 (dim3) {data["dim3"].dtype} 40B 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' * time (time) datetime64[ns] 160B 2000-01-01 2000-01-02 ... 2000-01-20 numbers (dim3) int64 80B 0 1 2 0 0 1 1 2 2 3 - Dimensions without coordinates: dim1 Data variables: var1 (dim1, dim2) float64 576B -0.9891 -0.3678 1.288 ... -0.2116 0.364 var2 (dim1, dim2) float64 576B 0.953 1.52 1.704 ... 0.1347 -0.6423 @@ -426,7 +425,6 @@ def __repr__(self): """\ Size: 16B Dimensions: (x: 2) - Dimensions without coordinates: x Data variables: foo (x) float64 16B Custom Array""" ) diff --git a/xarray/tests/test_datatree.py b/xarray/tests/test_datatree.py index 2bf079a7cbd..338b91bad31 100644 --- a/xarray/tests/test_datatree.py +++ b/xarray/tests/test_datatree.py @@ -1116,7 +1116,6 @@ def test_repr_four_nodes(self) -> None: │ e (x) float64 16B 1.0 2.0 └── Group: /b │ Dimensions: (y: 1) - │ Dimensions without coordinates: y │ Data variables: │ f (y) float64 8B 3.0 ├── Group: /b/c @@ -1136,7 +1135,6 @@ def test_repr_four_nodes(self) -> None: │ Dimensions: (x: 2, y: 1) │ Inherited coordinates: │ * x (x) float64 16B 2.0 3.0 - │ Dimensions without coordinates: y │ Data variables: │ f (y) float64 8B 3.0 ├── Group: /b/c @@ -1156,7 +1154,6 @@ def test_repr_four_nodes(self) -> None: Dimensions: (x: 2, y: 1) Inherited coordinates: * x (x) float64 16B 2.0 3.0 - Dimensions without coordinates: y Data variables: g float64 8B 4.0 """ @@ -1303,12 +1300,10 @@ def test_repr_inherited_dims(self) -> None: Group: / │ Dimensions: (x: 1) - │ Dimensions without coordinates: x │ Data variables: │ foo (x) float64 8B 1.0 └── Group: /child Dimensions: (y: 1) - Dimensions without coordinates: y Data variables: bar (y) float64 8B 2.0 """ @@ -1321,7 +1316,6 @@ def test_repr_inherited_dims(self) -> None: Group: /child Dimensions: (x: 1, y: 1) - Dimensions without coordinates: x, y Data variables: bar (y) float64 8B 2.0 """ @@ -1517,12 +1511,10 @@ def test_inconsistent_dims(self) -> None: group '/b' is not aligned with its parents: Group: Dimensions: (x: 1) - Dimensions without coordinates: x Data variables: c (x) float64 8B 3.0 From parents: Dimensions: (x: 2) - Dimensions without coordinates: x """ ) @@ -1623,12 +1615,10 @@ def test_inconsistent_grandchild_dims(self) -> None: group '/b/c' is not aligned with its parents: Group: Dimensions: (x: 1) - Dimensions without coordinates: x Data variables: d (x) float64 8B 3.0 From parents: Dimensions: (x: 2) - Dimensions without coordinates: x """ ) diff --git a/xarray/tests/test_formatting.py b/xarray/tests/test_formatting.py index 88c2c819405..8de6cafd1b3 100644 --- a/xarray/tests/test_formatting.py +++ b/xarray/tests/test_formatting.py @@ -545,8 +545,7 @@ def test_array_repr(self) -> None: expected = dedent( """\ Size: 8B - array([0], dtype=uint64) - Dimensions without coordinates: test""" + array([0], dtype=uint64)""" ) assert actual == expected @@ -564,8 +563,7 @@ def test_array_repr(self) -> None: expected = dedent( """\ Size: 8B - 0 - Dimensions without coordinates: test""" + 0""" ) assert actual == expected @@ -830,8 +828,7 @@ def test_repr_file_collapsed(tmp_path) -> None: expected = dedent( """\ Size: 2kB - [300 values with dtype=int64] - Dimensions without coordinates: test""" + [300 values with dtype=int64]""" ) assert actual == expected @@ -841,8 +838,7 @@ def test_repr_file_collapsed(tmp_path) -> None: expected = dedent( """\ Size: 2kB - 0 1 2 3 4 5 6 7 8 9 10 11 12 ... 288 289 290 291 292 293 294 295 296 297 298 299 - Dimensions without coordinates: test""" + 0 1 2 3 4 5 6 7 8 9 10 11 12 ... 288 289 290 291 292 293 294 295 296 297 298 299""" ) assert actual == expected @@ -930,34 +926,6 @@ def test__mapping_repr_recursive() -> None: formatting.dataset_repr(ds2) -def test__element_formatter(n_elements: int = 100) -> None: - expected = """\ - Dimensions without coordinates: dim_0: 3, dim_1: 3, dim_2: 3, dim_3: 3, - dim_4: 3, dim_5: 3, dim_6: 3, dim_7: 3, - dim_8: 3, dim_9: 3, dim_10: 3, dim_11: 3, - dim_12: 3, dim_13: 3, dim_14: 3, dim_15: 3, - dim_16: 3, dim_17: 3, dim_18: 3, dim_19: 3, - dim_20: 3, dim_21: 3, dim_22: 3, dim_23: 3, - ... - dim_76: 3, dim_77: 3, dim_78: 3, dim_79: 3, - dim_80: 3, dim_81: 3, dim_82: 3, dim_83: 3, - dim_84: 3, dim_85: 3, dim_86: 3, dim_87: 3, - dim_88: 3, dim_89: 3, dim_90: 3, dim_91: 3, - dim_92: 3, dim_93: 3, dim_94: 3, dim_95: 3, - dim_96: 3, dim_97: 3, dim_98: 3, dim_99: 3""" - expected = dedent(expected) - - intro = "Dimensions without coordinates: " - elements = [ - f"{k}: {v}" for k, v in {f"dim_{k}": 3 for k in np.arange(n_elements)}.items() - ] - values = xr.core.formatting._element_formatter( - elements, col_width=len(intro), max_rows=12 - ) - actual = intro + values - assert expected == actual - - def test_lazy_array_wont_compute() -> None: from xarray.core.indexing import LazilyIndexedArray @@ -1069,7 +1037,6 @@ def test_array_repr_dtypes(): expected = """ Size: 1B array([0], dtype=int8) -Dimensions without coordinates: x """.strip() assert actual == expected @@ -1078,7 +1045,6 @@ def test_array_repr_dtypes(): expected = """ Size: 2B array([0], dtype=int16) -Dimensions without coordinates: x """.strip() assert actual == expected @@ -1089,7 +1055,6 @@ def test_array_repr_dtypes(): expected = """ Size: 1B array([0], dtype=uint8) -Dimensions without coordinates: x """.strip() assert actual == expected @@ -1098,7 +1063,6 @@ def test_array_repr_dtypes(): expected = """ Size: 2B array([0], dtype=uint16) -Dimensions without coordinates: x """.strip() assert actual == expected @@ -1107,7 +1071,6 @@ def test_array_repr_dtypes(): expected = """ Size: 4B array([0], dtype=uint32) -Dimensions without coordinates: x """.strip() assert actual == expected @@ -1116,7 +1079,6 @@ def test_array_repr_dtypes(): expected = """ Size: 8B array([0], dtype=uint64) -Dimensions without coordinates: x """.strip() assert actual == expected @@ -1127,7 +1089,6 @@ def test_array_repr_dtypes(): expected = """ Size: 8B array([0.]) -Dimensions without coordinates: x """.strip() assert actual == expected @@ -1136,7 +1097,6 @@ def test_array_repr_dtypes(): expected = """ Size: 2B array([0.], dtype=float16) -Dimensions without coordinates: x """.strip() assert actual == expected @@ -1145,7 +1105,6 @@ def test_array_repr_dtypes(): expected = """ Size: 4B array([0.], dtype=float32) -Dimensions without coordinates: x """.strip() assert actual == expected @@ -1154,7 +1113,6 @@ def test_array_repr_dtypes(): expected = """ Size: 8B array([0.]) -Dimensions without coordinates: x """.strip() assert actual == expected @@ -1166,7 +1124,6 @@ def test_array_repr_dtypes(): expected = f""" Size: {array.dtype.itemsize}B {array!r} -Dimensions without coordinates: x """.strip() assert actual == expected @@ -1176,7 +1133,6 @@ def test_array_repr_dtypes(): expected = f""" Size: 4B {array!r} -Dimensions without coordinates: x """.strip() assert actual == expected @@ -1186,6 +1142,5 @@ def test_array_repr_dtypes(): expected = f""" Size: 8B {array!r} -Dimensions without coordinates: x """.strip() assert actual == expected diff --git a/xarray/tests/test_sparse.py b/xarray/tests/test_sparse.py index f33a906947e..1ba6daadbd9 100644 --- a/xarray/tests/test_sparse.py +++ b/xarray/tests/test_sparse.py @@ -692,8 +692,7 @@ def test_dataarray_repr(self): Size: 64B Coordinates: - y (x) int64 48B - Dimensions without coordinates: x""" + y (x) int64 48B """ ) assert expected == repr(a) @@ -708,7 +707,6 @@ def test_dataset_repr(self): Dimensions: (x: 4) Coordinates: y (x) int64 48B - Dimensions without coordinates: x Data variables: a (x) float64 64B """ ) @@ -727,7 +725,6 @@ def test_sparse_dask_dataset_repr(self): f"""\ Size: 32B Dimensions: (x: 4) - Dimensions without coordinates: x Data variables: a (x) float64 32B dask.array""" ) From 8e94036ec90273ffb17480a415317d076e4dcbf4 Mon Sep 17 00:00:00 2001 From: Benoit Bovy Date: Thu, 3 Jul 2025 14:06:46 +0200 Subject: [PATCH 3/3] fix doctest --- xarray/core/dataarray.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index 2355feeb783..20eef61a7c5 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -6234,7 +6234,7 @@ def argmax( array([3, 5, 3]) >>> array.argmax(dim=["x", "z"]) {'x': Size: 24B - array([0, 1, 0]) + array([0, 1, 0]), 'z': Size: 24B array([0, 1, 2])} >>> array.isel(array.argmax(dim=["x", "z"])) Size: 24B