Skip to content

Commit 16a2c03

Browse files
pletchmshoyer
authored andcommitted
Allow expand_dims() method to support inserting/broadcasting dimensions with size>1 (#2757)
* Quarter offset implemented (base is now latest pydata-master). (#2721) * Quarter offset implemented (base is now latest pydata-master). * Fixed issues raised in review (#2721 (review)) * Updated whats-new.rst with info on quarter offset support. * Updated whats-new.rst with info on quarter offset support. * Update doc/whats-new.rst Co-Authored-By: jwenfai <[email protected]> * Added support for quarter frequencies when resampling CFTimeIndex. Less redundancy in CFTimeIndex resampling tests. * Removed normalization code (unnecessary for cftime_range) in cftime_offsets.py. Removed redundant lines in whats-new.rst. * Removed invalid option from _get_day_of_month docstring. Added tests back in that raises ValueError when resampling (base=24 when resampling to daily freq, e.g., '8D'). * Minor edits to docstrings/comments * lint * Add `Dataset.drop_dims` (#2767) * ENH: Add Dataset.drop_dims() * Drops full dimensions and any corresponding variables in a Dataset * Fixes GH1949 * DOC: Add Dataset.drop_dims() documentation * Improve name concat (#2792) * Added tests of desired name inferring behaviour * Infers names * updated what's new * Don't use deprecated np.asscalar() (#2800) It got deprecated in numpy 1.16 and throws a ton of warnings due to that. All the function does is returning .item() anyway, which is why it got deprecated. * Add support for cftime.datetime coordinates with coarsen (#2778) * some docs updates (#2746) * Friendlier io title. * Fix lists. * Fix *args, **kwargs "inline emphasis..." * misc * Reference xarray_extras for csv writing. Closes #2289 * Add metpy accessor. Closes #461 * fix transpose docstring. Closes #2576 * Revert "Fix lists." This reverts commit 39983a5. * Revert "Fix *args, **kwargs" This reverts commit 1b9da35. * Add MetPy to related projects. * Add Weather and Climate specific page. * Add hvplot. * Note open_dataset, mfdataset open files as read-only (closes #2345). * Update metpy 1 Co-Authored-By: dcherian <[email protected]> * Update doc/weather-climate.rst Co-Authored-By: dcherian <[email protected]> * Drop failing tests writing multi-dimensional arrays as attributes (#2810) These aren't valid for netCDF files. Fixes GH2803 * Push back finalizing deprecations for 0.12 (#2809) 0.12 will already have a big change in dropping Python 2.7 support. I'd rather wait a bit longer to finalize these deprecations to minimize the impact on users. * enable loading remote hdf5 files (#2782) * attempt at loading remote hdf5 * added a couple tests * rewind bytes after reading header * addressed comments for tests and error message * fixed pep8 formatting * created _get_engine_from_magic_number function, new tests * added description in whats-new * fixed test failure on windows * same error on windows and nix * Release 0.12.0 * Add whats-new for 0.12.1 * Rework whats-new for 0.12 * DOC: Update donation links * DOC: remove outdated warning (#2818) * Allow expand_dims() method to support inserting/broadcasting dimensions with size>1 (#2757) * Make using dim_kwargs for python 3.5 illegal -- a ValueError is thrown * dataset.expand_dims() method take dict like object where values represent length of dimensions or coordinates of dimesnsions * dataarray.expand_dims() method take dict like object where values represent length of dimensions or coordinates of dimesnsions * Add alternative option to passing a dict to the dim argument, which is now an optional kwarg, passing in each new dimension as its own kwarg * Add expand_dims enhancement from issue 2710 to whats-new.rst * Fix test_dataarray.TestDataArray.test_expand_dims_with_greater_dim_size tests to pass in python 3.5 using ordered dicts instead of regular dicts. This was needed because python 3.5 and earlier did not maintain insertion order for dicts * Restrict core logic to use 'dim' as a dict--it will be converted into a dict on entry if it is a str or a sequence of str * Don't cast dim values (coords) as a list since IndexVariable/Variable will internally convert it into a numpy.ndarray. So just use IndexVariable((k,), v) * TypeErrors should be raised for invalid input types, rather than ValueErrors. * Force 'dim' to be OrderedDict for python 3.5 * Allow expand_dims() method to support inserting/broadcasting dimensions with size>1 (#2757) * use .size attribute to determine the size of a dimension, rather than converting to a list, which can be slow for large iterables * Make using dim_kwargs for python 3.5 illegal -- a ValueError is thrown * dataset.expand_dims() method take dict like object where values represent length of dimensions or coordinates of dimesnsions * dataarray.expand_dims() method take dict like object where values represent length of dimensions or coordinates of dimesnsions * Add alternative option to passing a dict to the dim argument, which is now an optional kwarg, passing in each new dimension as its own kwarg * Add expand_dims enhancement from issue 2710 to whats-new.rst * Fix test_dataarray.TestDataArray.test_expand_dims_with_greater_dim_size tests to pass in python 3.5 using ordered dicts instead of regular dicts. This was needed because python 3.5 and earlier did not maintain insertion order for dicts * Restrict core logic to use 'dim' as a dict--it will be converted into a dict on entry if it is a str or a sequence of str * Don't cast dim values (coords) as a list since IndexVariable/Variable will internally convert it into a numpy.ndarray. So just use IndexVariable((k,), v) * TypeErrors should be raised for invalid input types, rather than ValueErrors. * Force 'dim' to be OrderedDict for python 3.5 * Allow expand_dims() method to support inserting/broadcasting dimensions with size>1 (#2757) * Move enhancement description up to 0.12.1 * use .size attribute to determine the size of a dimension, rather than converting to a list, which can be slow for large iterables * Make using dim_kwargs for python 3.5 illegal -- a ValueError is thrown * dataset.expand_dims() method take dict like object where values represent length of dimensions or coordinates of dimesnsions * dataarray.expand_dims() method take dict like object where values represent length of dimensions or coordinates of dimesnsions * Add alternative option to passing a dict to the dim argument, which is now an optional kwarg, passing in each new dimension as its own kwarg * Add expand_dims enhancement from issue 2710 to whats-new.rst * Fix test_dataarray.TestDataArray.test_expand_dims_with_greater_dim_size tests to pass in python 3.5 using ordered dicts instead of regular dicts. This was needed because python 3.5 and earlier did not maintain insertion order for dicts * Restrict core logic to use 'dim' as a dict--it will be converted into a dict on entry if it is a str or a sequence of str * Don't cast dim values (coords) as a list since IndexVariable/Variable will internally convert it into a numpy.ndarray. So just use IndexVariable((k,), v) * TypeErrors should be raised for invalid input types, rather than ValueErrors. * Force 'dim' to be OrderedDict for python 3.5
1 parent 89dddc1 commit 16a2c03

File tree

5 files changed

+218
-19
lines changed

5 files changed

+218
-19
lines changed

doc/whats-new.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ v0.12.1 (unreleased)
2121
Enhancements
2222
~~~~~~~~~~~~
2323

24+
- Allow ``expand_dims`` method to support inserting/broadcasting dimensions
25+
with size > 1. (:issue:`2710`)
26+
By `Martin Pletcher <https://github.com/pletchm>`_.
27+
2428

2529
Bug fixes
2630
~~~~~~~~~

xarray/core/dataarray.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import functools
2+
import sys
23
import warnings
34
from collections import OrderedDict
45

@@ -1138,7 +1139,7 @@ def swap_dims(self, dims_dict):
11381139
ds = self._to_temp_dataset().swap_dims(dims_dict)
11391140
return self._from_temp_dataset(ds)
11401141

1141-
def expand_dims(self, dim, axis=None):
1142+
def expand_dims(self, dim=None, axis=None, **dim_kwargs):
11421143
"""Return a new object with an additional axis (or axes) inserted at
11431144
the corresponding position in the array shape.
11441145
@@ -1147,21 +1148,53 @@ def expand_dims(self, dim, axis=None):
11471148
11481149
Parameters
11491150
----------
1150-
dim : str or sequence of str.
1151+
dim : str, sequence of str, dict, or None
11511152
Dimensions to include on the new variable.
1152-
dimensions are inserted with length 1.
1153+
If provided as str or sequence of str, then dimensions are inserted
1154+
with length 1. If provided as a dict, then the keys are the new
1155+
dimensions and the values are either integers (giving the length of
1156+
the new dimensions) or sequence/ndarray (giving the coordinates of
1157+
the new dimensions). **WARNING** for python 3.5, if ``dim`` is
1158+
dict-like, then it must be an ``OrderedDict``. This is to ensure
1159+
that the order in which the dims are given is maintained.
11531160
axis : integer, list (or tuple) of integers, or None
11541161
Axis position(s) where new axis is to be inserted (position(s) on
11551162
the result array). If a list (or tuple) of integers is passed,
11561163
multiple axes are inserted. In this case, dim arguments should be
11571164
same length list. If axis=None is passed, all the axes will be
11581165
inserted to the start of the result array.
1166+
**dim_kwargs : int or sequence/ndarray
1167+
The keywords are arbitrary dimensions being inserted and the values
1168+
are either the lengths of the new dims (if int is given), or their
1169+
coordinates. Note, this is an alternative to passing a dict to the
1170+
dim kwarg and will only be used if dim is None. **WARNING** for
1171+
python 3.5 ``dim_kwargs`` is not available.
11591172
11601173
Returns
11611174
-------
11621175
expanded : same type as caller
11631176
This object, but with an additional dimension(s).
11641177
"""
1178+
if isinstance(dim, int):
1179+
raise TypeError('dim should be str or sequence of strs or dict')
1180+
elif isinstance(dim, str):
1181+
dim = OrderedDict(((dim, 1),))
1182+
elif isinstance(dim, (list, tuple)):
1183+
if len(dim) != len(set(dim)):
1184+
raise ValueError('dims should not contain duplicate values.')
1185+
dim = OrderedDict(((d, 1) for d in dim))
1186+
1187+
# TODO: get rid of the below code block when python 3.5 is no longer
1188+
# supported.
1189+
python36_plus = sys.version_info[0] == 3 and sys.version_info[1] > 5
1190+
not_ordereddict = dim is not None and not isinstance(dim, OrderedDict)
1191+
if not python36_plus and not_ordereddict:
1192+
raise TypeError("dim must be an OrderedDict for python <3.6")
1193+
elif not python36_plus and dim_kwargs:
1194+
raise ValueError("dim_kwargs isn't available for python <3.6")
1195+
dim_kwargs = OrderedDict(dim_kwargs)
1196+
1197+
dim = either_dict_or_kwargs(dim, dim_kwargs, 'expand_dims')
11651198
ds = self._to_temp_dataset().expand_dims(dim, axis)
11661199
return self._from_temp_dataset(ds)
11671200

xarray/core/dataset.py

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2324,7 +2324,7 @@ def swap_dims(self, dims_dict, inplace=None):
23242324
return self._replace_with_new_dims(variables, coord_names,
23252325
indexes=indexes, inplace=inplace)
23262326

2327-
def expand_dims(self, dim, axis=None):
2327+
def expand_dims(self, dim=None, axis=None, **dim_kwargs):
23282328
"""Return a new object with an additional axis (or axes) inserted at
23292329
the corresponding position in the array shape.
23302330
@@ -2333,26 +2333,53 @@ def expand_dims(self, dim, axis=None):
23332333
23342334
Parameters
23352335
----------
2336-
dim : str or sequence of str.
2336+
dim : str, sequence of str, dict, or None
23372337
Dimensions to include on the new variable.
2338-
dimensions are inserted with length 1.
2338+
If provided as str or sequence of str, then dimensions are inserted
2339+
with length 1. If provided as a dict, then the keys are the new
2340+
dimensions and the values are either integers (giving the length of
2341+
the new dimensions) or sequence/ndarray (giving the coordinates of
2342+
the new dimensions). **WARNING** for python 3.5, if ``dim`` is
2343+
dict-like, then it must be an ``OrderedDict``. This is to ensure
2344+
that the order in which the dims are given is maintained.
23392345
axis : integer, list (or tuple) of integers, or None
23402346
Axis position(s) where new axis is to be inserted (position(s) on
23412347
the result array). If a list (or tuple) of integers is passed,
23422348
multiple axes are inserted. In this case, dim arguments should be
2343-
the same length list. If axis=None is passed, all the axes will
2344-
be inserted to the start of the result array.
2349+
same length list. If axis=None is passed, all the axes will be
2350+
inserted to the start of the result array.
2351+
**dim_kwargs : int or sequence/ndarray
2352+
The keywords are arbitrary dimensions being inserted and the values
2353+
are either the lengths of the new dims (if int is given), or their
2354+
coordinates. Note, this is an alternative to passing a dict to the
2355+
dim kwarg and will only be used if dim is None. **WARNING** for
2356+
python 3.5 ``dim_kwargs`` is not available.
23452357
23462358
Returns
23472359
-------
23482360
expanded : same type as caller
23492361
This object, but with an additional dimension(s).
23502362
"""
23512363
if isinstance(dim, int):
2352-
raise ValueError('dim should be str or sequence of strs or dict')
2364+
raise TypeError('dim should be str or sequence of strs or dict')
2365+
elif isinstance(dim, str):
2366+
dim = OrderedDict(((dim, 1),))
2367+
elif isinstance(dim, (list, tuple)):
2368+
if len(dim) != len(set(dim)):
2369+
raise ValueError('dims should not contain duplicate values.')
2370+
dim = OrderedDict(((d, 1) for d in dim))
2371+
2372+
# TODO: get rid of the below code block when python 3.5 is no longer
2373+
# supported.
2374+
python36_plus = sys.version_info[0] == 3 and sys.version_info[1] > 5
2375+
not_ordereddict = dim is not None and not isinstance(dim, OrderedDict)
2376+
if not python36_plus and not_ordereddict:
2377+
raise TypeError("dim must be an OrderedDict for python <3.6")
2378+
elif not python36_plus and dim_kwargs:
2379+
raise ValueError("dim_kwargs isn't available for python <3.6")
2380+
2381+
dim = either_dict_or_kwargs(dim, dim_kwargs, 'expand_dims')
23532382

2354-
if isinstance(dim, str):
2355-
dim = [dim]
23562383
if axis is not None and not isinstance(axis, (list, tuple)):
23572384
axis = [axis]
23582385

@@ -2371,10 +2398,24 @@ def expand_dims(self, dim, axis=None):
23712398
'{dim} already exists as coordinate or'
23722399
' variable name.'.format(dim=d))
23732400

2374-
if len(dim) != len(set(dim)):
2375-
raise ValueError('dims should not contain duplicate values.')
2376-
23772401
variables = OrderedDict()
2402+
# If dim is a dict, then ensure that the values are either integers
2403+
# or iterables.
2404+
for k, v in dim.items():
2405+
if hasattr(v, "__iter__"):
2406+
# If the value for the new dimension is an iterable, then
2407+
# save the coordinates to the variables dict, and set the
2408+
# value within the dim dict to the length of the iterable
2409+
# for later use.
2410+
variables[k] = xr.IndexVariable((k,), v)
2411+
self._coord_names.add(k)
2412+
dim[k] = variables[k].size
2413+
elif isinstance(v, int):
2414+
pass # Do nothing if the dimensions value is just an int
2415+
else:
2416+
raise TypeError('The value of new dimension {k} must be '
2417+
'an iterable or an int'.format(k=k))
2418+
23782419
for k, v in self._variables.items():
23792420
if k not in dim:
23802421
if k in self._coord_names: # Do not change coordinates
@@ -2395,11 +2436,13 @@ def expand_dims(self, dim, axis=None):
23952436
' values.')
23962437
# We need to sort them to make sure `axis` equals to the
23972438
# axis positions of the result array.
2398-
zip_axis_dim = sorted(zip(axis_pos, dim))
2439+
zip_axis_dim = sorted(zip(axis_pos, dim.items()))
2440+
2441+
all_dims = list(zip(v.dims, v.shape))
2442+
for d, c in zip_axis_dim:
2443+
all_dims.insert(d, c)
2444+
all_dims = OrderedDict(all_dims)
23992445

2400-
all_dims = list(v.dims)
2401-
for a, d in zip_axis_dim:
2402-
all_dims.insert(a, d)
24032446
variables[k] = v.set_dims(all_dims)
24042447
else:
24052448
# If dims includes a label of a non-dimension coordinate,

xarray/tests/test_dataarray.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from collections import OrderedDict
44
from copy import deepcopy
55
from textwrap import dedent
6+
import sys
67

78
import numpy as np
89
import pandas as pd
@@ -1303,7 +1304,7 @@ def test_expand_dims_error(self):
13031304
coords={'x': np.linspace(0.0, 1.0, 3)},
13041305
attrs={'key': 'entry'})
13051306

1306-
with raises_regex(ValueError, 'dim should be str or'):
1307+
with raises_regex(TypeError, 'dim should be str or'):
13071308
array.expand_dims(0)
13081309
with raises_regex(ValueError, 'lengths of dim and axis'):
13091310
# dims and axis argument should be the same length
@@ -1328,6 +1329,16 @@ def test_expand_dims_error(self):
13281329
array.expand_dims(dim=['y', 'z'], axis=[2, -4])
13291330
array.expand_dims(dim=['y', 'z'], axis=[2, 3])
13301331

1332+
array = DataArray(np.random.randn(3, 4), dims=['x', 'dim_0'],
1333+
coords={'x': np.linspace(0.0, 1.0, 3)},
1334+
attrs={'key': 'entry'})
1335+
with pytest.raises(TypeError):
1336+
array.expand_dims(OrderedDict((("new_dim", 3.2),)))
1337+
1338+
# Attempt to use both dim and kwargs
1339+
with pytest.raises(ValueError):
1340+
array.expand_dims(OrderedDict((("d", 4),)), e=4)
1341+
13311342
def test_expand_dims(self):
13321343
array = DataArray(np.random.randn(3, 4), dims=['x', 'dim_0'],
13331344
coords={'x': np.linspace(0.0, 1.0, 3)},
@@ -1392,6 +1403,46 @@ def test_expand_dims_with_scalar_coordinate(self):
13921403
roundtripped = actual.squeeze(['z'], drop=False)
13931404
assert_identical(array, roundtripped)
13941405

1406+
def test_expand_dims_with_greater_dim_size(self):
1407+
array = DataArray(np.random.randn(3, 4), dims=['x', 'dim_0'],
1408+
coords={'x': np.linspace(0.0, 1.0, 3), 'z': 1.0},
1409+
attrs={'key': 'entry'})
1410+
# For python 3.5 and earlier this has to be an ordered dict, to
1411+
# maintain insertion order.
1412+
actual = array.expand_dims(
1413+
OrderedDict((('y', 2), ('z', 1), ('dim_1', ['a', 'b', 'c']))))
1414+
1415+
expected_coords = OrderedDict((
1416+
('y', [0, 1]), ('z', [1.0]), ('dim_1', ['a', 'b', 'c']),
1417+
('x', np.linspace(0, 1, 3)), ('dim_0', range(4))))
1418+
expected = DataArray(array.values * np.ones([2, 1, 3, 3, 4]),
1419+
coords=expected_coords,
1420+
dims=list(expected_coords.keys()),
1421+
attrs={'key': 'entry'}
1422+
).drop(['y', 'dim_0'])
1423+
assert_identical(expected, actual)
1424+
1425+
# Test with kwargs instead of passing dict to dim arg.
1426+
1427+
# TODO: only the code under the if-statement is needed when python 3.5
1428+
# is no longer supported.
1429+
python36_plus = sys.version_info[0] == 3 and sys.version_info[1] > 5
1430+
if python36_plus:
1431+
other_way = array.expand_dims(dim_1=['a', 'b', 'c'])
1432+
1433+
other_way_expected = DataArray(
1434+
array.values * np.ones([3, 3, 4]),
1435+
coords={'dim_1': ['a', 'b', 'c'],
1436+
'x': np.linspace(0, 1, 3),
1437+
'dim_0': range(4), 'z': 1.0},
1438+
dims=['dim_1', 'x', 'dim_0'],
1439+
attrs={'key': 'entry'}).drop('dim_0')
1440+
assert_identical(other_way_expected, other_way)
1441+
else:
1442+
# In python 3.5, using dim_kwargs should raise a ValueError.
1443+
with raises_regex(ValueError, "dim_kwargs isn't"):
1444+
array.expand_dims(e=["l", "m", "n"])
1445+
13951446
def test_set_index(self):
13961447
indexes = [self.mindex.get_level_values(n) for n in self.mindex.names]
13971448
coords = {idx.name: ('x', idx) for idx in indexes}

xarray/tests/test_dataset.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,6 +2030,27 @@ def test_expand_dims_error(self):
20302030
with raises_regex(ValueError, 'already exists'):
20312031
original.expand_dims(dim=['z'])
20322032

2033+
original = Dataset({'x': ('a', np.random.randn(3)),
2034+
'y': (['b', 'a'], np.random.randn(4, 3)),
2035+
'z': ('a', np.random.randn(3))},
2036+
coords={'a': np.linspace(0, 1, 3),
2037+
'b': np.linspace(0, 1, 4),
2038+
'c': np.linspace(0, 1, 5)},
2039+
attrs={'key': 'entry'})
2040+
with raises_regex(TypeError, 'value of new dimension'):
2041+
original.expand_dims(OrderedDict((("d", 3.2),)))
2042+
2043+
# TODO: only the code under the if-statement is needed when python 3.5
2044+
# is no longer supported.
2045+
python36_plus = sys.version_info[0] == 3 and sys.version_info[1] > 5
2046+
if python36_plus:
2047+
with raises_regex(ValueError, 'both keyword and positional'):
2048+
original.expand_dims(OrderedDict((("d", 4),)), e=4)
2049+
else:
2050+
# In python 3.5, using dim_kwargs should raise a ValueError.
2051+
with raises_regex(ValueError, "dim_kwargs isn't"):
2052+
original.expand_dims(OrderedDict((("d", 4),)), e=4)
2053+
20332054
def test_expand_dims(self):
20342055
original = Dataset({'x': ('a', np.random.randn(3)),
20352056
'y': (['b', 'a'], np.random.randn(4, 3))},
@@ -2063,6 +2084,53 @@ def test_expand_dims(self):
20632084
roundtripped = actual.squeeze('z')
20642085
assert_identical(original, roundtripped)
20652086

2087+
# Test expanding one dimension to have size > 1 that doesn't have
2088+
# coordinates, and also expanding another dimension to have size > 1
2089+
# that DOES have coordinates.
2090+
actual = original.expand_dims(
2091+
OrderedDict((("d", 4), ("e", ["l", "m", "n"]))))
2092+
2093+
expected = Dataset(
2094+
{'x': xr.DataArray(original['x'].values * np.ones([4, 3, 3]),
2095+
coords=dict(d=range(4),
2096+
e=['l', 'm', 'n'],
2097+
a=np.linspace(0, 1, 3)),
2098+
dims=['d', 'e', 'a']).drop('d'),
2099+
'y': xr.DataArray(original['y'].values * np.ones([4, 3, 4, 3]),
2100+
coords=dict(d=range(4),
2101+
e=['l', 'm', 'n'],
2102+
b=np.linspace(0, 1, 4),
2103+
a=np.linspace(0, 1, 3)),
2104+
dims=['d', 'e', 'b', 'a']).drop('d')},
2105+
coords={'c': np.linspace(0, 1, 5)},
2106+
attrs={'key': 'entry'})
2107+
assert_identical(actual, expected)
2108+
2109+
# Test with kwargs instead of passing dict to dim arg.
2110+
2111+
# TODO: only the code under the if-statement is needed when python 3.5
2112+
# is no longer supported.
2113+
python36_plus = sys.version_info[0] == 3 and sys.version_info[1] > 5
2114+
if python36_plus:
2115+
other_way = original.expand_dims(e=["l", "m", "n"])
2116+
other_way_expected = Dataset(
2117+
{'x': xr.DataArray(original['x'].values * np.ones([3, 3]),
2118+
coords=dict(e=['l', 'm', 'n'],
2119+
a=np.linspace(0, 1, 3)),
2120+
dims=['e', 'a']),
2121+
'y': xr.DataArray(original['y'].values * np.ones([3, 4, 3]),
2122+
coords=dict(e=['l', 'm', 'n'],
2123+
b=np.linspace(0, 1, 4),
2124+
a=np.linspace(0, 1, 3)),
2125+
dims=['e', 'b', 'a'])},
2126+
coords={'c': np.linspace(0, 1, 5)},
2127+
attrs={'key': 'entry'})
2128+
assert_identical(other_way_expected, other_way)
2129+
else:
2130+
# In python 3.5, using dim_kwargs should raise a ValueError.
2131+
with raises_regex(ValueError, "dim_kwargs isn't"):
2132+
original.expand_dims(e=["l", "m", "n"])
2133+
20662134
def test_set_index(self):
20672135
expected = create_test_multiindex()
20682136
mindex = expected['x'].to_index()

0 commit comments

Comments
 (0)