Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ Enhancements
Bug fixes
~~~~~~~~~

- ``xarray.DataArray.roll`` correctly handles multidimensional arrays.
(:issue:`2445`)
By `Keisuke Fujii <https://github.com/fujiisoup>`_.

- ``xarray.DataArray.std()`` now correctly accepts ``ddof`` keyword argument.
(:issue:`2240`)
By `Keisuke Fujii <https://github.com/fujiisoup>`_.
Expand Down
3 changes: 2 additions & 1 deletion xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3595,7 +3595,8 @@ def roll(self, shifts=None, roll_coords=None, **shifts_kwargs):
variables = OrderedDict()
for k, v in iteritems(self.variables):
if k not in unrolled_vars:
variables[k] = v.roll(**shifts)
variables[k] = v.roll(**{k: s for k, s in shifts.items()
if k in v.dims})
else:
variables[k] = v

Expand Down
10 changes: 10 additions & 0 deletions xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3945,6 +3945,16 @@ def test_roll_coords_none(self):
expected = Dataset({'foo': ('x', [3, 1, 2])}, ex_coords, attrs)
assert_identical(expected, actual)

def test_roll_multidim(self):
# regression test for 2445
arr = xr.DataArray(
[[1, 2, 3],[4, 5, 6]], coords={'x': range(3), 'y': range(2)},
dims=('y','x'))
actual = arr.roll(x=1, roll_coords=True)
expected = xr.DataArray([[3, 1, 2],[6, 4, 5]],
coords=[('y', [0, 1]), ('x', [2, 0, 1])])
assert_identical(expected, actual)

def test_real_and_imag(self):
attrs = {'foo': 'bar'}
ds = Dataset({'x': ((), 1 + 2j, attrs)}, attrs=attrs)
Expand Down