-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue with expand_dims on 0d arrays of tuples (#867)
* Fix issue with expand_dims on 0d arrays of tuples This was originally reported on the mailing list: https://groups.google.com/forum/#!topic/xarray/fz7HHgpgwk0 Unfortunately, the fix requires a backwards compatibility break, because it changes how 0d object arrays are handled: In [4]: xr.Variable([], object()).values Out[4]: array(<object object at 0x10072e2e0>, dtype=object) Previously, we just returned the original object. * Add another test * Fix issue with squeeze() on object arrays of lists * another test * another test
- Loading branch information
Showing
6 changed files
with
137 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,46 @@ | ||
import numpy as np | ||
import xarray as xr | ||
from xarray.core.groupby import _consolidate_slices | ||
|
||
import pytest | ||
|
||
|
||
def test_consolidate_slices(): | ||
|
||
assert _consolidate_slices([slice(3), slice(3, 5)]) == [slice(5)] | ||
assert _consolidate_slices([slice(2, 3), slice(3, 6)]) == [slice(2, 6)] | ||
assert (_consolidate_slices([slice(2, 3, 1), slice(3, 6, 1)]) | ||
assert _consolidate_slices([slice(3), slice(3, 5)]) == [slice(5)] | ||
assert _consolidate_slices([slice(2, 3), slice(3, 6)]) == [slice(2, 6)] | ||
assert (_consolidate_slices([slice(2, 3, 1), slice(3, 6, 1)]) | ||
== [slice(2, 6, 1)]) | ||
|
||
slices = [slice(2, 3), slice(5, 6)] | ||
assert _consolidate_slices(slices) == slices | ||
|
||
with pytest.raises(ValueError): | ||
_consolidate_slices([slice(3), 4]) | ||
slices = [slice(2, 3), slice(5, 6)] | ||
assert _consolidate_slices(slices) == slices | ||
|
||
with pytest.raises(ValueError): | ||
_consolidate_slices([slice(3), 4]) | ||
|
||
|
||
def test_multi_index_groupby_apply(): | ||
# regression test for GH873 | ||
ds = xr.Dataset({'foo': (('x', 'y'), np.random.randn(3, 4))}, | ||
{'x': ['a', 'b', 'c'], 'y': [1, 2, 3, 4]}) | ||
doubled = 2 * ds | ||
group_doubled = (ds.stack(space=['x', 'y']) | ||
.groupby('space') | ||
.apply(lambda x: 2 * x) | ||
.unstack('space')) | ||
assert doubled.equals(group_doubled) | ||
|
||
|
||
def test_multi_index_groupby_sum(): | ||
# regression test for GH873 | ||
ds = xr.Dataset({'foo': (('x', 'y', 'z'), np.ones((3, 4, 2)))}, | ||
{'x': ['a', 'b', 'c'], 'y': [1, 2, 3, 4]}) | ||
expected = ds.sum('z') | ||
actual = (ds.stack(space=['x', 'y']) | ||
.groupby('space') | ||
.sum('z') | ||
.unstack('space')) | ||
assert expected.equals(actual) | ||
|
||
|
||
# TODO: move other groupby tests from test_dataset and test_dataarray over here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters