示例#1
0
文件: ops.py 项目: solaris33/pandas
 def _aggregate_series_fast(self, obj: Series,
                            func: F) -> tuple[ArrayLike, np.ndarray]:
     # At this point we have already checked that
     #  - obj.index is not a MultiIndex
     #  - obj is backed by an ndarray, not ExtensionArray
     #  - ngroups != 0
     #  - len(self.bins) > 0
     sbg = libreduction.SeriesBinGrouper(obj, func, self.bins)
     return sbg.get_result()
示例#2
0
文件: ops.py 项目: krey/pandas
    def agg_series(self, obj: Series, func):
        if is_extension_array_dtype(obj.dtype):
            # pre-empty SeriesBinGrouper from raising TypeError
            # TODO: watch out, this can return None
            return self._aggregate_series_pure_python(obj, func)

        dummy = obj[:0]
        grouper = libreduction.SeriesBinGrouper(obj, func, self.bins, dummy)
        return grouper.get_result()
示例#3
0
文件: ops.py 项目: samay20/pandas
    def agg_series(self, obj: Series, func: F):
        # Caller is responsible for checking ngroups != 0
        assert self.ngroups != 0
        assert len(self.bins) > 0  # otherwise we'd get IndexError in get_result

        if is_extension_array_dtype(obj.dtype):
            # preempt SeriesBinGrouper from raising TypeError
            return self._aggregate_series_pure_python(obj, func)

        grouper = libreduction.SeriesBinGrouper(obj, func, self.bins)
        return grouper.get_result()
示例#4
0
def test_series_bin_grouper():
    obj = Series(np.random.randn(10))

    bins = np.array([3, 6])

    grouper = libreduction.SeriesBinGrouper(obj, np.mean, bins)
    result, counts = grouper.get_result()

    expected = np.array([obj[:3].mean(), obj[3:6].mean(), obj[6:].mean()])
    tm.assert_almost_equal(result, expected)

    exp_counts = np.array([3, 3, 4], dtype=np.int64)
    tm.assert_almost_equal(counts, exp_counts)
def test_series_bin_grouper():
    from pandas import Series
    obj = Series(np.random.randn(10))
    dummy = obj[:0]

    bins = np.array([3, 6])

    grouper = reduction.SeriesBinGrouper(obj, np.mean, bins, dummy)
    result, counts = grouper.get_result()

    expected = np.array([obj[:3].mean(), obj[3:6].mean(), obj[6:].mean()])
    assert_almost_equal(result, expected)

    exp_counts = np.array([3, 3, 4], dtype=np.int64)
    assert_almost_equal(counts, exp_counts)
示例#6
0
    def agg_series(self,
                   obj: Series,
                   func,
                   *args,
                   engine="cython",
                   engine_kwargs=None,
                   **kwargs):
        # Caller is responsible for checking ngroups != 0
        assert self.ngroups != 0
        assert len(
            self.bins) > 0  # otherwise we'd get IndexError in get_result

        if is_extension_array_dtype(obj.dtype):
            # pre-empt SeriesBinGrouper from raising TypeError
            return self._aggregate_series_pure_python(obj, func)

        dummy = obj[:0]
        grouper = libreduction.SeriesBinGrouper(obj, func, self.bins, dummy)
        return grouper.get_result()
示例#7
0
文件: ops.py 项目: yhaque1213/pandas
 def agg_series(self, obj, func):
     dummy = obj[:0]
     grouper = reduction.SeriesBinGrouper(obj, func, self.bins, dummy)
     return grouper.get_result()