Skip to content

Commit c2e9dd9

Browse files
authored
TST/REF: share tz_localize tests, move misplaced arith (#44220)
1 parent 32ff424 commit c2e9dd9

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

pandas/tests/series/methods/test_tz_convert.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

pandas/tests/series/methods/test_tz_localize.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,39 @@ def test_series_tz_localize_matching_index(self):
6868
["foo", "invalid"],
6969
],
7070
)
71-
def test_series_tz_localize_nonexistent(self, tz, method, exp):
71+
def test_tz_localize_nonexistent(self, tz, method, exp):
7272
# GH 8917
7373
n = 60
7474
dti = date_range(start="2015-03-29 02:00:00", periods=n, freq="min")
75-
s = Series(1, dti)
75+
ser = Series(1, index=dti)
76+
df = ser.to_frame()
77+
7678
if method == "raise":
79+
80+
with tm.external_error_raised(pytz.NonExistentTimeError):
81+
dti.tz_localize(tz, nonexistent=method)
82+
with tm.external_error_raised(pytz.NonExistentTimeError):
83+
ser.tz_localize(tz, nonexistent=method)
7784
with tm.external_error_raised(pytz.NonExistentTimeError):
78-
s.tz_localize(tz, nonexistent=method)
85+
df.tz_localize(tz, nonexistent=method)
86+
7987
elif exp == "invalid":
8088
with pytest.raises(ValueError, match="argument must be one of"):
8189
dti.tz_localize(tz, nonexistent=method)
90+
with pytest.raises(ValueError, match="argument must be one of"):
91+
ser.tz_localize(tz, nonexistent=method)
92+
with pytest.raises(ValueError, match="argument must be one of"):
93+
df.tz_localize(tz, nonexistent=method)
94+
8295
else:
83-
result = s.tz_localize(tz, nonexistent=method)
96+
result = ser.tz_localize(tz, nonexistent=method)
8497
expected = Series(1, index=DatetimeIndex([exp] * n, tz=tz))
8598
tm.assert_series_equal(result, expected)
8699

100+
result = df.tz_localize(tz, nonexistent=method)
101+
expected = expected.to_frame()
102+
tm.assert_frame_equal(result, expected)
103+
87104
@pytest.mark.parametrize("tzstr", ["US/Eastern", "dateutil/US/Eastern"])
88105
def test_series_tz_localize_empty(self, tzstr):
89106
# GH#2248

pandas/tests/series/test_arithmetic.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,16 @@ def test_series_add_tz_mismatch_converts_to_utc(self):
714714
assert result.index.tz == pytz.UTC
715715
tm.assert_series_equal(result, expected)
716716

717+
# TODO: redundant with test_series_add_tz_mismatch_converts_to_utc?
718+
def test_series_arithmetic_mismatched_tzs_convert_to_utc(self):
719+
base = pd.DatetimeIndex(["2011-01-01", "2011-01-02", "2011-01-03"], tz="UTC")
720+
idx1 = base.tz_convert("Asia/Tokyo")[:2]
721+
idx2 = base.tz_convert("US/Eastern")[1:]
722+
723+
res = Series([1, 2], index=idx1) + Series([1, 1], index=idx2)
724+
expected = Series([np.nan, 3, np.nan], index=base)
725+
tm.assert_series_equal(res, expected)
726+
717727
def test_series_add_aware_naive_raises(self):
718728
rng = date_range("1/1/2011", periods=10, freq="H")
719729
ser = Series(np.random.randn(len(rng)), index=rng)

0 commit comments

Comments
 (0)