Skip to content

Commit

Permalink
API fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Anatoly Myachev <anatoly.myachev@intel.com>
  • Loading branch information
anmyachev committed Feb 7, 2024
1 parent 50caeb4 commit e7b28b7
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 15 deletions.
38 changes: 34 additions & 4 deletions modin/pandas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,11 +1106,26 @@ def _deprecate_downcast(self, downcast, method_name: str):
return downcast

def bfill(
self, *, axis=None, inplace=False, limit=None, downcast=lib.no_default
self,
*,
axis=None,
inplace=False,
limit=None,
limit_area=None,
downcast=lib.no_default,
): # noqa: PR01, RT01, D200
"""
Synonym for `DataFrame.fillna` with ``method='bfill'``.
"""
if limit_area is not None:
return self._default_to_pandas(
"bfill",
axis=axis,
inplace=inplace,
limit=limit,
limit_area=limit_area,
downcast=downcast,
)
downcast = self._deprecate_downcast(downcast, "bfill")
with warnings.catch_warnings():
warnings.filterwarnings(
Expand Down Expand Up @@ -1599,11 +1614,26 @@ def expanding(
)

def ffill(
self, *, axis=None, inplace=False, limit=None, downcast=lib.no_default
self,
*,
axis=None,
inplace=False,
limit=None,
limit_area=None,
downcast=lib.no_default,
): # noqa: PR01, RT01, D200
"""
Synonym for `DataFrame.fillna` with ``method='ffill'``.
"""
if limit_area is not None:
return self._default_to_pandas(
"ffill",
axis=axis,
inplace=inplace,
limit=limit,
limit_area=limit_area,
downcast=downcast,
)
downcast = self._deprecate_downcast(downcast, "ffill")
with warnings.catch_warnings():
warnings.filterwarnings(
Expand Down Expand Up @@ -2489,8 +2519,8 @@ def resample(
axis: Axis = lib.no_default,
closed: Optional[str] = None,
label: Optional[str] = None,
convention: str = "start",
kind: Optional[str] = None,
convention: str = lib.no_default,
kind: Optional[str] = lib.no_default,
on: Level = None,
level: Level = None,
origin: Union[str, TimestampConvertibleTypes] = "start_day",
Expand Down
8 changes: 6 additions & 2 deletions modin/pandas/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,14 @@ def apply(
result_type=None,
args=(),
by_row="compat",
engine="python",
engine_kwargs=None,
**kwargs,
): # noqa: PR01, RT01, D200
"""
Apply a function along an axis of the ``DataFrame``.
"""
if by_row != "compat":
if by_row != "compat" or engine != "python":
# TODO: add test
return self._default_to_pandas(
pandas.DataFrame.apply,
Expand All @@ -409,6 +411,8 @@ def apply(
result_type=result_type,
args=args,
by_row=by_row,
engine=engine,
engine_kwargs=engine_kwargs,
**kwargs,
)

Expand Down Expand Up @@ -1446,7 +1450,7 @@ def pivot_table(
margins=False,
dropna=True,
margins_name="All",
observed=False,
observed=lib.no_default,
sort=True,
): # noqa: PR01, RT01, D200
"""
Expand Down
3 changes: 2 additions & 1 deletion modin/pandas/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,14 @@ def _get_groups(self):
Groups as specified by resampling arguments.
"""
df = self._dataframe if self.axis == 0 else self._dataframe.T
convention = self.resample_kwargs["convention"]
groups = df.groupby(
pandas.Grouper(
key=self.resample_kwargs["on"],
freq=self.resample_kwargs["rule"],
closed=self.resample_kwargs["closed"],
label=self.resample_kwargs["label"],
convention=self.resample_kwargs["convention"],
convention=convention if convention is not lib.no_default else "start",
level=self.resample_kwargs["level"],
origin=self.resample_kwargs["origin"],
offset=self.resample_kwargs["offset"],
Expand Down
4 changes: 2 additions & 2 deletions modin/pandas/series_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

@_inherit_docstrings(pandas.core.arrays.arrow.ListAccessor)
class ListAccessor(ClassLogger):
def __init__(self, data):
def __init__(self, data=None):
self._series = data
self._query_compiler = data._query_compiler

Expand Down Expand Up @@ -71,7 +71,7 @@ def _default_to_pandas(self, op, *args, **kwargs):

@_inherit_docstrings(pandas.core.arrays.arrow.StructAccessor)
class StructAccessor(ClassLogger):
def __init__(self, data):
def __init__(self, data=None):
self._series = data
self._query_compiler = data._query_compiler

Expand Down
10 changes: 5 additions & 5 deletions modin/pandas/test/dataframe/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ def test_replace():
df_equals(modin_df, pandas_df)


@pytest.mark.parametrize("rule", ["5T", pandas.offsets.Hour()])
@pytest.mark.parametrize("rule", ["5min", pandas.offsets.Hour()])
@pytest.mark.parametrize("axis", [0])
def test_resampler(rule, axis):
data, index = (
Expand All @@ -808,7 +808,7 @@ def test_resampler(rule, axis):
)


@pytest.mark.parametrize("rule", ["5T"])
@pytest.mark.parametrize("rule", ["5min"])
@pytest.mark.parametrize("axis", ["index", "columns"])
@pytest.mark.parametrize(
"method",
Expand All @@ -833,7 +833,7 @@ def test_resampler_functions(rule, axis, method):
)


@pytest.mark.parametrize("rule", ["5T"])
@pytest.mark.parametrize("rule", ["5min"])
@pytest.mark.parametrize("axis", ["index", "columns"])
@pytest.mark.parametrize(
"method_arg",
Expand Down Expand Up @@ -861,7 +861,7 @@ def test_resampler_functions_with_arg(rule, axis, method_arg):
)


@pytest.mark.parametrize("rule", ["5T"])
@pytest.mark.parametrize("rule", ["5min"])
@pytest.mark.parametrize("closed", ["left", "right"])
@pytest.mark.parametrize("label", ["right", "left"])
@pytest.mark.parametrize(
Expand Down Expand Up @@ -955,7 +955,7 @@ def test_resample_getitem(columns):
}
eval_general(
*create_test_dfs(data, index=index),
lambda df: df.resample("3T")[columns].mean(),
lambda df: df.resample("3min")[columns].mean(),
)


Expand Down
2 changes: 1 addition & 1 deletion modin/pandas/test/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2936,7 +2936,7 @@ def test_replace():
@pytest.mark.parametrize("level", [None, 1])
@pytest.mark.exclude_in_sanity
def test_resample(closed, label, level):
rule = "5T"
rule = "5min"
freq = "h"

index = pandas.date_range("1/1/2000", periods=12, freq=freq)
Expand Down

0 comments on commit e7b28b7

Please sign in to comment.