Skip to content

Commit 133c7f3

Browse files
jbrockmendelJulianWgs
authored andcommitted
REF: clearer names in libreduction (pandas-dev#41274)
1 parent d89affb commit 133c7f3

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

pandas/_libs/reduction.pyx

+21-17
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,17 @@ cdef class _BaseGrouper:
6363
)
6464
return cached_index, cached_series
6565

66-
cdef inline _update_cached_objs(self, object cached_typ, object cached_ityp,
66+
cdef inline _update_cached_objs(self, object cached_series, object cached_index,
6767
Slider islider, Slider vslider):
6868
# See the comment in indexes/base.py about _index_data.
6969
# We need this for EA-backed indexes that have a reference
7070
# to a 1-d ndarray like datetime / timedelta / period.
71-
cached_ityp._engine.clear_mapping()
72-
cached_ityp._cache.clear() # e.g. inferred_freq must go
73-
cached_typ._mgr.set_values(vslider.buf)
71+
cached_index._engine.clear_mapping()
72+
cached_index._cache.clear() # e.g. inferred_freq must go
73+
cached_series._mgr.set_values(vslider.buf)
7474

7575
cdef inline object _apply_to_group(self,
76-
object cached_typ, object cached_ityp,
76+
object cached_series, object cached_index,
7777
bint initialized):
7878
"""
7979
Call self.f on our new group, then update to the next group.
@@ -83,7 +83,7 @@ cdef class _BaseGrouper:
8383

8484
# NB: we assume that _update_cached_objs has already cleared cleared
8585
# the cache and engine mapping
86-
res = self.f(cached_typ)
86+
res = self.f(cached_series)
8787
res = extract_result(res)
8888
if not initialized:
8989
# On the first pass, we check the output shape to see
@@ -140,7 +140,7 @@ cdef class SeriesBinGrouper(_BaseGrouper):
140140
object res
141141
bint initialized = 0
142142
Slider vslider, islider
143-
object cached_typ = None, cached_ityp = None
143+
object cached_series = None, cached_index = None
144144

145145
counts = np.zeros(self.ngroups, dtype=np.int64)
146146

@@ -160,7 +160,9 @@ cdef class SeriesBinGrouper(_BaseGrouper):
160160

161161
result = np.empty(self.ngroups, dtype='O')
162162

163-
cached_ityp, cached_typ = self._init_dummy_series_and_index(islider, vslider)
163+
cached_index, cached_series = self._init_dummy_series_and_index(
164+
islider, vslider
165+
)
164166

165167
start = 0
166168
try:
@@ -172,9 +174,9 @@ cdef class SeriesBinGrouper(_BaseGrouper):
172174
vslider.move(start, end)
173175

174176
self._update_cached_objs(
175-
cached_typ, cached_ityp, islider, vslider)
177+
cached_series, cached_index, islider, vslider)
176178

177-
res, initialized = self._apply_to_group(cached_typ, cached_ityp,
179+
res, initialized = self._apply_to_group(cached_series, cached_index,
178180
initialized)
179181
start += group_size
180182

@@ -236,7 +238,7 @@ cdef class SeriesGrouper(_BaseGrouper):
236238
object res
237239
bint initialized = 0
238240
Slider vslider, islider
239-
object cached_typ = None, cached_ityp = None
241+
object cached_series = None, cached_index = None
240242

241243
labels = self.labels
242244
counts = np.zeros(self.ngroups, dtype=np.int64)
@@ -248,7 +250,9 @@ cdef class SeriesGrouper(_BaseGrouper):
248250

249251
result = np.empty(self.ngroups, dtype='O')
250252

251-
cached_ityp, cached_typ = self._init_dummy_series_and_index(islider, vslider)
253+
cached_index, cached_series = self._init_dummy_series_and_index(
254+
islider, vslider
255+
)
252256

253257
start = 0
254258
try:
@@ -268,9 +272,9 @@ cdef class SeriesGrouper(_BaseGrouper):
268272
vslider.move(start, end)
269273

270274
self._update_cached_objs(
271-
cached_typ, cached_ityp, islider, vslider)
275+
cached_series, cached_index, islider, vslider)
272276

273-
res, initialized = self._apply_to_group(cached_typ, cached_ityp,
277+
res, initialized = self._apply_to_group(cached_series, cached_index,
274278
initialized)
275279

276280
start += group_size
@@ -293,20 +297,20 @@ cdef class SeriesGrouper(_BaseGrouper):
293297
return result, counts
294298

295299

296-
cpdef inline extract_result(object res, bint squeeze=True):
300+
cpdef inline extract_result(object res):
297301
""" extract the result object, it might be a 0-dim ndarray
298302
or a len-1 0-dim, or a scalar """
299303
if hasattr(res, "_values"):
300304
# Preserve EA
301305
res = res._values
302-
if squeeze and res.ndim == 1 and len(res) == 1:
306+
if res.ndim == 1 and len(res) == 1:
303307
res = res[0]
304308
if hasattr(res, 'values') and is_array(res.values):
305309
res = res.values
306310
if is_array(res):
307311
if res.ndim == 0:
308312
res = res.item()
309-
elif squeeze and res.ndim == 1 and len(res) == 1:
313+
elif res.ndim == 1 and len(res) == 1:
310314
res = res[0]
311315
return res
312316

0 commit comments

Comments
 (0)