Skip to content

Commit

Permalink
FIX-modin-project#6585: avoid 'FutureWarning's in 'rolling' unless ne…
Browse files Browse the repository at this point in the history
…cessary

Signed-off-by: Anatoly Myachev <[email protected]>
  • Loading branch information
anmyachev committed Sep 18, 2023
1 parent 40216fa commit 0e42d21
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 34 deletions.
1 change: 1 addition & 0 deletions modin/pandas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2561,6 +2561,7 @@ def rolling(
else:
axis = 0

# with warnings.catch_warnings():
if win_type is not None:
from .window import Window

Expand Down
39 changes: 21 additions & 18 deletions modin/pandas/test/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,29 +629,32 @@ def test_unique():
def test_value_counts(normalize, bins, dropna):
# We sort indices for Modin and pandas result because of issue #1650
values = np.array([3, 1, 2, 3, 4, np.nan])
modin_result = sort_index_for_equal_values(
pd.value_counts(values, normalize=normalize, ascending=False), False
)
pandas_result = sort_index_for_equal_values(
pandas.value_counts(values, normalize=normalize, ascending=False), False
)
with pytest.warns(FutureWarning, match=".*pandas.value_counts is deprecated.*"):
modin_result = sort_index_for_equal_values(
pd.value_counts(values, normalize=normalize, ascending=False), False
)
pandas_result = sort_index_for_equal_values(
pandas.value_counts(values, normalize=normalize, ascending=False), False
)
df_equals(modin_result, pandas_result)

with warns_that_defaulting_to_pandas():
modin_result = sort_index_for_equal_values(
pd.value_counts(values, bins=bins, ascending=False), False
with pytest.warns(FutureWarning, match=".*pandas.value_counts is deprecated.*"):
with warns_that_defaulting_to_pandas():
modin_result = sort_index_for_equal_values(
pd.value_counts(values, bins=bins, ascending=False), False
)
pandas_result = sort_index_for_equal_values(
pandas.value_counts(values, bins=bins, ascending=False), False
)
pandas_result = sort_index_for_equal_values(
pandas.value_counts(values, bins=bins, ascending=False), False
)
df_equals(modin_result, pandas_result)

modin_result = sort_index_for_equal_values(
pd.value_counts(values, dropna=dropna, ascending=True), True
)
pandas_result = sort_index_for_equal_values(
pandas.value_counts(values, dropna=dropna, ascending=True), True
)
with pytest.warns(FutureWarning, match=".*pandas.value_counts is deprecated.*"):
modin_result = sort_index_for_equal_values(
pd.value_counts(values, dropna=dropna, ascending=True), True
)
pandas_result = sort_index_for_equal_values(
pandas.value_counts(values, dropna=dropna, ascending=True), True
)
df_equals(modin_result, pandas_result)


Expand Down
38 changes: 23 additions & 15 deletions modin/pandas/test/test_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
# ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.

import contextlib

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

import modin.pandas as pd
Expand Down Expand Up @@ -50,7 +53,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 All @@ -75,20 +78,25 @@ def test_dataframe_rolling(data, window, min_periods, axis, method, kwargs):
modin_df, pandas_df = create_test_dfs(data)
if window > len(pandas_df):
window = len(pandas_df)
eval_general(
modin_df,
pandas_df,
lambda df: getattr(
df.rolling(
window=window,
min_periods=min_periods,
win_type=None,
center=True,
axis=axis,
),
method,
)(**kwargs),
)
with pytest.warns(
FutureWarning,
match=".*Support for axis=1 in DataFrame.rolling is deprecated.*"
+ ".*Use obj.T.rolling.*",
) if axis == 1 else contextlib.nullcontext():
eval_general(
modin_df,
pandas_df,
lambda df: getattr(
df.rolling(
window=window,
min_periods=min_periods,
win_type=None,
center=True,
axis=axis,
),
method,
)(**kwargs),
)


@pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tag_prefix =
parentdir_prefix = modin-

[tool:pytest]
addopts = --disable-pytest-warnings --cov-config=setup.cfg --cov=modin --cov-append --cov-report=
addopts = --cov-config=setup.cfg --cov=modin --cov-append --cov-report=
xfail_strict=true
markers =
xfail_executions
Expand Down

0 comments on commit 0e42d21

Please sign in to comment.