From b6f00449c85a90d66b8661c9da0c0a0e4708eb03 Mon Sep 17 00:00:00 2001 From: Brock Date: Sun, 2 May 2021 18:56:20 -0700 Subject: [PATCH] REF: clearer names in libreduction --- pandas/_libs/reduction.pyx | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/pandas/_libs/reduction.pyx b/pandas/_libs/reduction.pyx index d0f85b75a629e..09999b6970bca 100644 --- a/pandas/_libs/reduction.pyx +++ b/pandas/_libs/reduction.pyx @@ -63,17 +63,17 @@ cdef class _BaseGrouper: ) return cached_index, cached_series - cdef inline _update_cached_objs(self, object cached_typ, object cached_ityp, + cdef inline _update_cached_objs(self, object cached_series, object cached_index, Slider islider, Slider vslider): # See the comment in indexes/base.py about _index_data. # We need this for EA-backed indexes that have a reference # to a 1-d ndarray like datetime / timedelta / period. - cached_ityp._engine.clear_mapping() - cached_ityp._cache.clear() # e.g. inferred_freq must go - cached_typ._mgr.set_values(vslider.buf) + cached_index._engine.clear_mapping() + cached_index._cache.clear() # e.g. inferred_freq must go + cached_series._mgr.set_values(vslider.buf) cdef inline object _apply_to_group(self, - object cached_typ, object cached_ityp, + object cached_series, object cached_index, bint initialized): """ Call self.f on our new group, then update to the next group. @@ -83,7 +83,7 @@ cdef class _BaseGrouper: # NB: we assume that _update_cached_objs has already cleared cleared # the cache and engine mapping - res = self.f(cached_typ) + res = self.f(cached_series) res = extract_result(res) if not initialized: # On the first pass, we check the output shape to see @@ -140,7 +140,7 @@ cdef class SeriesBinGrouper(_BaseGrouper): object res bint initialized = 0 Slider vslider, islider - object cached_typ = None, cached_ityp = None + object cached_series = None, cached_index = None counts = np.zeros(self.ngroups, dtype=np.int64) @@ -160,7 +160,9 @@ cdef class SeriesBinGrouper(_BaseGrouper): result = np.empty(self.ngroups, dtype='O') - cached_ityp, cached_typ = self._init_dummy_series_and_index(islider, vslider) + cached_index, cached_series = self._init_dummy_series_and_index( + islider, vslider + ) start = 0 try: @@ -172,9 +174,9 @@ cdef class SeriesBinGrouper(_BaseGrouper): vslider.move(start, end) self._update_cached_objs( - cached_typ, cached_ityp, islider, vslider) + cached_series, cached_index, islider, vslider) - res, initialized = self._apply_to_group(cached_typ, cached_ityp, + res, initialized = self._apply_to_group(cached_series, cached_index, initialized) start += group_size @@ -236,7 +238,7 @@ cdef class SeriesGrouper(_BaseGrouper): object res bint initialized = 0 Slider vslider, islider - object cached_typ = None, cached_ityp = None + object cached_series = None, cached_index = None labels = self.labels counts = np.zeros(self.ngroups, dtype=np.int64) @@ -248,7 +250,9 @@ cdef class SeriesGrouper(_BaseGrouper): result = np.empty(self.ngroups, dtype='O') - cached_ityp, cached_typ = self._init_dummy_series_and_index(islider, vslider) + cached_index, cached_series = self._init_dummy_series_and_index( + islider, vslider + ) start = 0 try: @@ -268,9 +272,9 @@ cdef class SeriesGrouper(_BaseGrouper): vslider.move(start, end) self._update_cached_objs( - cached_typ, cached_ityp, islider, vslider) + cached_series, cached_index, islider, vslider) - res, initialized = self._apply_to_group(cached_typ, cached_ityp, + res, initialized = self._apply_to_group(cached_series, cached_index, initialized) start += group_size @@ -293,20 +297,20 @@ cdef class SeriesGrouper(_BaseGrouper): return result, counts -cpdef inline extract_result(object res, bint squeeze=True): +cpdef inline extract_result(object res): """ extract the result object, it might be a 0-dim ndarray or a len-1 0-dim, or a scalar """ if hasattr(res, "_values"): # Preserve EA res = res._values - if squeeze and res.ndim == 1 and len(res) == 1: + if res.ndim == 1 and len(res) == 1: res = res[0] if hasattr(res, 'values') and is_array(res.values): res = res.values if is_array(res): if res.ndim == 0: res = res.item() - elif squeeze and res.ndim == 1 and len(res) == 1: + elif res.ndim == 1 and len(res) == 1: res = res[0] return res