Skip to content

Commit

Permalink
FIX-modin-project#6624: Add FutureWarnings for first/last/bool (m…
Browse files Browse the repository at this point in the history
…odin-project#6625)

Signed-off-by: Anatoly Myachev <anatoly.myachev@intel.com>
  • Loading branch information
anmyachev committed Oct 9, 2023
1 parent 3fe050d commit b608ea0
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 11 deletions.
16 changes: 16 additions & 0 deletions modin/pandas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,11 @@ def bool(self): # noqa: RT01, D200
"""
Return the bool of a single element `BasePandasDataset`.
"""
warnings.warn(
f"{type(self).__name__}.bool is now deprecated and will be removed "
+ "in future version of pandas",
FutureWarning,
)
shape = self.shape
if shape != (1,) and shape != (1, 1):
raise ValueError(
Expand Down Expand Up @@ -1757,6 +1762,11 @@ def first(self, offset): # noqa: PR01, RT01, D200
"""
Select initial periods of time series data based on a date offset.
"""
warnings.warn(
"first is deprecated and will be removed in a future version. "
+ "Please create a mask and filter using `.loc` instead",
FutureWarning,
)
return self._create_or_update_from_compiler(
self._query_compiler.first(offset=to_offset(offset))
)
Expand Down Expand Up @@ -1913,6 +1923,12 @@ def last(self, offset): # noqa: PR01, RT01, D200
"""
Select final periods of time series data based on a date offset.
"""
warnings.warn(
"last is deprecated and will be removed in a future version. "
+ "Please create a mask and filter using `.loc` instead",
FutureWarning,
)

return self._create_or_update_from_compiler(
self._query_compiler.last(offset=to_offset(offset))
)
Expand Down
31 changes: 25 additions & 6 deletions modin/pandas/test/dataframe/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,19 @@
# Our configuration in pytest.ini requires that we explicitly catch all
# instances of defaulting to pandas, but some test modules, like this one,
# have too many such instances.
pytestmark = pytest.mark.filterwarnings(default_to_pandas_ignore_string)
pytestmark = [
pytest.mark.filterwarnings(default_to_pandas_ignore_string),
# IGNORE FUTUREWARNINGS MARKS TO CLEANUP OUTPUT
pytest.mark.filterwarnings(
"ignore:.*bool is now deprecated and will be removed:FutureWarning"
),
pytest.mark.filterwarnings(
"ignore:first is deprecated and will be removed:FutureWarning"
),
pytest.mark.filterwarnings(
"ignore:last is deprecated and will be removed:FutureWarning"
),
]


@pytest.mark.parametrize(
Expand Down Expand Up @@ -188,9 +200,12 @@ def test_bfill(data):
def test_bool(data):
modin_df = pd.DataFrame(data)

with pytest.raises(ValueError):
modin_df.bool()
modin_df.__bool__()
with pytest.warns(
FutureWarning, match="bool is now deprecated and will be removed"
):
with pytest.raises(ValueError):
modin_df.bool()
modin_df.__bool__()

single_bool_pandas_df = pandas.DataFrame([True])
single_bool_modin_df = pd.DataFrame([True])
Expand Down Expand Up @@ -446,7 +461,9 @@ def test_first():
pandas_df = pandas.DataFrame(
{"A": list(range(400)), "B": list(range(400))}, index=i
)
df_equals(modin_df.first("3D"), pandas_df.first("3D"))
with pytest.warns(FutureWarning, match="first is deprecated and will be removed"):
modin_result = modin_df.first("3D")
df_equals(modin_result, pandas_df.first("3D"))
df_equals(modin_df.first("20D"), pandas_df.first("20D"))


Expand Down Expand Up @@ -522,7 +539,9 @@ def test_last():
pandas_df = pandas.DataFrame(
{"A": list(range(400)), "B": list(range(400))}, index=pandas_index
)
df_equals(modin_df.last("3D"), pandas_df.last("3D"))
with pytest.warns(FutureWarning, match="last is deprecated and will be removed"):
modin_result = modin_df.last("3D")
df_equals(modin_result, pandas_df.last("3D"))
df_equals(modin_df.last("20D"), pandas_df.last("20D"))


Expand Down
29 changes: 24 additions & 5 deletions modin/pandas/test/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,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),
# IGNORE FUTUREWARNINGS MARKS TO CLEANUP OUTPUT
pytest.mark.filterwarnings(
"ignore:.*bool is now deprecated and will be removed:FutureWarning"
),
pytest.mark.filterwarnings(
"ignore:first is deprecated and will be removed:FutureWarning"
),
pytest.mark.filterwarnings(
"ignore:last is deprecated and will be removed:FutureWarning"
),
]

NPartitions.put(4)

Expand Down Expand Up @@ -1237,8 +1249,11 @@ def test_bfill(data):
def test_bool(data):
modin_series, _ = create_test_series(data)

with pytest.raises(ValueError):
modin_series.bool()
with pytest.warns(
FutureWarning, match="bool is now deprecated and will be removed"
):
with pytest.raises(ValueError):
modin_series.bool()
with pytest.raises(ValueError):
modin_series.__bool__()

Expand Down Expand Up @@ -2034,7 +2049,9 @@ def test_first():
i = pd.date_range("2010-04-09", periods=400, freq="2D")
modin_series = pd.Series(list(range(400)), index=i)
pandas_series = pandas.Series(list(range(400)), index=i)
df_equals(modin_series.first("3D"), pandas_series.first("3D"))
with pytest.warns(FutureWarning, match="first is deprecated and will be removed"):
modin_result = modin_series.first("3D")
df_equals(modin_result, pandas_series.first("3D"))
df_equals(modin_series.first("20D"), pandas_series.first("20D"))


Expand Down Expand Up @@ -2277,7 +2294,9 @@ def test_last():
pandas_index = pandas.date_range("2010-04-09", periods=400, freq="2D")
modin_series = pd.Series(list(range(400)), index=modin_index)
pandas_series = pandas.Series(list(range(400)), index=pandas_index)
df_equals(modin_series.last("3D"), pandas_series.last("3D"))
with pytest.warns(FutureWarning, match="last is deprecated and will be removed"):
modin_result = modin_series.last("3D")
df_equals(modin_result, pandas_series.last("3D"))
df_equals(modin_series.last("20D"), pandas_series.last("20D"))


Expand Down

0 comments on commit b608ea0

Please sign in to comment.