Skip to content

Clean up timefuncs tests, fix nightly due to new errors #1322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions tests/series/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@
TimestampSeries: TypeAlias = pd.Series
OffsetSeries: TypeAlias = pd.Series

if not PD_LTE_23:
from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore # isort: skip
else:
Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef]

# Tests will use numpy 2.1 in python 3.10 or later
# From Numpy 2.1 __init__.pyi
Expand Down Expand Up @@ -3855,11 +3859,19 @@ def test_series_reindex() -> None:
def test_series_reindex_like() -> None:
s = pd.Series([1, 2, 3], index=[0, 1, 2])
other = pd.Series([1, 2], index=[1, 0])
with pytest_warns_bounded(
FutureWarning,
"the 'method' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'method'",
lower="2.3.99",
upper="3.0.99",
with (
pytest_warns_bounded(
FutureWarning,
"the 'method' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'method'",
lower="2.3.99",
upper="2.99",
),
pytest_warns_bounded(
Pandas4Warning,
"the 'method' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'method'",
lower="2.99",
upper="3.0.99",
),
):
check(
assert_type(
Expand Down
22 changes: 18 additions & 4 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@
else:
_PandasNamedTuple: TypeAlias = tuple

if not PD_LTE_23:
from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore # isort: skip
else:
Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef]

DF = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})


Expand Down Expand Up @@ -3254,10 +3259,19 @@ def test_frame_reindex_like() -> None:
# GH 84
df = pd.DataFrame({"a": [1, 2, 3]}, index=[0, 1, 2])
other = pd.DataFrame({"a": [1, 2]}, index=[1, 0])
with pytest_warns_bounded(
FutureWarning,
"the 'method' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'method'",
lower="2.3.99",
with (
pytest_warns_bounded(
FutureWarning,
"the 'method' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'method'",
lower="2.3.99",
upper="2.99",
),
pytest_warns_bounded(
Pandas4Warning,
"the 'method' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'method'",
lower="2.99",
upper="3.0.99",
),
):
check(
assert_type(
Expand Down
1 change: 1 addition & 0 deletions tests/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,7 @@ def test_datetimeindex_shift() -> None:

def test_timedeltaindex_shift() -> None:
ind = pd.date_range("1/1/2021", "1/5/2021") - pd.Timestamp("1/3/2019")
# broken on 3.0.0.dev0 as of 20250813, fix with pandas-dev/pandas/issues/62094
check(assert_type(ind.shift(1), pd.TimedeltaIndex), pd.TimedeltaIndex)


Expand Down
40 changes: 27 additions & 13 deletions tests/test_timefuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
else:
TimestampSeries: TypeAlias = pd.Series

if not PD_LTE_23:
from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore # isort: skip
else:
Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef]

from tests import np_ndarray_bool


Expand Down Expand Up @@ -95,9 +100,9 @@ def test_types_init() -> None:


def test_types_arithmetic() -> None:
ts: pd.Timestamp = pd.to_datetime("2021-03-01")
ts2: pd.Timestamp = pd.to_datetime("2021-01-01")
delta: pd.Timedelta = pd.to_timedelta("1 day")
ts = pd.to_datetime("2021-03-01")
ts2 = pd.to_datetime("2021-01-01")
delta = pd.to_timedelta("1 day")

check(assert_type(ts - ts2, pd.Timedelta), pd.Timedelta)
check(assert_type(ts + delta, pd.Timestamp), pd.Timestamp)
Expand All @@ -106,8 +111,8 @@ def test_types_arithmetic() -> None:


def test_types_comparison() -> None:
ts: pd.Timestamp = pd.to_datetime("2021-03-01")
ts2: pd.Timestamp = pd.to_datetime("2021-01-01")
ts = pd.to_datetime("2021-03-01")
ts2 = pd.to_datetime("2021-01-01")

check(assert_type(ts < ts2, bool), bool)
check(assert_type(ts > ts2, bool), bool)
Expand Down Expand Up @@ -136,7 +141,7 @@ def test_types_timestamp_series_comparisons() -> None:


def test_types_pydatetime() -> None:
ts: pd.Timestamp = pd.Timestamp("2021-03-01T12")
ts = pd.Timestamp("2021-03-01T12")

check(assert_type(ts.to_pydatetime(), dt.datetime), dt.datetime)
check(assert_type(ts.to_pydatetime(False), dt.datetime), dt.datetime)
Expand All @@ -152,9 +157,9 @@ def test_to_timedelta() -> None:


def test_timedelta_arithmetic() -> None:
td1: pd.Timedelta = pd.to_timedelta(3, "days")
td2: pd.Timedelta = pd.to_timedelta(4, "hours")
td3: pd.Timedelta = td1 + td2
td1 = pd.to_timedelta(3, "days")
td2 = pd.to_timedelta(4, "hours")
td3 = td1 + td2
check(assert_type(td1 - td2, pd.Timedelta), pd.Timedelta)
check(assert_type(td1 * 4.3, pd.Timedelta), pd.Timedelta)
check(assert_type(td3 / 10.2, pd.Timedelta), pd.Timedelta)
Expand Down Expand Up @@ -541,10 +546,19 @@ def test_series_dt_accessors() -> None:
check(assert_type(s2.dt.microseconds, "pd.Series[int]"), pd.Series, np.integer)
check(assert_type(s2.dt.nanoseconds, "pd.Series[int]"), pd.Series, np.integer)
check(assert_type(s2.dt.components, pd.DataFrame), pd.DataFrame)
with pytest_warns_bounded(
FutureWarning,
"The behavior of TimedeltaProperties.to_pytimedelta is deprecated",
lower="2.3.99",
with (
pytest_warns_bounded(
FutureWarning,
"The behavior of TimedeltaProperties.to_pytimedelta is deprecated",
lower="2.3.99",
upper="2.99",
),
pytest_warns_bounded(
Pandas4Warning, # should be Pandas4Warning but only exposed starting pandas 3.0.0
"The behavior of TimedeltaProperties.to_pytimedelta is deprecated",
lower="2.99",
upper="3.0.99",
),
):
check(assert_type(s2.dt.to_pytimedelta(), np.ndarray), np.ndarray)
check(assert_type(s2.dt.total_seconds(), "pd.Series[float]"), pd.Series, float)
Expand Down
Loading