From bd5b5fd1c6463c454418ecab36d2357e769163e3 Mon Sep 17 00:00:00 2001 From: dcherian Date: Tue, 8 Oct 2019 10:46:44 -0600 Subject: [PATCH] fix tests. --- xarray/core/groupby.py | 2 +- xarray/tests/test_groupby.py | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/xarray/core/groupby.py b/xarray/core/groupby.py index 43b58fb085b..519b91538bd 100644 --- a/xarray/core/groupby.py +++ b/xarray/core/groupby.py @@ -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 diff --git a/xarray/tests/test_groupby.py b/xarray/tests/test_groupby.py index 07bf9c91469..8a30dc6025c 100644 --- a/xarray/tests/test_groupby.py +++ b/xarray/tests/test_groupby.py @@ -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