Skip to content

BUG: closes bug in BinGrouper.group_info where returned values are not compatible with base class #10918

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
Aug 28, 2015
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.17.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ Bug Fixes
- Bug in ``Index`` construction with a mixed list of tuples (:issue:`10697`)
- Bug in ``DataFrame.reset_index`` when index contains `NaT`. (:issue:`10388`)
- Bug in ``ExcelReader`` when worksheet is empty (:issue:`6403`)
- Bug in ``BinGrouper.group_info`` where returned values are not compatible with base class (:issue:`10914`)


- Bug causing ``DataFrame.where`` to not respect the ``axis`` parameter when the frame has a symmetric shape. (:issue:`9736`)
Expand Down
6 changes: 4 additions & 2 deletions pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1790,8 +1790,10 @@ def indices(self):

@cache_readonly
def group_info(self):
# for compat
return self.bins, self.binlabels, self.ngroups
ngroups = self.ngroups
obs_group_ids = np.arange(ngroups)
comp_ids = np.repeat(np.arange(ngroups), np.diff(np.r_[0, self.bins]))
return comp_ids, obs_group_ids, ngroups

@cache_readonly
def ngroups(self):
Expand Down
25 changes: 25 additions & 0 deletions pandas/tseries/tests/test_resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,31 @@ def test_resample_timegrouper(self):
result = df.groupby(pd.Grouper(freq='M', key='A')).count()
assert_frame_equal(result, expected)

def test_resample_group_info(self): # GH10914
for n, k in product((10000, 100000), (10, 100, 1000)):
dr = date_range(start='2015-08-27', periods=n // 10, freq='T')
ts = Series(np.random.randint(0, n // k, n),
index=np.random.choice(dr, n))

left = ts.resample('30T', how='nunique')
ix = date_range(start=ts.index.min(),
end=ts.index.max(),
freq='30T')

vals = ts.values
bins = np.searchsorted(ix.values, ts.index, side='right')

sorter = np.lexsort((vals, bins))
vals, bins = vals[sorter], bins[sorter]

mask = np.r_[True, vals[1:] != vals[:-1]]
mask |= np.r_[True, bins[1:] != bins[:-1]]

arr = np.bincount(bins[mask] - 1, minlength=len(ix))
right = Series(arr, index=ix)

assert_series_equal(left, right)

def test_resmaple_dst_anchor(self):
# 5172
dti = DatetimeIndex([datetime(2012, 11, 4, 23)], tz='US/Eastern')
Expand Down