From f531ea01de463ef831347bd7f0df302e73199627 Mon Sep 17 00:00:00 2001 From: jmunsch Date: Sun, 8 Jan 2017 00:35:40 -0800 Subject: [PATCH 1/4] BUG: Unclear ValueError in _GroupBy closes GH15082 --- pandas/core/groupby.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/groupby.py b/pandas/core/groupby.py index 7eba32b4932d0..322fa70c4acb0 100644 --- a/pandas/core/groupby.py +++ b/pandas/core/groupby.py @@ -588,8 +588,8 @@ def curried(x): try: return self._aggregate_item_by_item(name, *args, **kwargs) - except (AttributeError): - raise ValueError + except (AttributeError) as e: + raise ValueError(e) return wrapper From eb32b7efdffec5fcca6e9e2541985c144f862f9a Mon Sep 17 00:00:00 2001 From: jmunsch Date: Sun, 8 Jan 2017 00:36:59 -0800 Subject: [PATCH 2/4] TST: add test for unclear ValueError in _GroupBy closes GH15082 --- pandas/tests/groupby/test_groupby.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index e87b5d04271e8..a2b2550221c38 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -772,6 +772,29 @@ def max_value(group): 'int64': 1}).sort_values() assert_series_equal(result, expected) + def test_groupby_aggregate_item_by_item(self): + def test_df(): + s = pd.DataFrame(np.array([[13, 14, 15, 16]]), + index=[0], + columns=['b', 'c', 'd', 'e']) + num = np.array([[s, s, s, datetime.strptime('2016-12-28', "%Y-%m-%d"), 'asdf', 24], + [s, s, s, datetime.strptime('2016-12-28', "%Y-%m-%d"), 'asdf', 6]]) + columns = ['a', 'b', 'c', 'd', 'e', 'f'] + idx = [x for x in xrange(0, len(num))] + return pd.DataFrame(num, index=idx, columns=columns) + c = [test_df().sort_values(['d', 'e', 'f']), + test_df().sort_values(['d', 'e', 'f'])] + df = pd.concat(c) + df = df[["e", "a"]].copy().reset_index(drop=True) + df["e_idx"] = df["e"] + what = [0, 0.5, 0.5, 1] + + def x(): + df.groupby(["e_idx", "e"])["a"].quantile(what) + self.assertRaisesRegexp(ValueError, + "'SeriesGroupBy' object has no attribute '_aggregate_item_by_item'", + x) + def test_groupby_return_type(self): # GH2893, return a reduced type From 3b6706a50213e27944b62cfabdcbea1908963799 Mon Sep 17 00:00:00 2001 From: jmunsch Date: Sun, 8 Jan 2017 00:44:40 -0800 Subject: [PATCH 3/4] TST: formatting for new test closes GH15082 --- pandas/tests/groupby/test_groupby.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index a2b2550221c38..d147993fe2f54 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -777,9 +777,10 @@ def test_df(): s = pd.DataFrame(np.array([[13, 14, 15, 16]]), index=[0], columns=['b', 'c', 'd', 'e']) - num = np.array([[s, s, s, datetime.strptime('2016-12-28', "%Y-%m-%d"), 'asdf', 24], - [s, s, s, datetime.strptime('2016-12-28', "%Y-%m-%d"), 'asdf', 6]]) - columns = ['a', 'b', 'c', 'd', 'e', 'f'] + a1 = [s, s, datetime.strptime('2016-12-28', "%Y-%m-%d"), 'asdf', 2] + a2 = [s, s, datetime.strptime('2016-12-28', "%Y-%m-%d"), 'asdf', 6] + num = np.array([a1, a2]) + columns = ['b', 'c', 'd', 'e', 'f'] idx = [x for x in xrange(0, len(num))] return pd.DataFrame(num, index=idx, columns=columns) c = [test_df().sort_values(['d', 'e', 'f']), @@ -792,7 +793,8 @@ def test_df(): def x(): df.groupby(["e_idx", "e"])["a"].quantile(what) self.assertRaisesRegexp(ValueError, - "'SeriesGroupBy' object has no attribute '_aggregate_item_by_item'", + "'SeriesGroupBy' object " + "has no attribute '_aggregate_item_by_item'", x) def test_groupby_return_type(self): From 785f1a0815358ef5f173885548f83445055fdd8a Mon Sep 17 00:00:00 2001 From: jmunsch Date: Sun, 8 Jan 2017 00:48:12 -0800 Subject: [PATCH 4/4] DOC: add whatsnew description GH15082 --- doc/source/whatsnew/v0.20.0.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.20.0.txt b/doc/source/whatsnew/v0.20.0.txt index 0148a47068beb..fd522f2bcf91e 100644 --- a/doc/source/whatsnew/v0.20.0.txt +++ b/doc/source/whatsnew/v0.20.0.txt @@ -318,7 +318,7 @@ Bug Fixes - Bug in ``Series.unique()`` in which unsigned 64-bit integers were causing overflow (:issue:`14721`) - Bug in ``pd.unique()`` in which unsigned 64-bit integers were causing overflow (:issue:`14915`) - +- Bug in ``_GroupBy`` where a ``ValueError`` is raised without a message. (:issue:`15082`) - Bug in ``Series.iloc`` where a ``Categorical`` object for list-like indexes input was returned, where a ``Series`` was expected. (:issue:`14580`)