Skip to content

Commit

Permalink
Use Pandas40DeprecationWarning for new deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
Aloqeely committed May 21, 2024
1 parent ede0885 commit c96551c
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 42 deletions.
5 changes: 2 additions & 3 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@
Pandas40DeprecationWarning,
find_stack_level,
)

from pandas.util._validators import (
check_dtype_backend,
validate_ascending,
Expand Down Expand Up @@ -2568,15 +2567,15 @@ def to_json(
warnings.warn(
"The default 'epoch' date format is deprecated and will be removed "
"in a future version, please use 'iso' date format instead.",
FutureWarning,
Pandas40DeprecationWarning,
stacklevel=find_stack_level(),
)
elif date_format == "epoch":
# GH#57063
warnings.warn(
"'epoch' date format is deprecated and will be removed in a future "
"version, please use 'iso' date format instead.",
FutureWarning,
Pandas40DeprecationWarning,
stacklevel=find_stack_level(),
)

Expand Down
9 changes: 6 additions & 3 deletions pandas/core/indexes/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
import numpy as np

from pandas._libs import lib
from pandas.util._exceptions import find_stack_level
from pandas.util._exceptions import (
Pandas40DeprecationWarning,
find_stack_level,
)

from pandas.core.dtypes.common import (
is_integer_dtype,
Expand Down Expand Up @@ -218,7 +221,7 @@ def to_pytimedelta(self):
"in a future version this will return a Series containing python "
"datetime.timedelta objects instead of an ndarray. To retain the "
"old behavior, call `np.array` on the result",
FutureWarning,
Pandas40DeprecationWarning,
stacklevel=find_stack_level(),
)
return cast(ArrowExtensionArray, self._parent.array)._dt_to_pytimedelta()
Expand Down Expand Up @@ -479,7 +482,7 @@ def to_pytimedelta(self) -> np.ndarray:
"in a future version this will return a Series containing python "
"datetime.timedelta objects instead of an ndarray. To retain the "
"old behavior, call `np.array` on the result",
FutureWarning,
Pandas40DeprecationWarning,
stacklevel=find_stack_level(),
)
return self._get_values().to_pytimedelta()
Expand Down
1 change: 0 additions & 1 deletion pandas/core/window/expanding.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,6 @@ def kurt(self, numeric_only: bool = False):
aggregation_description="quantile",
agg_method="quantile",
)

def quantile(
self,
q: float,
Expand Down
1 change: 0 additions & 1 deletion pandas/core/window/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -2553,7 +2553,6 @@ def kurt(self, numeric_only: bool = False):
aggregation_description="quantile",
agg_method="quantile",
)

def quantile(
self,
q: float,
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/extension/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
pa_version_under13p0,
pa_version_under14p0,
)
from pandas.util._exceptions import Pandas40DeprecationWarning
import pandas.util._test_decorators as td

from pandas.core.dtypes.dtypes import (
Expand Down Expand Up @@ -2862,14 +2863,14 @@ def test_dt_to_pytimedelta():
ser = pd.Series(data, dtype=ArrowDtype(pa.duration("ns")))

msg = "The behavior of ArrowTemporalProperties.to_pytimedelta is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg):
result = ser.dt.to_pytimedelta()
expected = np.array(data, dtype=object)
tm.assert_numpy_array_equal(result, expected)
assert all(type(res) is timedelta for res in result)

msg = "The behavior of TimedeltaProperties.to_pytimedelta is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg):
expected = ser.astype("timedelta64[ns]").dt.to_pytimedelta()
tm.assert_numpy_array_equal(result, expected)

Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/frame/methods/test_reindex_like.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import numpy as np
import pytest

from pandas.util._exceptions import Pandas40DeprecationWarning

from pandas import DataFrame
import pandas._testing as tm

Expand All @@ -22,10 +24,10 @@ def test_reindex_like(self, float_frame):
def test_reindex_like_methods(self, method, expected_values):
df = DataFrame({"x": list(range(5))})

with tm.assert_produces_warning(FutureWarning):
with tm.assert_produces_warning(Pandas40DeprecationWarning):
result = df.reindex_like(df, method=method, tolerance=0)
tm.assert_frame_equal(df, result)
with tm.assert_produces_warning(FutureWarning):
with tm.assert_produces_warning(Pandas40DeprecationWarning):
result = df.reindex_like(df, method=method, tolerance=[0, 0, 0, 0])
tm.assert_frame_equal(df, result)

Expand Down
6 changes: 5 additions & 1 deletion pandas/tests/io/json/test_json_table_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import numpy as np
import pytest

from pandas.util._exceptions import Pandas40DeprecationWarning

from pandas.core.dtypes.dtypes import (
CategoricalDtype,
DatetimeTZDtype,
Expand Down Expand Up @@ -460,7 +462,9 @@ def test_date_format_raises(self, df_table):
"version, please use 'iso' date format instead."
)
with pytest.raises(ValueError, match=error_msg):
with tm.assert_produces_warning(FutureWarning, match=warning_msg):
with tm.assert_produces_warning(
Pandas40DeprecationWarning, match=warning_msg
):
df_table.to_json(orient="table", date_format="epoch")

# others work
Expand Down
43 changes: 22 additions & 21 deletions pandas/tests/io/json/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from pandas._config import using_pyarrow_string_dtype

from pandas.compat import IS64
from pandas.util._exceptions import Pandas40DeprecationWarning
import pandas.util._test_decorators as td

import pandas as pd
Expand Down Expand Up @@ -142,7 +143,7 @@ def test_frame_non_unique_columns(self, orient, data):
"in a future version, please use 'iso' date format instead."
)
if df.iloc[:, 0].dtype == "datetime64[ns]":
expected_warning = FutureWarning
expected_warning = Pandas40DeprecationWarning

with tm.assert_produces_warning(expected_warning, match=msg):
result = read_json(
Expand Down Expand Up @@ -774,7 +775,7 @@ def test_series_with_dtype_datetime(self, dtype, expected):
"The default 'epoch' date format is deprecated and will be removed "
"in a future version, please use 'iso' date format instead."
)
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg):
data = StringIO(s.to_json())
result = read_json(data, typ="series", dtype=dtype)
tm.assert_series_equal(result, expected)
Expand Down Expand Up @@ -825,13 +826,13 @@ def test_convert_dates(self, datetime_series, datetime_frame):
"The default 'epoch' date format is deprecated and will be removed "
"in a future version, please use 'iso' date format instead."
)
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg):
json = StringIO(df.to_json())
result = read_json(json)
tm.assert_frame_equal(result, df)

df["foo"] = 1.0
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg):
json = StringIO(df.to_json(date_unit="ns"))

result = read_json(json, convert_dates=False)
Expand All @@ -842,7 +843,7 @@ def test_convert_dates(self, datetime_series, datetime_frame):

# series
ts = Series(Timestamp("20130101").as_unit("ns"), index=datetime_series.index)
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg):
json = StringIO(ts.to_json())
result = read_json(json, typ="series")
tm.assert_series_equal(result, ts)
Expand All @@ -860,7 +861,7 @@ def test_date_index_and_values(self, date_format, as_object, date_typ):
expected_warning = None
if date_format == "epoch":
expected = '{"1577836800000":1577836800000,"null":null}'
expected_warning = FutureWarning
expected_warning = Pandas40DeprecationWarning
else:
expected = (
'{"2020-01-01T00:00:00.000":"2020-01-01T00:00:00.000","null":null}'
Expand Down Expand Up @@ -973,7 +974,7 @@ def test_date_unit(self, unit, datetime_frame):
"'epoch' date format is deprecated and will be removed in a future "
"version, please use 'iso' date format instead."
)
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg):
json = df.to_json(date_format="epoch", date_unit=unit)

# force date unit
Expand All @@ -993,13 +994,13 @@ def test_date_unit(self, unit, datetime_frame):
DataFrame(
{"A": ["a", "b", "c"], "B": pd.to_timedelta(np.arange(3), unit="D")}
),
FutureWarning,
Pandas40DeprecationWarning,
),
(
DataFrame(
{"A": pd.to_datetime(["2020-01-01", "2020-02-01", "2020-03-01"])}
),
FutureWarning,
Pandas40DeprecationWarning,
),
],
)
Expand Down Expand Up @@ -1085,7 +1086,7 @@ def test_doc_example(self):
"The default 'epoch' date format is deprecated and will be removed "
"in a future version, please use 'iso' date format instead."
)
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg):
json = StringIO(dfj2.to_json())
result = read_json(json, dtype={"ints": np.int64, "bools": np.bool_})
tm.assert_frame_equal(result, result)
Expand Down Expand Up @@ -1127,20 +1128,20 @@ def test_timedelta(self):
"The default 'epoch' date format is deprecated and will be removed "
"in a future version, please use 'iso' date format instead."
)
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg):
result = read_json(StringIO(ser.to_json()), typ="series").apply(converter)
tm.assert_series_equal(result, ser)

ser = Series([timedelta(23), timedelta(seconds=5)], index=Index([0, 1]))
assert ser.dtype == "timedelta64[ns]"
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg):
result = read_json(StringIO(ser.to_json()), typ="series").apply(converter)
tm.assert_series_equal(result, ser)

frame = DataFrame([timedelta(23), timedelta(seconds=5)])
assert frame[0].dtype == "timedelta64[ns]"

with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg):
json = frame.to_json()
tm.assert_frame_equal(frame, read_json(StringIO(json)).apply(converter))

Expand All @@ -1156,7 +1157,7 @@ def test_timedelta2(self):
"The default 'epoch' date format is deprecated and will be removed "
"in a future version, please use 'iso' date format instead."
)
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg):
data = StringIO(frame.to_json(date_unit="ns"))
result = read_json(data)
result["a"] = pd.to_timedelta(result.a, unit="ns")
Expand Down Expand Up @@ -1191,7 +1192,7 @@ def test_timedelta_to_json(self, as_object, date_format, timedelta_typ):
'{"P1DT0H0M0S":"P1DT0H0M0S","P2DT0H0M0S":"P2DT0H0M0S","null":null}'
)
else:
expected_warning = FutureWarning
expected_warning = Pandas40DeprecationWarning
expected = '{"86400000":86400000,"172800000":172800000,"null":null}'

if as_object:
Expand All @@ -1210,7 +1211,7 @@ def test_timedelta_to_json(self, as_object, date_format, timedelta_typ):
def test_timedelta_to_json_fractional_precision(self, as_object, timedelta_typ):
data = [timedelta_typ(milliseconds=42)]
ser = Series(data, index=data)
warn = FutureWarning
warn = Pandas40DeprecationWarning
if as_object:
ser = ser.astype(object)
warn = None
Expand Down Expand Up @@ -1306,13 +1307,13 @@ def test_datetime_tz(self):
"The default 'epoch' date format is deprecated and will be removed "
"in a future version, please use 'iso' date format instead."
)
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg):
expected = df_naive.to_json()
assert expected == df.to_json()

stz = Series(tz_range)
s_naive = Series(tz_naive)
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg):
assert stz.to_json() == s_naive.to_json()

def test_sparse(self):
Expand Down Expand Up @@ -1582,7 +1583,7 @@ def test_to_json_from_json_columns_dtypes(self, orient):
"The default 'epoch' date format is deprecated and will be removed "
"in a future version, please use 'iso' date format instead."
)
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg):
dfjson = expected.to_json(orient=orient)

result = read_json(
Expand Down Expand Up @@ -1776,7 +1777,7 @@ def test_timedelta_as_label(self, date_format, key):

expected_warning = None
if date_format == "epoch":
expected_warning = FutureWarning
expected_warning = Pandas40DeprecationWarning

msg = (
"'epoch' date format is deprecated and will be removed in a future "
Expand Down Expand Up @@ -2021,7 +2022,7 @@ def test_json_pandas_nulls(self, nulls_fixture, request):
"in a future version, please use 'iso' date format instead."
)
if nulls_fixture is pd.NaT:
expected_warning = FutureWarning
expected_warning = Pandas40DeprecationWarning

with tm.assert_produces_warning(expected_warning, match=msg):
result = DataFrame([[nulls_fixture]]).to_json()
Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/io/test_gcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import numpy as np
import pytest

from pandas.util._exceptions import Pandas40DeprecationWarning

from pandas import (
DataFrame,
Index,
Expand Down Expand Up @@ -82,7 +84,7 @@ def test_to_read_gcs(gcs_buffer, format, monkeypatch, capsys):
"The default 'epoch' date format is deprecated and will be removed "
"in a future version, please use 'iso' date format instead."
)
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg):
df1.to_json(path)
df2 = read_json(path, convert_dates=["dt"])
elif format == "parquet":
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/resample/test_datetime_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pandas._libs import lib
from pandas._typing import DatetimeNaTType
from pandas.compat import is_platform_windows
from pandas.util._exceptions import Pandas40DeprecationWarning
import pandas.util._test_decorators as td

import pandas as pd
Expand Down Expand Up @@ -1300,7 +1301,7 @@ def test_resample_consistency(unit):

s10 = s.reindex(index=i10, method="bfill")
s10_2 = s.reindex(index=i10, method="bfill", limit=2)
with tm.assert_produces_warning(FutureWarning):
with tm.assert_produces_warning(Pandas40DeprecationWarning):
rl = s.reindex_like(s10, method="bfill", limit=2)
r10_2 = s.resample("10Min").bfill(limit=2)
r10 = s.resample("10Min").bfill()
Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/series/accessors/test_cat_accessor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import numpy as np
import pytest

from pandas.util._exceptions import Pandas40DeprecationWarning

from pandas import (
Categorical,
DataFrame,
Expand Down Expand Up @@ -202,7 +204,7 @@ def test_dt_accessor_api_for_categorical(self, idx):
warn_cls.append(UserWarning)
elif func == "to_pytimedelta":
# GH 57463
warn_cls.append(FutureWarning)
warn_cls.append(Pandas40DeprecationWarning)
if warn_cls:
warn_cls = tuple(warn_cls)
else:
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/series/accessors/test_dt_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import pytz

from pandas._libs.tslibs.timezones import maybe_get_tz
from pandas.util._exceptions import Pandas40DeprecationWarning

from pandas.core.dtypes.common import (
is_integer_dtype,
Expand Down Expand Up @@ -193,7 +194,7 @@ def test_dt_namespace_accessor_timedelta(self):
tm.assert_index_equal(result.index, ser.index)

msg = "The behavior of TimedeltaProperties.to_pytimedelta is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg):
result = ser.dt.to_pytimedelta()
assert isinstance(result, np.ndarray)
assert result.dtype == object
Expand Down
Loading

0 comments on commit c96551c

Please sign in to comment.