Skip to content

Commit

Permalink
add tests for 'limit_area'
Browse files Browse the repository at this point in the history
Signed-off-by: Anatoly Myachev <[email protected]>
  • Loading branch information
anmyachev committed Feb 9, 2024
1 parent 710b2ef commit 361d7fa
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
8 changes: 6 additions & 2 deletions modin/pandas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def _binary_op(self, op, other, **kwargs):
new_query_compiler = getattr(self._query_compiler, op)(other, **kwargs)
return self._create_or_update_from_compiler(new_query_compiler)

def _default_to_pandas(self, op, *args, **kwargs):
def _default_to_pandas(self, op, *args, reason: str = None, **kwargs):
"""
Convert dataset to pandas type and call a pandas function on it.
Expand All @@ -481,6 +481,7 @@ def _default_to_pandas(self, op, *args, **kwargs):
Name of pandas function.
*args : list
Additional positional arguments to be passed to `op`.
reason : str, optional
**kwargs : dict
Additional keywords arguments to be passed to `op`.
Expand All @@ -495,7 +496,8 @@ def _default_to_pandas(self, op, *args, **kwargs):
type(self).__name__,
op if isinstance(op, str) else op.__name__,
empty_self_str,
)
),
reason=reason,
)

args = try_cast_to_pandas(args)
Expand Down Expand Up @@ -1112,6 +1114,7 @@ def bfill(
if limit_area is not None:
return self._default_to_pandas(
"bfill",
reason="'limit_area' parameter isn't supported",
axis=axis,
inplace=inplace,
limit=limit,
Expand Down Expand Up @@ -1620,6 +1623,7 @@ def ffill(
if limit_area is not None:
return self._default_to_pandas(
"ffill",
reason="'limit_area' parameter isn't supported",
axis=axis,
inplace=inplace,
limit=limit,
Expand Down
2 changes: 1 addition & 1 deletion modin/pandas/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ def apply(
"""
Apply a function along an axis of the ``DataFrame``.
"""
if by_row != "compat" or engine != "python":
if by_row != "compat" or engine != "python" or engine_kwargs:
# TODO: add test
return self._default_to_pandas(
pandas.DataFrame.apply,
Expand Down
2 changes: 1 addition & 1 deletion modin/pandas/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2539,7 +2539,7 @@ def _inflate_light(cls, query_compiler, name, source_pid):
"""
if os.getpid() != source_pid:
res = query_compiler.to_pandas()
# at the query compiler level, `to_pandas` always returns a DataFrame,
# at the query compiler layer, `to_pandas` always returns a DataFrame,
# even if it stores a Series, as a single-column DataFrame
if res.columns == [MODIN_UNNAMED_SERIES_LABEL]:
res = res.squeeze(axis=1)
Expand Down
9 changes: 9 additions & 0 deletions modin/pandas/test/dataframe/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ def test_bfill(data):
df_equals(modin_df.bfill(), pandas_df.bfill())


@pytest.mark.parametrize("limit_area", [None, "inside", "outside"])
@pytest.mark.parametrize("method", ["ffill", "bfill"])
def test_ffill_bfill_limit_area(method, limit_area):
modin_df, pandas_df = create_test_dfs([1, None, 2, None])
eval_general(
modin_df, pandas_df, lambda df: getattr(df, method)(limit_area=limit_area)
)


@pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)
def test_bool(data):
modin_df = pd.DataFrame(data)
Expand Down
9 changes: 9 additions & 0 deletions modin/pandas/test/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1997,6 +1997,15 @@ def test_ffill(data):
df_equals(modin_series_cp, pandas_series_cp)


@pytest.mark.parametrize("limit_area", [None, "inside", "outside"])
@pytest.mark.parametrize("method", ["ffill", "bfill"])
def test_ffill_bfill_limit_area(method, limit_area):
modin_ser, pandas_ser = create_test_series([1, None, 2, None])
eval_general(
modin_ser, pandas_ser, lambda ser: getattr(ser, method)(limit_area=limit_area)
)


@pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)
@pytest.mark.parametrize("reindex", [None, 2, -2])
@pytest.mark.parametrize("limit", [None, 1, 2, 0.5, -1, -2, 1.5])
Expand Down

0 comments on commit 361d7fa

Please sign in to comment.