diff --git a/doc/source/v0.15.0.txt b/doc/source/v0.15.0.txt index 22860a143476e..92fd228ccd10e 100644 --- a/doc/source/v0.15.0.txt +++ b/doc/source/v0.15.0.txt @@ -880,7 +880,7 @@ Bug Fixes when matching block and manager items, when there's only one block there's no ambiguity (:issue:`7794`) - Bug in putting a ``PeriodIndex`` into a ``Series`` would convert to ``int64`` dtype, rather than ``object`` of ``Periods`` (:issue:`7932`) - Bug in HDFStore iteration when passing a where (:issue:`8014`) -- Bug in DataFrameGroupby.transform when transforming with a passed non-sorted key (:issue:`8046`) +- Bug in DataFrameGroupby.transform when transforming with a passed non-sorted key (:issue:`8046`, :issue:`8430`) - Bug in repeated timeseries line and area plot may result in ``ValueError`` or incorrect kind (:issue:`7733`) - Bug in inference in a MultiIndex with ``datetime.date`` inputs (:issue:`7888`) - Bug in ``get`` where an ``IndexError`` would not cause the default value to be returned (:issue:`7725`) diff --git a/pandas/core/groupby.py b/pandas/core/groupby.py index 9698d91b3ed8a..2e107e0b0e935 100644 --- a/pandas/core/groupby.py +++ b/pandas/core/groupby.py @@ -484,8 +484,7 @@ def _set_result_index_ordered(self, result): indices = self.indices # shortcut of we have an already ordered grouper - - if not Index(self.grouper.group_info[0]).is_monotonic: + if not self.grouper.is_monotonic: index = Index(np.concatenate([ indices[v] for v in self.grouper.result_index ])) result.index = index result = result.sort_index() @@ -1348,6 +1347,11 @@ def groups(self): to_groupby = Index(to_groupby) return self.axis.groupby(to_groupby.values) + @cache_readonly + def is_monotonic(self): + # return if my group orderings are monotonic + return Index(self.group_info[0]).is_monotonic + @cache_readonly def group_info(self): comp_ids, obs_group_ids = self._get_compressed_labels() @@ -1739,6 +1743,11 @@ def indices(self): i = bin return indices + @cache_readonly + def group_info(self): + # for compat + return self.bins, self.binlabels, self.ngroups + @cache_readonly def ngroups(self): return len(self.binlabels) diff --git a/pandas/tests/test_groupby.py b/pandas/tests/test_groupby.py index 3fdd7c3459c74..09763d53c017d 100644 --- a/pandas/tests/test_groupby.py +++ b/pandas/tests/test_groupby.py @@ -897,6 +897,11 @@ def demean(arr): expected = people.groupby(key).apply(demean).groupby(key).mean() assert_frame_equal(result, expected) + # GH 8430 + df = tm.makeTimeDataFrame() + g = df.groupby(pd.TimeGrouper('M')) + g.transform(lambda x: x-1) + def test_transform_fast(self): df = DataFrame( { 'id' : np.arange( 100000 ) / 3,