Skip to content

Commit ebeb09e

Browse files
committed
COMPAT/TST: fix group_info dtype issues, xref #10981
1 parent 2d0d58c commit ebeb09e

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

pandas/core/groupby.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1793,13 +1793,13 @@ def indices(self):
17931793
@cache_readonly
17941794
def group_info(self):
17951795
ngroups = self.ngroups
1796-
obs_group_ids = np.arange(ngroups)
1796+
obs_group_ids = np.arange(ngroups, dtype='int64')
17971797
rep = np.diff(np.r_[0, self.bins])
17981798

17991799
if ngroups == len(self.bins):
1800-
comp_ids = np.repeat(np.arange(ngroups), rep)
1800+
comp_ids = np.repeat(np.arange(ngroups, dtype='int64'), rep)
18011801
else:
1802-
comp_ids = np.repeat(np.r_[-1, np.arange(ngroups)], rep)
1802+
comp_ids = np.repeat(np.r_[-1, np.arange(ngroups, dtype='int64')], rep)
18031803

18041804
return comp_ids, obs_group_ids, ngroups
18051805

@@ -2552,8 +2552,8 @@ def nunique(self, dropna=True):
25522552

25532553
# group boundries are where group ids change
25542554
# unique observations are where sorted values change
2555-
idx = np.r_[0, 1 + np.nonzero(ids[1:] != ids[:-1])[0]]
2556-
inc = np.r_[1, val[1:] != val[:-1]]
2555+
idx = com._ensure_int64(np.r_[0, 1 + np.nonzero(ids[1:] != ids[:-1])[0]])
2556+
inc = com._ensure_int64(np.r_[1, val[1:] != val[:-1]])
25572557

25582558
# 1st item of each group is a new unique observation
25592559
mask = isnull(val)

pandas/tseries/tests/test_resample.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ def test_resample_timegrouper(self):
919919
def test_resample_group_info(self): # GH10914
920920
for n, k in product((10000, 100000), (10, 100, 1000)):
921921
dr = date_range(start='2015-08-27', periods=n // 10, freq='T')
922-
ts = Series(np.random.randint(0, n // k, n),
922+
ts = Series(np.random.randint(0, n // k, n).astype('int64'),
923923
index=np.random.choice(dr, n))
924924

925925
left = ts.resample('30T', how='nunique')
@@ -1585,7 +1585,7 @@ def test_aggregate_with_nat(self):
15851585
# check TimeGrouper's aggregation is identical as normal groupby
15861586

15871587
n = 20
1588-
data = np.random.randn(n, 4)
1588+
data = np.random.randn(n, 4).astype('int64')
15891589
normal_df = DataFrame(data, columns=['A', 'B', 'C', 'D'])
15901590
normal_df['key'] = [1, 2, np.nan, 4, 5] * 4
15911591

0 commit comments

Comments
 (0)