Skip to content

REF: import _libs.reduction as libreduction #28184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import numpy as np

from pandas._libs import reduction
from pandas._libs import reduction as libreduction
from pandas.util._decorators import cache_readonly

from pandas.core.dtypes.common import (
Expand Down Expand Up @@ -221,7 +221,7 @@ def apply_raw(self):
""" apply to the values as a numpy array """

try:
result = reduction.compute_reduction(self.values, self.f, axis=self.axis)
result = libreduction.compute_reduction(self.values, self.f, axis=self.axis)
except Exception:
result = np.apply_along_axis(self.f, self.axis, self.values)

Expand Down Expand Up @@ -281,7 +281,7 @@ def apply_standard(self):
dummy = Series(empty_arr, index=index, dtype=values.dtype)

try:
result = reduction.compute_reduction(
result = libreduction.compute_reduction(
values, self.f, axis=self.axis, dummy=dummy, labels=labels
)
return self.obj._constructor_sliced(result, index=labels)
Expand Down
10 changes: 5 additions & 5 deletions pandas/core/groupby/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from pandas._libs import NaT, iNaT, lib
import pandas._libs.groupby as libgroupby
import pandas._libs.reduction as reduction
import pandas._libs.reduction as libreduction
from pandas.errors import AbstractMethodError
from pandas.util._decorators import cache_readonly

Expand Down Expand Up @@ -207,7 +207,7 @@ def apply(self, f, data, axis=0):
if len(result_values) == len(group_keys):
return group_keys, result_values, mutated

except reduction.InvalidApply:
except libreduction.InvalidApply:
# Cannot fast apply on MultiIndex (_has_complex_internals).
# This Exception is also raised if `f` triggers an exception
# but it is preferable to raise the exception in Python.
Expand Down Expand Up @@ -678,7 +678,7 @@ def _aggregate_series_fast(self, obj, func):
indexer = get_group_index_sorter(group_index, ngroups)
obj = obj.take(indexer)
group_index = algorithms.take_nd(group_index, indexer, allow_fill=False)
grouper = reduction.SeriesGrouper(obj, func, group_index, ngroups, dummy)
grouper = libreduction.SeriesGrouper(obj, func, group_index, ngroups, dummy)
result, counts = grouper.get_result()
return result, counts

Expand Down Expand Up @@ -852,7 +852,7 @@ def groupings(self):

def agg_series(self, obj, func):
dummy = obj[:0]
grouper = reduction.SeriesBinGrouper(obj, func, self.bins, dummy)
grouper = libreduction.SeriesBinGrouper(obj, func, self.bins, dummy)
return grouper.get_result()


Expand Down Expand Up @@ -940,7 +940,7 @@ def fast_apply(self, f, names):
return [], True

sdata = self._get_sorted_data()
return reduction.apply_frame_axis0(sdata, f, names, starts, ends)
return libreduction.apply_frame_axis0(sdata, f, names, starts, ends)

def _chop(self, sdata, slice_obj):
if self.axis == 0:
Expand Down
16 changes: 8 additions & 8 deletions pandas/tests/groupby/test_bin_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from numpy import nan
import pytest

from pandas._libs import groupby, lib, reduction
from pandas._libs import groupby, lib, reduction as libreduction

from pandas.core.dtypes.common import ensure_int64

Expand All @@ -18,7 +18,7 @@ def test_series_grouper():

labels = np.array([-1, -1, -1, 0, 0, 0, 1, 1, 1, 1], dtype=np.int64)

grouper = reduction.SeriesGrouper(obj, np.mean, labels, 2, dummy)
grouper = libreduction.SeriesGrouper(obj, np.mean, labels, 2, dummy)
result, counts = grouper.get_result()

expected = np.array([obj[3:6].mean(), obj[6:].mean()])
Expand All @@ -34,7 +34,7 @@ def test_series_bin_grouper():

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

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

expected = np.array([obj[:3].mean(), obj[3:6].mean(), obj[6:].mean()])
Expand Down Expand Up @@ -120,31 +120,31 @@ class TestMoments:
class TestReducer:
def test_int_index(self):
arr = np.random.randn(100, 4)
result = reduction.compute_reduction(arr, np.sum, labels=Index(np.arange(4)))
result = libreduction.compute_reduction(arr, np.sum, labels=Index(np.arange(4)))
expected = arr.sum(0)
assert_almost_equal(result, expected)

result = reduction.compute_reduction(
result = libreduction.compute_reduction(
arr, np.sum, axis=1, labels=Index(np.arange(100))
)
expected = arr.sum(1)
assert_almost_equal(result, expected)

dummy = Series(0.0, index=np.arange(100))
result = reduction.compute_reduction(
result = libreduction.compute_reduction(
arr, np.sum, dummy=dummy, labels=Index(np.arange(4))
)
expected = arr.sum(0)
assert_almost_equal(result, expected)

dummy = Series(0.0, index=np.arange(4))
result = reduction.compute_reduction(
result = libreduction.compute_reduction(
arr, np.sum, axis=1, dummy=dummy, labels=Index(np.arange(100))
)
expected = arr.sum(1)
assert_almost_equal(result, expected)

result = reduction.compute_reduction(
result = libreduction.compute_reduction(
arr, np.sum, axis=1, dummy=dummy, labels=Index(np.arange(100))
)
assert_almost_equal(result, expected)