Skip to content

Commit 60754fd

Browse files
Check for just ..., rather than [...] in da.stack (#6132)
* Add tests for cases discussed in issue 6051 * Raise error if dims = ...
1 parent 0a40bf1 commit 60754fd

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

xarray/core/dataset.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3870,6 +3870,8 @@ def reorder_levels(
38703870
return self._replace(variables, indexes=indexes)
38713871

38723872
def _stack_once(self, dims, new_dim):
3873+
if dims == ...:
3874+
raise ValueError("Please use [...] for dims, rather than just ...")
38733875
if ... in dims:
38743876
dims = list(infix_dims(dims, self.dims))
38753877
variables = {}

xarray/tests/test_dataarray.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6678,3 +6678,17 @@ def test_from_pint_wrapping_dask(self):
66786678
expected = xr.DataArray(arr, dims="x", coords={"lat": ("x", arr * 2)})
66796679
assert_identical(result, expected)
66806680
np.testing.assert_equal(da.to_numpy(), arr)
6681+
6682+
6683+
class TestStackEllipsis:
6684+
# https://github.com/pydata/xarray/issues/6051
6685+
def test_result_as_expected(self):
6686+
da = DataArray([[1, 2], [1, 2]], dims=("x", "y"))
6687+
result = da.stack(flat=[...])
6688+
expected = da.stack(flat=da.dims)
6689+
assert_identical(result, expected)
6690+
6691+
def test_error_on_ellipsis_without_list(self):
6692+
da = DataArray([[1, 2], [1, 2]], dims=("x", "y"))
6693+
with pytest.raises(ValueError):
6694+
da.stack(flat=...)

0 commit comments

Comments
 (0)