56
56
else :
57
57
TimestampSeries : TypeAlias = pd .Series
58
58
59
+ if not PD_LTE_23 :
60
+ from pandas .errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore # isort: skip
61
+ else :
62
+ Pandas4Warning : TypeAlias = FutureWarning # type: ignore[no-redef]
63
+
59
64
from tests import np_ndarray_bool
60
65
61
66
@@ -95,9 +100,9 @@ def test_types_init() -> None:
95
100
96
101
97
102
def test_types_arithmetic () -> None :
98
- ts : pd . Timestamp = pd .to_datetime ("2021-03-01" )
99
- ts2 : pd . Timestamp = pd .to_datetime ("2021-01-01" )
100
- delta : pd . Timedelta = pd .to_timedelta ("1 day" )
103
+ ts = pd .to_datetime ("2021-03-01" )
104
+ ts2 = pd .to_datetime ("2021-01-01" )
105
+ delta = pd .to_timedelta ("1 day" )
101
106
102
107
check (assert_type (ts - ts2 , pd .Timedelta ), pd .Timedelta )
103
108
check (assert_type (ts + delta , pd .Timestamp ), pd .Timestamp )
@@ -106,8 +111,8 @@ def test_types_arithmetic() -> None:
106
111
107
112
108
113
def test_types_comparison () -> None :
109
- ts : pd . Timestamp = pd .to_datetime ("2021-03-01" )
110
- ts2 : pd . Timestamp = pd .to_datetime ("2021-01-01" )
114
+ ts = pd .to_datetime ("2021-03-01" )
115
+ ts2 = pd .to_datetime ("2021-01-01" )
111
116
112
117
check (assert_type (ts < ts2 , bool ), bool )
113
118
check (assert_type (ts > ts2 , bool ), bool )
@@ -136,7 +141,7 @@ def test_types_timestamp_series_comparisons() -> None:
136
141
137
142
138
143
def test_types_pydatetime () -> None :
139
- ts : pd . Timestamp = pd .Timestamp ("2021-03-01T12" )
144
+ ts = pd .Timestamp ("2021-03-01T12" )
140
145
141
146
check (assert_type (ts .to_pydatetime (), dt .datetime ), dt .datetime )
142
147
check (assert_type (ts .to_pydatetime (False ), dt .datetime ), dt .datetime )
@@ -152,9 +157,9 @@ def test_to_timedelta() -> None:
152
157
153
158
154
159
def test_timedelta_arithmetic () -> None :
155
- td1 : pd . Timedelta = pd .to_timedelta (3 , "days" )
156
- td2 : pd . Timedelta = pd .to_timedelta (4 , "hours" )
157
- td3 : pd . Timedelta = td1 + td2
160
+ td1 = pd .to_timedelta (3 , "days" )
161
+ td2 = pd .to_timedelta (4 , "hours" )
162
+ td3 = td1 + td2
158
163
check (assert_type (td1 - td2 , pd .Timedelta ), pd .Timedelta )
159
164
check (assert_type (td1 * 4.3 , pd .Timedelta ), pd .Timedelta )
160
165
check (assert_type (td3 / 10.2 , pd .Timedelta ), pd .Timedelta )
@@ -541,10 +546,19 @@ def test_series_dt_accessors() -> None:
541
546
check (assert_type (s2 .dt .microseconds , "pd.Series[int]" ), pd .Series , np .integer )
542
547
check (assert_type (s2 .dt .nanoseconds , "pd.Series[int]" ), pd .Series , np .integer )
543
548
check (assert_type (s2 .dt .components , pd .DataFrame ), pd .DataFrame )
544
- with pytest_warns_bounded (
545
- FutureWarning ,
546
- "The behavior of TimedeltaProperties.to_pytimedelta is deprecated" ,
547
- lower = "2.3.99" ,
549
+ with (
550
+ pytest_warns_bounded (
551
+ FutureWarning ,
552
+ "The behavior of TimedeltaProperties.to_pytimedelta is deprecated" ,
553
+ lower = "2.3.99" ,
554
+ upper = "2.99" ,
555
+ ),
556
+ pytest_warns_bounded (
557
+ Pandas4Warning , # should be Pandas4Warning but only exposed starting pandas 3.0.0
558
+ "The behavior of TimedeltaProperties.to_pytimedelta is deprecated" ,
559
+ lower = "2.99" ,
560
+ upper = "3.0.99" ,
561
+ ),
548
562
):
549
563
check (assert_type (s2 .dt .to_pytimedelta (), np .ndarray ), np .ndarray )
550
564
check (assert_type (s2 .dt .total_seconds (), "pd.Series[float]" ), pd .Series , float )
0 commit comments