Skip to content

Commit 01d275f

Browse files
committed
Merge pull request #8434 from jreback/bin_grouper
BUG: Groupby.transform related to BinGrouper and GH8046 (GH8430)
2 parents 8d3a39a + b3ce297 commit 01d275f

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

doc/source/v0.15.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ Bug Fixes
880880
when matching block and manager items, when there's only one block there's no ambiguity (:issue:`7794`)
881881
- Bug in putting a ``PeriodIndex`` into a ``Series`` would convert to ``int64`` dtype, rather than ``object`` of ``Periods`` (:issue:`7932`)
882882
- Bug in HDFStore iteration when passing a where (:issue:`8014`)
883-
- Bug in DataFrameGroupby.transform when transforming with a passed non-sorted key (:issue:`8046`)
883+
- Bug in DataFrameGroupby.transform when transforming with a passed non-sorted key (:issue:`8046`, :issue:`8430`)
884884
- Bug in repeated timeseries line and area plot may result in ``ValueError`` or incorrect kind (:issue:`7733`)
885885
- Bug in inference in a MultiIndex with ``datetime.date`` inputs (:issue:`7888`)
886886
- Bug in ``get`` where an ``IndexError`` would not cause the default value to be returned (:issue:`7725`)

pandas/core/groupby.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,7 @@ def _set_result_index_ordered(self, result):
484484
indices = self.indices
485485

486486
# shortcut of we have an already ordered grouper
487-
488-
if not Index(self.grouper.group_info[0]).is_monotonic:
487+
if not self.grouper.is_monotonic:
489488
index = Index(np.concatenate([ indices[v] for v in self.grouper.result_index ]))
490489
result.index = index
491490
result = result.sort_index()
@@ -1348,6 +1347,11 @@ def groups(self):
13481347
to_groupby = Index(to_groupby)
13491348
return self.axis.groupby(to_groupby.values)
13501349

1350+
@cache_readonly
1351+
def is_monotonic(self):
1352+
# return if my group orderings are monotonic
1353+
return Index(self.group_info[0]).is_monotonic
1354+
13511355
@cache_readonly
13521356
def group_info(self):
13531357
comp_ids, obs_group_ids = self._get_compressed_labels()
@@ -1739,6 +1743,11 @@ def indices(self):
17391743
i = bin
17401744
return indices
17411745

1746+
@cache_readonly
1747+
def group_info(self):
1748+
# for compat
1749+
return self.bins, self.binlabels, self.ngroups
1750+
17421751
@cache_readonly
17431752
def ngroups(self):
17441753
return len(self.binlabels)

pandas/tests/test_groupby.py

+5
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,11 @@ def demean(arr):
897897
expected = people.groupby(key).apply(demean).groupby(key).mean()
898898
assert_frame_equal(result, expected)
899899

900+
# GH 8430
901+
df = tm.makeTimeDataFrame()
902+
g = df.groupby(pd.TimeGrouper('M'))
903+
g.transform(lambda x: x-1)
904+
900905
def test_transform_fast(self):
901906

902907
df = DataFrame( { 'id' : np.arange( 100000 ) / 3,

0 commit comments

Comments
 (0)