Skip to content

Commit 3ba6bcc

Browse files
authored
CLN: tseries/offsets base tests (#49017)
1 parent c9fb018 commit 3ba6bcc

File tree

4 files changed

+263
-128
lines changed

4 files changed

+263
-128
lines changed

pandas/tests/tseries/offsets/common.py

+1-122
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,16 @@
55

66
from datetime import datetime
77

8-
from dateutil.tz.tz import tzlocal
9-
import pytest
10-
11-
from pandas._libs.tslibs import (
12-
OutOfBoundsDatetime,
13-
Timestamp,
14-
)
8+
from pandas._libs.tslibs import Timestamp
159
from pandas._libs.tslibs.offsets import (
1610
FY5253,
1711
BaseOffset,
18-
BusinessHour,
19-
CustomBusinessHour,
2012
DateOffset,
2113
FY5253Quarter,
2214
LastWeekOfMonth,
2315
Week,
2416
WeekOfMonth,
2517
)
26-
from pandas.compat import IS64
2718

2819

2920
def assert_offset_equal(offset, base, expected):
@@ -63,15 +54,6 @@ class Base:
6354
_offset: type[BaseOffset] | None = None
6455
d = Timestamp(datetime(2008, 1, 2))
6556

66-
timezones = [
67-
None,
68-
"UTC",
69-
"Asia/Tokyo",
70-
"US/Eastern",
71-
"dateutil/Asia/Tokyo",
72-
"dateutil/US/Pacific",
73-
]
74-
7557
def _get_offset(self, klass, value=1, normalize=False):
7658
# create instance from offset class
7759
if klass is FY5253:
@@ -102,106 +84,3 @@ def _get_offset(self, klass, value=1, normalize=False):
10284
else:
10385
klass = klass(value, normalize=normalize)
10486
return klass
105-
106-
def test_apply_out_of_range(self, request, tz_naive_fixture):
107-
tz = tz_naive_fixture
108-
if self._offset is None:
109-
return
110-
111-
# try to create an out-of-bounds result timestamp; if we can't create
112-
# the offset skip
113-
try:
114-
if self._offset in (BusinessHour, CustomBusinessHour):
115-
# Using 10000 in BusinessHour fails in tz check because of DST
116-
# difference
117-
offset = self._get_offset(self._offset, value=100000)
118-
else:
119-
offset = self._get_offset(self._offset, value=10000)
120-
121-
result = Timestamp("20080101") + offset
122-
assert isinstance(result, datetime)
123-
assert result.tzinfo is None
124-
125-
# Check tz is preserved
126-
t = Timestamp("20080101", tz=tz)
127-
result = t + offset
128-
assert isinstance(result, datetime)
129-
130-
if isinstance(tz, tzlocal) and not IS64:
131-
# If we hit OutOfBoundsDatetime on non-64 bit machines
132-
# we'll drop out of the try clause before the next test
133-
request.node.add_marker(
134-
pytest.mark.xfail(reason="OverflowError inside tzlocal past 2038")
135-
)
136-
assert t.tzinfo == result.tzinfo
137-
138-
except OutOfBoundsDatetime:
139-
pass
140-
except (ValueError, KeyError):
141-
# we are creating an invalid offset
142-
# so ignore
143-
pass
144-
145-
def test_offsets_compare_equal(self):
146-
# root cause of GH#456: __ne__ was not implemented
147-
if self._offset is None:
148-
return
149-
offset1 = self._offset()
150-
offset2 = self._offset()
151-
assert not offset1 != offset2
152-
assert offset1 == offset2
153-
154-
def test_rsub(self):
155-
if self._offset is None or not hasattr(self, "offset2"):
156-
# i.e. skip for TestCommon and YQM subclasses that do not have
157-
# offset2 attr
158-
return
159-
assert self.d - self.offset2 == (-self.offset2)._apply(self.d)
160-
161-
def test_radd(self):
162-
if self._offset is None or not hasattr(self, "offset2"):
163-
# i.e. skip for TestCommon and YQM subclasses that do not have
164-
# offset2 attr
165-
return
166-
assert self.d + self.offset2 == self.offset2 + self.d
167-
168-
def test_sub(self):
169-
if self._offset is None or not hasattr(self, "offset2"):
170-
# i.e. skip for TestCommon and YQM subclasses that do not have
171-
# offset2 attr
172-
return
173-
off = self.offset2
174-
msg = "Cannot subtract datetime from offset"
175-
with pytest.raises(TypeError, match=msg):
176-
off - self.d
177-
178-
assert 2 * off - off == off
179-
assert self.d - self.offset2 == self.d + self._offset(-2)
180-
assert self.d - self.offset2 == self.d - (2 * off - off)
181-
182-
def testMult1(self):
183-
if self._offset is None or not hasattr(self, "offset1"):
184-
# i.e. skip for TestCommon and YQM subclasses that do not have
185-
# offset1 attr
186-
return
187-
assert self.d + 10 * self.offset1 == self.d + self._offset(10)
188-
assert self.d + 5 * self.offset1 == self.d + self._offset(5)
189-
190-
def testMult2(self):
191-
if self._offset is None:
192-
return
193-
assert self.d + (-5 * self._offset(-10)) == self.d + self._offset(50)
194-
assert self.d + (-3 * self._offset(-2)) == self.d + self._offset(6)
195-
196-
def test_compare_str(self):
197-
# GH#23524
198-
# comparing to strings that cannot be cast to DateOffsets should
199-
# not raise for __eq__ or __ne__
200-
if self._offset is None:
201-
return
202-
off = self._get_offset(self._offset)
203-
204-
assert not off == "infer"
205-
assert off != "foo"
206-
# Note: inequalities are only implemented for Tick subclasses;
207-
# tests for this are in test_ticks

0 commit comments

Comments
 (0)