Skip to content

Commit

Permalink
Merge pull request #220 from nalepae/revert-resample
Browse files Browse the repository at this point in the history
Revert "Add `parallel_apply` for `Resampler` class (#211)"
  • Loading branch information
nalepae authored Jan 15, 2023
2 parents ff8271b + 347ed22 commit bc2712a
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 179 deletions.
7 changes: 0 additions & 7 deletions pandarallel/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from pandas.core.groupby import DataFrameGroupBy as PandaDataFrameGroupBy
from pandas.core.window.expanding import ExpandingGroupby as PandasExpandingGroupby
from pandas.core.window.rolling import RollingGroupby as PandasRollingGroupby
from pandas.core.resample import Resampler as PandasResampler

from .data_types import (
DataFrame,
Expand All @@ -23,7 +22,6 @@
RollingGroupBy,
Series,
SeriesRolling,
Resampler
)
from .progress_bars import ProgressBarsType, get_progress_bars, progress_wrapper
from .utils import WorkerStatus
Expand Down Expand Up @@ -556,8 +554,3 @@ def initialize(
pd.core.window.Rolling.parallel_apply = parallelize(
nb_workers, SeriesRolling.Apply, progress_bars_in_user_defined_function
)

# Resampler
PandasResampler.parallel_apply = parallelize(
nb_workers, Resampler.Apply, progress_bars_in_user_defined_function
)
1 change: 0 additions & 1 deletion pandarallel/data_types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
from .generic import DataType
from .series import Series
from .series_rolling import SeriesRolling
from .resampler import Resampler
64 changes: 0 additions & 64 deletions pandarallel/data_types/resampler.py

This file was deleted.

107 changes: 0 additions & 107 deletions tests/test_pandarallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def func(x):
@pytest.fixture()
def func_dataframe_groupby_apply():
def func(df):
import math
dum = 0
for item in df.b:
dum += math.log10(math.sqrt(math.exp(item**2)))
Expand Down Expand Up @@ -157,46 +156,6 @@ def func(x):
return dict(named=func, anonymous=lambda x: x**2)[request.param]


@pytest.fixture()
def func_dataframe_resampler_apply():
def func(df):
import math
dum = 0
for item in df.b:
dum += math.log10(math.sqrt(math.exp(item**2)))

return dum / len(df.b)

return func


@pytest.fixture()
def func_dataframe_resampler_apply_complex():
def func(df):
return pd.DataFrame(
[[df.b.mean(), df.b.min(), df.b.max()]],
columns=["b_mean", "b_min", "b_max"],
)

return func


@pytest.fixture()
def func_dataframe_resampler_apply_series():
def func(df):
return df.iloc[0]

return func


@pytest.fixture()
def func_series_resampler_apply():
def func(x):
return x.sum()

return func


@pytest.fixture
def pandarallel_init(progress_bar, use_memory_fs):
pandarallel.initialize(
Expand Down Expand Up @@ -397,69 +356,3 @@ def test_dataframe_axis_1_no_reduction(
res_parallel = df.parallel_apply(func_dataframe_apply_axis_1_no_reduce, axis=1)

assert res.equals(res_parallel)


def test_dataframe_resampler_apply(
pandarallel_init, func_dataframe_resampler_apply, df_size
):
df = pd.DataFrame(
dict(
b=np.random.rand(df_size),
c=np.random.rand(df_size),
),
index=pd.to_datetime(np.arange(df_size), unit="m")
)

if pd.__version__ != "1.0.5":
res = df.resample("h").apply(func_dataframe_resampler_apply)
res_parallel = df.resample("h").parallel_apply(func_dataframe_resampler_apply)
assert res.equals(res_parallel)
else:
with pytest.raises(AttributeError):
res = df.resample("h").apply(func_dataframe_resampler_apply)


def test_dataframe_resampler_apply_complex(
pandarallel_init, func_dataframe_resampler_apply_complex, df_size
):
df = pd.DataFrame(
dict(b=np.random.rand(df_size)),
index=pd.to_datetime(np.arange(df_size), unit="m")
)

if pd.__version__ != "1.0.5":
res = df.resample("h").apply(func_dataframe_resampler_apply_complex)
res_parallel = df.resample("h").parallel_apply(func_dataframe_resampler_apply_complex)
assert res.equals(res_parallel)
else:
with pytest.raises(AttributeError):
res = df.resample("h").apply(func_dataframe_resampler_apply_complex)


def test_dataframe_resampler_apply_series(
pandarallel_init, func_dataframe_resampler_apply_series, df_size
):
df = pd.DataFrame(
dict(
b=np.random.rand(df_size),
c=np.random.rand(df_size),
),
index=pd.to_datetime(np.arange(df_size), unit="m")
)


res = df.resample("h").apply(func_dataframe_resampler_apply_series)
res_parallel = df.resample("h").parallel_apply(func_dataframe_resampler_apply_series)
assert res.equals(res_parallel)

def test_series_resampler_apply(
pandarallel_init, func_series_resampler_apply, df_size
):
df = pd.Series(
np.random.rand(df_size),
index=pd.to_datetime(np.arange(df_size), unit="m")
)

res = df.resample("h").apply(func_series_resampler_apply)
res_parallel = df.resample("h").parallel_apply(func_series_resampler_apply)
assert res.equals(res_parallel)

0 comments on commit bc2712a

Please sign in to comment.