From 2f8a835ef24eea621fc1f16486235b80b97feb84 Mon Sep 17 00:00:00 2001 From: Andrew Huang Date: Thu, 9 Aug 2018 22:12:00 -0700 Subject: [PATCH 1/9] Add option to not roll coords --- xarray/core/dataarray.py | 14 ++++++++++---- xarray/core/dataset.py | 25 +++++++++++++++++++------ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index f215bc47df8..b7a57f5581d 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -2015,14 +2015,20 @@ def shift(self, **shifts): variable = self.variable.shift(**shifts) return self._replace(variable) - def roll(self, **shifts): + def roll(self, coords, **shifts): """Roll this array by an offset along one or more dimensions. - Unlike shift, roll rotates all variables, including coordinates. The - direction of rotation is consistent with :py:func:`numpy.roll`. + Unlike shift, roll may rotate all variables, including coordinates + if specified. The direction of rotation is consistent with + :py:func:`numpy.roll`. Parameters ---------- + coords : bool + Indicates whether to roll the coordinates by the offset + The current default of coords (None, equivalent to True) is + deprecated and will change to False in a future version. + Explicitly pass coords to silence the warning and sort. **shifts : keyword arguments of the form {dim: offset} Integer offset to rotate each of the given dimensions. Positive offsets roll to the right; negative offsets roll to the left. @@ -2046,7 +2052,7 @@ def roll(self, **shifts): Coordinates: * x (x) int64 2 0 1 """ - ds = self._to_temp_dataset().roll(**shifts) + ds = self._to_temp_dataset().roll(coords=coords, **shifts) return self._from_temp_dataset(ds) @property diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 4b52178ad0e..7ebabca3f36 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -3355,14 +3355,20 @@ def shift(self, **shifts): return self._replace_vars_and_dims(variables) - def roll(self, **shifts): + def roll(self, coords=None, **shifts): """Roll this dataset by an offset along one or more dimensions. - Unlike shift, roll rotates all variables, including coordinates. The - direction of rotation is consistent with :py:func:`numpy.roll`. + Unlike shift, roll may rotate all variables, including coordinates + if specified. The direction of rotation is consistent with + :py:func:`numpy.roll`. Parameters ---------- + coords : bool + Indicates whether to roll the coordinates by the offset + The current default of coords (None, equivalent to True) is + deprecated and will change to False in a future version. + Explicitly pass coords to silence the warning and sort. **shifts : keyword arguments of the form {dim: offset} Integer offset to rotate each of the given dimensions. Positive offsets roll to the right; negative offsets roll to the left. @@ -3395,9 +3401,16 @@ def roll(self, **shifts): variables = OrderedDict() for name, var in iteritems(self.variables): - var_shifts = dict((k, v) for k, v in shifts.items() - if k in var.dims) - variables[name] = var.roll(**var_shifts) + if name in self.data_vars or coords: + if coords is None: + warnings.warn("Coords will be set to False in the future." + " Explicitly set coords to silence warning.", + DeprecationWarning, stacklevel=3) + var_shifts = dict((k, v) for k, v in shifts.items() + if k in var.dims) + variables[name] = var.roll(**var_shifts) + else: + variables[name] = var return self._replace_vars_and_dims(variables) From 2caa553b7e9c9e2862f2b52cb3a8aabfb592b900 Mon Sep 17 00:00:00 2001 From: Andrew Huang Date: Sat, 11 Aug 2018 21:14:13 -0700 Subject: [PATCH 2/9] Rename keyword arg and add tests --- xarray/core/dataarray.py | 10 +++++----- xarray/core/dataset.py | 16 ++++++++-------- xarray/tests/test_dataset.py | 18 +++++++++++++++--- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index b7a57f5581d..65d1c12a16e 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -2015,7 +2015,7 @@ def shift(self, **shifts): variable = self.variable.shift(**shifts) return self._replace(variable) - def roll(self, coords, **shifts): + def roll(self, roll_coords=None, **shifts): """Roll this array by an offset along one or more dimensions. Unlike shift, roll may rotate all variables, including coordinates @@ -2024,11 +2024,11 @@ def roll(self, coords, **shifts): Parameters ---------- - coords : bool + roll_coords : bool Indicates whether to roll the coordinates by the offset - The current default of coords (None, equivalent to True) is + The current default of roll_coords (None, equivalent to True) is deprecated and will change to False in a future version. - Explicitly pass coords to silence the warning and sort. + Explicitly pass roll_coords to silence the warning and sort. **shifts : keyword arguments of the form {dim: offset} Integer offset to rotate each of the given dimensions. Positive offsets roll to the right; negative offsets roll to the left. @@ -2052,7 +2052,7 @@ def roll(self, coords, **shifts): Coordinates: * x (x) int64 2 0 1 """ - ds = self._to_temp_dataset().roll(coords=coords, **shifts) + ds = self._to_temp_dataset().roll(roll_coords=roll_coords, **shifts) return self._from_temp_dataset(ds) @property diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 7ebabca3f36..539188a5a8d 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -3355,7 +3355,7 @@ def shift(self, **shifts): return self._replace_vars_and_dims(variables) - def roll(self, coords=None, **shifts): + def roll(self, roll_coords=None, **shifts): """Roll this dataset by an offset along one or more dimensions. Unlike shift, roll may rotate all variables, including coordinates @@ -3364,11 +3364,11 @@ def roll(self, coords=None, **shifts): Parameters ---------- - coords : bool + roll_coords : bool Indicates whether to roll the coordinates by the offset - The current default of coords (None, equivalent to True) is + The current default of roll_coords (None, equivalent to True) is deprecated and will change to False in a future version. - Explicitly pass coords to silence the warning and sort. + Explicitly pass roll_coords to silence the warning and sort. **shifts : keyword arguments of the form {dim: offset} Integer offset to rotate each of the given dimensions. Positive offsets roll to the right; negative offsets roll to the left. @@ -3401,10 +3401,10 @@ def roll(self, coords=None, **shifts): variables = OrderedDict() for name, var in iteritems(self.variables): - if name in self.data_vars or coords: - if coords is None: - warnings.warn("Coords will be set to False in the future." - " Explicitly set coords to silence warning.", + if name in self.data_vars or roll_coords: + if roll_coords is None: + warnings.warn("roll_coords will be set to False in the future." + " Explicitly set roll_coords to silence warning.", DeprecationWarning, stacklevel=3) var_shifts = dict((k, v) for k, v in shifts.items() if k in var.dims) diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index c0516ed7e56..9a65a2ba3bd 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -3837,18 +3837,30 @@ def test_shift(self): with raises_regex(ValueError, 'dimensions'): ds.shift(foo=123) - def test_roll(self): + def test_roll_coords(self): coords = {'bar': ('x', list('abc')), 'x': [-4, 3, 2]} attrs = {'meta': 'data'} ds = Dataset({'foo': ('x', [1, 2, 3])}, coords, attrs) - actual = ds.roll(x=1) + actual = ds.roll(x=1, roll_coords=True) ex_coords = {'bar': ('x', list('cab')), 'x': [2, -4, 3]} expected = Dataset({'foo': ('x', [3, 1, 2])}, ex_coords, attrs) assert_identical(expected, actual) with raises_regex(ValueError, 'dimensions'): - ds.roll(foo=123) + ds.roll(foo=123, roll_coords=True) + + def test_roll_no_coords(self): + coords = {'bar': ('x', list('abc')), 'x': [-4, 3, 2]} + attrs = {'meta': 'data'} + ds = Dataset({'foo': ('x', [1, 2, 3])}, coords, attrs) + actual = ds.roll(x=1, roll_coords=False) + + expected = Dataset({'foo': ('x', [3, 1, 2])}, coords, attrs) + assert_identical(expected, actual) + + with raises_regex(ValueError, 'dimensions'): + ds.roll(abc=321, roll_coords=False) def test_real_and_imag(self): attrs = {'foo': 'bar'} From a2737b8c8ae7d2564332412c3a93ea9bdb2c3652 Mon Sep 17 00:00:00 2001 From: Andrew Huang Date: Sat, 11 Aug 2018 21:24:04 -0700 Subject: [PATCH 3/9] Add what's new --- doc/whats-new.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 3641a072e2e..32ef10ddd45 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -52,6 +52,12 @@ Enhancements (:issue:`2331`) By `Maximilian Roos `_. +- You can now control whether or not to offset the coordinates when using + the ``roll`` method and the current behavior, coordinates rolled by default, + raises a deprecation warning unless explicitly setting the keyword argument. + (:issue:`1875`) + By `Andrew Huang `_. + Bug fixes ~~~~~~~~~ From 0b5e7fdf4553dfbd0ec2c69762207633a0ae0e9d Mon Sep 17 00:00:00 2001 From: Andrew Huang Date: Sat, 11 Aug 2018 22:16:40 -0700 Subject: [PATCH 4/9] Fix passing None and add more tests --- xarray/core/dataset.py | 2 +- xarray/tests/test_dataarray.py | 16 ++++++++++++++-- xarray/tests/test_dataset.py | 10 ++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 539188a5a8d..847da1f1f94 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -3401,7 +3401,7 @@ def roll(self, roll_coords=None, **shifts): variables = OrderedDict() for name, var in iteritems(self.variables): - if name in self.data_vars or roll_coords: + if name in self.data_vars or roll_coords or roll_coords is None: if roll_coords is None: warnings.warn("roll_coords will be set to False in the future." " Explicitly set roll_coords to silence warning.", diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index fdca3fd8d13..8da43d1e69b 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -3096,9 +3096,21 @@ def test_shift(self): actual = arr.shift(x=offset) assert_identical(expected, actual) - def test_roll(self): + def test_roll_coords(self): arr = DataArray([1, 2, 3], coords={'x': range(3)}, dims='x') - actual = arr.roll(x=1) + actual = arr.roll(x=1, roll_coords=True) + expected = DataArray([3, 1, 2], coords=[('x', [2, 0, 1])]) + assert_identical(expected, actual) + + def test_roll_no_coords(self): + arr = DataArray([1, 2, 3], coords={'x': range(3)}, dims='x') + actual = arr.roll(x=1, roll_coords=False) + expected = DataArray([3, 1, 2], coords=[('x', [0, 1, 2])]) + assert_identical(expected, actual) + + def test_roll_coords_none(self): + arr = DataArray([1, 2, 3], coords={'x': range(3)}, dims='x') + actual = arr.roll(x=1, roll_coords=None) expected = DataArray([3, 1, 2], coords=[('x', [2, 0, 1])]) assert_identical(expected, actual) diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index 9a65a2ba3bd..cca5b9387e1 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -3862,6 +3862,16 @@ def test_roll_no_coords(self): with raises_regex(ValueError, 'dimensions'): ds.roll(abc=321, roll_coords=False) + def test_roll_coords_none(self): + coords = {'bar': ('x', list('abc')), 'x': [-4, 3, 2]} + attrs = {'meta': 'data'} + ds = Dataset({'foo': ('x', [1, 2, 3])}, coords, attrs) + actual = ds.roll(x=1, roll_coords=None) + + ex_coords = {'bar': ('x', list('cab')), 'x': [2, -4, 3]} + expected = Dataset({'foo': ('x', [3, 1, 2])}, ex_coords, attrs) + assert_identical(expected, actual) + def test_real_and_imag(self): attrs = {'foo': 'bar'} ds = Dataset({'x': ((), 1 + 2j, attrs)}, attrs=attrs) From a4da1ca12967ce86b16151f573dae8997aaecc98 Mon Sep 17 00:00:00 2001 From: Andrew Huang Date: Sat, 11 Aug 2018 22:27:00 -0700 Subject: [PATCH 5/9] Revise from comments --- xarray/core/dataset.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 847da1f1f94..f1af21a2f81 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -3400,12 +3400,20 @@ def roll(self, roll_coords=None, **shifts): raise ValueError("dimensions %r do not exist" % invalid) variables = OrderedDict() + coord_names = set(k for k in self.coords if k in self.variables) for name, var in iteritems(self.variables): - if name in self.data_vars or roll_coords or roll_coords is None: - if roll_coords is None: - warnings.warn("roll_coords will be set to False in the future." - " Explicitly set roll_coords to silence warning.", - DeprecationWarning, stacklevel=3) + if name in self.data_vars: + var_shifts = dict((k, v) for k, v in shifts.items() + if k in var.dims) + variables[name] = var.roll(**var_shifts) + elif name in coord_names and roll_coords: + var_shifts = dict((k, v) for k, v in shifts.items() + if k in var.dims) + variables[name] = var.roll(**var_shifts) + elif name in coord_names and roll_coords is None: + warnings.warn("roll_coords will be set to False in the future." + " Explicitly set roll_coords to silence warning.", + DeprecationWarning, stacklevel=3) var_shifts = dict((k, v) for k, v in shifts.items() if k in var.dims) variables[name] = var.roll(**var_shifts) From 896b18a0f50eee83338f3794934ddb1f7b6b44e5 Mon Sep 17 00:00:00 2001 From: Andrew Huang Date: Sat, 11 Aug 2018 22:46:40 -0700 Subject: [PATCH 6/9] Revise with cleaner version --- xarray/core/dataset.py | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index f1af21a2f81..e0d1ddc0c02 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -3399,26 +3399,20 @@ def roll(self, roll_coords=None, **shifts): if invalid: raise ValueError("dimensions %r do not exist" % invalid) + if roll_coords is None: + warnings.warn("roll_coords will be set to False in the future." + " Explicitly set roll_coords to silence warning.", + DeprecationWarning, stacklevel=3) + roll_coords = True + + unrolled_vars = () if roll_coords else self.coords + variables = OrderedDict() - coord_names = set(k for k in self.coords if k in self.variables) - for name, var in iteritems(self.variables): - if name in self.data_vars: - var_shifts = dict((k, v) for k, v in shifts.items() - if k in var.dims) - variables[name] = var.roll(**var_shifts) - elif name in coord_names and roll_coords: - var_shifts = dict((k, v) for k, v in shifts.items() - if k in var.dims) - variables[name] = var.roll(**var_shifts) - elif name in coord_names and roll_coords is None: - warnings.warn("roll_coords will be set to False in the future." - " Explicitly set roll_coords to silence warning.", - DeprecationWarning, stacklevel=3) - var_shifts = dict((k, v) for k, v in shifts.items() - if k in var.dims) - variables[name] = var.roll(**var_shifts) + for k, v in iteritems(self.variables): + if k not in unrolled_vars: + variables[k] = v.roll(**shifts) else: - variables[name] = var + variables[k] = v return self._replace_vars_and_dims(variables) From c64f726a63587a5988c02301af1370179a6d0b97 Mon Sep 17 00:00:00 2001 From: Andrew Huang Date: Sun, 12 Aug 2018 22:27:01 -0700 Subject: [PATCH 7/9] Revisions based on comments --- xarray/core/dataarray.py | 2 +- xarray/core/dataset.py | 7 +++++-- xarray/tests/test_dataarray.py | 5 ++++- xarray/tests/test_dataset.py | 4 +++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index 65d1c12a16e..e975d93504a 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -2028,7 +2028,7 @@ def roll(self, roll_coords=None, **shifts): Indicates whether to roll the coordinates by the offset The current default of roll_coords (None, equivalent to True) is deprecated and will change to False in a future version. - Explicitly pass roll_coords to silence the warning and sort. + Explicitly pass roll_coords to silence the warning. **shifts : keyword arguments of the form {dim: offset} Integer offset to rotate each of the given dimensions. Positive offsets roll to the right; negative offsets roll to the left. diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index e0d1ddc0c02..58ea37a8762 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -3368,7 +3368,7 @@ def roll(self, roll_coords=None, **shifts): Indicates whether to roll the coordinates by the offset The current default of roll_coords (None, equivalent to True) is deprecated and will change to False in a future version. - Explicitly pass roll_coords to silence the warning and sort. + Explicitly pass roll_coords to silence the warning. **shifts : keyword arguments of the form {dim: offset} Integer offset to rotate each of the given dimensions. Positive offsets roll to the right; negative offsets roll to the left. @@ -3395,6 +3395,9 @@ def roll(self, roll_coords=None, **shifts): Data variables: foo (x) object 'd' 'e' 'a' 'b' 'c' """ + shifts = either_dict_or_kwargs(None, + shifts, + 'roll') invalid = [k for k in shifts if k not in self.dims] if invalid: raise ValueError("dimensions %r do not exist" % invalid) @@ -3402,7 +3405,7 @@ def roll(self, roll_coords=None, **shifts): if roll_coords is None: warnings.warn("roll_coords will be set to False in the future." " Explicitly set roll_coords to silence warning.", - DeprecationWarning, stacklevel=3) + FutureWarning, stacklevel=2) roll_coords = True unrolled_vars = () if roll_coords else self.coords diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index 8da43d1e69b..8bad63a3dc4 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -3110,7 +3110,10 @@ def test_roll_no_coords(self): def test_roll_coords_none(self): arr = DataArray([1, 2, 3], coords={'x': range(3)}, dims='x') - actual = arr.roll(x=1, roll_coords=None) + + with pytest.warns(FutureWarning): + actual = arr.roll(x=1, roll_coords=None) + expected = DataArray([3, 1, 2], coords=[('x', [2, 0, 1])]) assert_identical(expected, actual) diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index cca5b9387e1..d6d504df4e9 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -3866,7 +3866,9 @@ def test_roll_coords_none(self): coords = {'bar': ('x', list('abc')), 'x': [-4, 3, 2]} attrs = {'meta': 'data'} ds = Dataset({'foo': ('x', [1, 2, 3])}, coords, attrs) - actual = ds.roll(x=1, roll_coords=None) + + with pytest.warns(FutureWarning): + actual = ds.roll(x=1, roll_coords=None) ex_coords = {'bar': ('x', list('cab')), 'x': [2, -4, 3]} expected = Dataset({'foo': ('x', [3, 1, 2])}, ex_coords, attrs) From 57255787da3603fbe65427bdfe1a00dab2926ba2 Mon Sep 17 00:00:00 2001 From: Andrew Huang Date: Sun, 12 Aug 2018 22:40:08 -0700 Subject: [PATCH 8/9] Fix either_dict_or_kwargs --- xarray/core/dataarray.py | 5 ++++- xarray/core/dataset.py | 18 +++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index e975d93504a..ac055f17131 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -2015,7 +2015,7 @@ def shift(self, **shifts): variable = self.variable.shift(**shifts) return self._replace(variable) - def roll(self, roll_coords=None, **shifts): + def roll(self, shifts=None, roll_coords=None, **shifts_kwargs): """Roll this array by an offset along one or more dimensions. Unlike shift, roll may rotate all variables, including coordinates @@ -2052,6 +2052,9 @@ def roll(self, roll_coords=None, **shifts): Coordinates: * x (x) int64 2 0 1 """ + shifts = either_dict_or_kwargs(shifts, + shifts_kwargs, + 'roll') ds = self._to_temp_dataset().roll(roll_coords=roll_coords, **shifts) return self._from_temp_dataset(ds) diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 58ea37a8762..dd5b9557760 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -3355,7 +3355,7 @@ def shift(self, **shifts): return self._replace_vars_and_dims(variables) - def roll(self, roll_coords=None, **shifts): + def roll(self, shifts=None, roll_coords=None, **shifts_kwargs): """Roll this dataset by an offset along one or more dimensions. Unlike shift, roll may rotate all variables, including coordinates @@ -3364,15 +3364,19 @@ def roll(self, roll_coords=None, **shifts): Parameters ---------- + + shifts : dict, optional + A dict with keys matching dimensions and values given + by integers to rotate each of the given dimensions. Positive + offsets roll to the right; negative offsets roll to the left. roll_coords : bool Indicates whether to roll the coordinates by the offset The current default of roll_coords (None, equivalent to True) is deprecated and will change to False in a future version. Explicitly pass roll_coords to silence the warning. - **shifts : keyword arguments of the form {dim: offset} - Integer offset to rotate each of the given dimensions. Positive - offsets roll to the right; negative offsets roll to the left. - + **shifts_kwargs : {dim: offset, ...}, optional + The keyword arguments form of ``shifts``. + One of shifts or shifts_kwargs must be provided. Returns ------- rolled : Dataset @@ -3395,8 +3399,8 @@ def roll(self, roll_coords=None, **shifts): Data variables: foo (x) object 'd' 'e' 'a' 'b' 'c' """ - shifts = either_dict_or_kwargs(None, - shifts, + shifts = either_dict_or_kwargs(shifts, + shifts_kwargs, 'roll') invalid = [k for k in shifts if k not in self.dims] if invalid: From 3f9dc4af91c84a8e3bfa38d498675c2196f08704 Mon Sep 17 00:00:00 2001 From: Andrew Huang Date: Tue, 14 Aug 2018 18:00:06 -0700 Subject: [PATCH 9/9] Revisions from comments --- xarray/core/dataarray.py | 6 ++---- xarray/core/dataset.py | 8 +++----- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index ac055f17131..b1be994416e 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -2052,10 +2052,8 @@ def roll(self, shifts=None, roll_coords=None, **shifts_kwargs): Coordinates: * x (x) int64 2 0 1 """ - shifts = either_dict_or_kwargs(shifts, - shifts_kwargs, - 'roll') - ds = self._to_temp_dataset().roll(roll_coords=roll_coords, **shifts) + ds = self._to_temp_dataset().roll( + shifts=shifts, roll_coords=roll_coords, **shifts_kwargs) return self._from_temp_dataset(ds) @property diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index e2ffc14d760..37544aca372 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -2324,13 +2324,13 @@ def unstack(self, dim): 'a MultiIndex') full_idx = pd.MultiIndex.from_product(index.levels, names=index.names) - + # take a shortcut in case the MultiIndex was not modified. if index.equals(full_idx): obj = self else: obj = self.reindex(copy=False, **{dim: full_idx}) - + new_dim_names = index.names new_dim_sizes = [lev.size for lev in index.levels] @@ -3404,9 +3404,7 @@ def roll(self, shifts=None, roll_coords=None, **shifts_kwargs): Data variables: foo (x) object 'd' 'e' 'a' 'b' 'c' """ - shifts = either_dict_or_kwargs(shifts, - shifts_kwargs, - 'roll') + shifts = either_dict_or_kwargs(shifts, shifts_kwargs, 'roll') invalid = [k for k in shifts if k not in self.dims] if invalid: raise ValueError("dimensions %r do not exist" % invalid)