Skip to content
forked from pydata/xarray

Commit

Permalink
fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Oct 8, 2019
1 parent 5269e81 commit bd5b5fd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion xarray/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def __init__(
# cached attributes
self._groups = None

if not group_indices:
if len(group_indices) == 0:
if bins is not None:
raise ValueError(
"None of the data falls within bins with edges %r" % bins
Expand Down
15 changes: 10 additions & 5 deletions xarray/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,24 +234,29 @@ def test_groupby_repr(obj, dim):
expected = "%sGroupBy" % obj.__class__.__name__
expected += ", grouped over %r " % dim
expected += "\n%r groups with labels " % (len(np.unique(obj[dim])))
dims = list(obj.dims)
if dim == "x":
expected += "1, 2, 3, 4, 5"
expected += "1, 2, 3, 4, 5. "
elif dim == "y":
expected += "0, 1, 2, 3, 4, 5, ..., 15, 16, 17, 18, 19"
expected += "0, 1, 2, 3, 4, 5, ..., 15, 16, 17, 18, 19. "
dims = list(obj.isel(y=1).dims)
elif dim == "z":
expected += "'a', 'b', 'c'"
expected += "'a', 'b', 'c'. "
elif dim == "month":
expected += "1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12"
expected += "1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12. "
expected += "\nEach group has dimensions: %r" % dims
assert actual == expected


@pytest.mark.parametrize("obj", [repr_da, repr_da.to_dataset(name="a")])
def test_groupby_repr_datetime(obj):
dims = list(obj.dims)
actual = repr(obj.groupby("t.month"))
expected = "%sGroupBy" % obj.__class__.__name__
expected += ", grouped over 'month' "
expected += "\n%r groups with labels " % (len(np.unique(obj.t.dt.month)))
expected += "1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12"
expected += "1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12. "
expected += "\nEach group has dimensions: %r" % dims
assert actual == expected


Expand Down

0 comments on commit bd5b5fd

Please sign in to comment.