Skip to content

Commit

Permalink
FIX-#6585: avoid FutureWarnings in rolling unless necessary (#6586)
Browse files Browse the repository at this point in the history
Signed-off-by: Anatoly Myachev <[email protected]>
  • Loading branch information
anmyachev authored Oct 3, 2023
1 parent 2087e18 commit 77b8d36
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
4 changes: 2 additions & 2 deletions modin/core/storage_formats/pandas/query_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1519,9 +1519,9 @@ def expanding_corr(
)
)
rolling_quantile = Fold.register(
lambda df, rolling_kwargs, quantile, interpolation, **kwargs: pandas.DataFrame(
lambda df, rolling_kwargs, q, interpolation, **kwargs: pandas.DataFrame(
df.rolling(**rolling_kwargs).quantile(
quantile=quantile, interpolation=interpolation, **kwargs
q=q, interpolation=interpolation, **kwargs
)
)
)
Expand Down
4 changes: 2 additions & 2 deletions modin/pandas/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def pytest_collection_modifyitems(items):
):
for item in items:
if item.name in (
"test_dataframe_dt_index[3s-both-DateCol-0]",
"test_dataframe_dt_index[3s-right-DateCol-0]",
"test_dataframe_dt_index[3s-both-DateCol-_NoDefault.no_default]",
"test_dataframe_dt_index[3s-right-DateCol-_NoDefault.no_default]",
):
item.add_marker(
pytest.mark.xfail(
Expand Down
41 changes: 34 additions & 7 deletions modin/pandas/test/test_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import numpy as np
import pandas
import pandas._libs.lib as lib
import pytest

import modin.pandas as pd
Expand All @@ -34,7 +35,19 @@
# have too many such instances.
# TODO(https://github.com/modin-project/modin/issues/3655): catch all instances
# of defaulting to pandas.
pytestmark = pytest.mark.filterwarnings(default_to_pandas_ignore_string)
pytestmark = [
pytest.mark.filterwarnings(default_to_pandas_ignore_string),
# TO MAKE SURE ALL FUTUREWARNINGS ARE CONSIDERED
pytest.mark.filterwarnings("error::FutureWarning"),
# IGNORE FUTUREWARNINGS MARKS TO CLEANUP OUTPUT
pytest.mark.filterwarnings(
"ignore:Support for axis=1 in DataFrame.rolling is deprecated:FutureWarning"
),
# FIXME: these cases inconsistent between modin and pandas
pytest.mark.filterwarnings(
"ignore:.*In a future version of pandas, the provided callable will be used directly.*:FutureWarning"
),
]


def create_test_series(vals):
Expand All @@ -50,7 +63,7 @@ def create_test_series(vals):
@pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)
@pytest.mark.parametrize("window", [5, 100])
@pytest.mark.parametrize("min_periods", [None, 5])
@pytest.mark.parametrize("axis", [0, 1])
@pytest.mark.parametrize("axis", [lib.no_default, 1])
@pytest.mark.parametrize(
"method, kwargs",
[
Expand Down Expand Up @@ -94,7 +107,7 @@ def test_dataframe_rolling(data, window, min_periods, axis, method, kwargs):
@pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)
@pytest.mark.parametrize("window", [5, 100])
@pytest.mark.parametrize("min_periods", [None, 5])
@pytest.mark.parametrize("axis", [0, 1])
@pytest.mark.parametrize("axis", [lib.no_default, 1])
def test_dataframe_agg(data, window, min_periods, axis):
modin_df, pandas_df = create_test_dfs(data)
if window > len(pandas_df):
Expand All @@ -119,7 +132,7 @@ def test_dataframe_agg(data, window, min_periods, axis):
@pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)
@pytest.mark.parametrize("window", [5, 100])
@pytest.mark.parametrize("min_periods", [None, 5])
@pytest.mark.parametrize("axis", [0, 1])
@pytest.mark.parametrize("axis", [lib.no_default, 1])
@pytest.mark.parametrize(
"method, kwargs",
[
Expand Down Expand Up @@ -150,7 +163,7 @@ def test_dataframe_window(data, window, min_periods, axis, method, kwargs):
)


@pytest.mark.parametrize("axis", [0, "columns"])
@pytest.mark.parametrize("axis", [lib.no_default, "columns"])
@pytest.mark.parametrize("on", [None, "DateCol"])
@pytest.mark.parametrize("closed", ["both", "right"])
@pytest.mark.parametrize("window", [3, "3s"])
Expand All @@ -159,7 +172,7 @@ def test_dataframe_dt_index(axis, on, closed, window):
data = {"A": range(12), "B": range(12)}
pandas_df = pandas.DataFrame(data, index=index)
modin_df = pd.DataFrame(data, index=index)
if on is not None and axis == 0 and isinstance(window, str):
if on is not None and axis == lib.no_default and isinstance(window, str):
pandas_df[on] = pandas.date_range("22/06/1941", periods=12, freq="T")
modin_df[on] = pd.date_range("22/06/1941", periods=12, freq="T")
else:
Expand All @@ -181,7 +194,7 @@ def test_dataframe_dt_index(axis, on, closed, window):
df_equals(
modin_rolled.cov(modin_df, False), pandas_rolled.cov(pandas_df, False)
)
if axis == 0:
if axis == lib.no_default:
df_equals(
modin_rolled.cov(modin_df[modin_df.columns[0]], True),
pandas_rolled.cov(pandas_df[pandas_df.columns[0]], True),
Expand Down Expand Up @@ -333,3 +346,17 @@ def test_issue_3512():
pandas_ans = pandas_df[0:33].rolling(window=21).mean()

df_equals(modin_ans, pandas_ans)


### TEST ROLLING WARNINGS ###


def test_rolling_axis_1_depr():
index = pandas.date_range("31/12/2000", periods=12, freq="T")
data = {"A": range(12), "B": range(12)}
modin_df = pd.DataFrame(data, index=index)
with pytest.warns(
FutureWarning,
match="Support for axis=1 in DataFrame.rolling is deprecated",
):
modin_df.rolling(window=3, axis=1)

0 comments on commit 77b8d36

Please sign in to comment.