Skip to content

Commit 3e848eb

Browse files
committed
test expand_dims doesn't create Index
1 parent 2534712 commit 3e848eb

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

xarray/tests/test_dataset.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3431,6 +3431,23 @@ def test_expand_dims_kwargs_python36plus(self) -> None:
34313431
)
34323432
assert_identical(other_way_expected, other_way)
34333433

3434+
def test_expand_dims_creates_indexvariable(self):
3435+
# data variables should not gain an index ever
3436+
ds = Dataset({"a": 0})
3437+
for flag in [True, False]:
3438+
expanded = ds.expand_dims("x", create_1d_index=flag)
3439+
expected = Dataset({"a": ("x", [0])})
3440+
assert_identical(expanded, expected)
3441+
assert expanded.indexes == {}
3442+
3443+
# coordinate variables should gain an index only if create_1d_index is True (the default)
3444+
ds = Dataset(coords={"x": 0})
3445+
expanded = ds.expand_dims("x")
3446+
expected = Dataset({"x": ("x", [0])})
3447+
assert_identical(expanded, expected)
3448+
expanded_no_index = ds.expand_dims("x", create_1d_index=False)
3449+
assert expanded_no_index.indexes == {}
3450+
34343451
@requires_pandas_version_two
34353452
def test_expand_dims_non_nanosecond_conversion(self) -> None:
34363453
# Regression test for https://github.com/pydata/xarray/issues/7493#issuecomment-1953091000

0 commit comments

Comments
 (0)