Skip to content

BUG: Groupby.transform related to BinGrouper and GH8046 (GH8430) #8434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 1, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/v0.15.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
13 changes: 11 additions & 2 deletions pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down