Skip to content

Commit 4445c02

Browse files
committed
Remove breakpoints
1 parent 270668d commit 4445c02

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

pandas/core/groupby/generic.py

+5-20
Original file line numberDiff line numberDiff line change
@@ -1141,17 +1141,11 @@ def nunique(self, dropna=True):
11411141
Number of unique values within each group.
11421142
"""
11431143
ids, _, _ = self.grouper.group_info
1144-
# breakpoint()
11451144

11461145
val = self.obj._internal_get_values()
1147-
# breakpoint()
11481146

1149-
# # GH 27951
1150-
# breakpoint()
1147+
# GH 27951
11511148
val[isna(val)] = np.datetime64("NaT")
1152-
# mask = notna(val)
1153-
# ids = ids[mask]
1154-
# val = val[mask]
11551149

11561150
try:
11571151
sorter = np.lexsort((val, ids))
@@ -1163,29 +1157,22 @@ def nunique(self, dropna=True):
11631157
_isna = lambda a: a == -1
11641158
else:
11651159
_isna = isna
1166-
# breakpoint()
11671160

11681161
ids, val = ids[sorter], val[sorter]
1169-
# breakpoint()
11701162

11711163
# group boundaries are where group ids change
11721164
# unique observations are where sorted values change
1173-
# idx: ids at which groups change
11741165
idx = np.r_[0, 1 + np.nonzero(ids[1:] != ids[:-1])[0]]
1175-
# inc: 1 if it's a new value, 0 else
11761166
inc = np.r_[1, val[1:] != val[:-1]]
1177-
# breakpoint()
11781167

11791168
# 1st item of each group is a new unique observation
11801169
mask = _isna(val)
11811170
if dropna:
1182-
inc[idx] = 1 # 1st itme of each group is defo unique!
1183-
inc[mask] = 0 # Nas should be excluded, we don't like them!
1171+
inc[idx] = 1
1172+
inc[mask] = 0
11841173
else:
1185-
inc[mask & np.r_[False, mask[:-1]]] = 0 # only set it to
1186-
# zero if there are two consecutive nans?
1187-
inc[idx] = 1 # As before, first of each group is defo unique
1188-
# breakpoint()
1174+
inc[mask & np.r_[False, mask[:-1]]] = 0
1175+
inc[idx] = 1
11891176

11901177
out = np.add.reduceat(inc, idx).astype("int64", copy=False)
11911178
if len(ids):
@@ -1199,13 +1186,11 @@ def nunique(self, dropna=True):
11991186
else:
12001187
res = out[1:]
12011188
ri = self.grouper.result_index
1202-
# breakpoint()
12031189

12041190
# we might have duplications among the bins
12051191
if len(res) != len(ri):
12061192
res, out = np.zeros(len(ri), dtype=out.dtype), res
12071193
res[ids[idx]] = out
1208-
# breakpoint()
12091194

12101195
return Series(res, index=ri, name=self._selection_name)
12111196

0 commit comments

Comments
 (0)