File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -3431,6 +3431,23 @@ def test_expand_dims_kwargs_python36plus(self) -> None:
3431
3431
)
3432
3432
assert_identical (other_way_expected , other_way )
3433
3433
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
+
3434
3451
@requires_pandas_version_two
3435
3452
def test_expand_dims_non_nanosecond_conversion (self ) -> None :
3436
3453
# Regression test for https://github.com/pydata/xarray/issues/7493#issuecomment-1953091000
You can’t perform that action at this time.
0 commit comments