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`) 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 diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index e87b5d04271e8..d147993fe2f54 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -772,6 +772,31 @@ 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']) + 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']), + 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