Skip to content

fix:2445 #2446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 28, 2018
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