Skip to content

TST/REF: share tz_localize tests, move misplaced arith #44220

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 1 commit into from
Oct 29, 2021
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
17 changes: 0 additions & 17 deletions pandas/tests/series/methods/test_tz_convert.py

This file was deleted.

25 changes: 21 additions & 4 deletions pandas/tests/series/methods/test_tz_localize.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,39 @@ def test_series_tz_localize_matching_index(self):
["foo", "invalid"],
],
)
def test_series_tz_localize_nonexistent(self, tz, method, exp):
def test_tz_localize_nonexistent(self, tz, method, exp):
# GH 8917
n = 60
dti = date_range(start="2015-03-29 02:00:00", periods=n, freq="min")
s = Series(1, dti)
ser = Series(1, index=dti)
df = ser.to_frame()

if method == "raise":

with tm.external_error_raised(pytz.NonExistentTimeError):
dti.tz_localize(tz, nonexistent=method)
with tm.external_error_raised(pytz.NonExistentTimeError):
ser.tz_localize(tz, nonexistent=method)
with tm.external_error_raised(pytz.NonExistentTimeError):
s.tz_localize(tz, nonexistent=method)
df.tz_localize(tz, nonexistent=method)

elif exp == "invalid":
with pytest.raises(ValueError, match="argument must be one of"):
dti.tz_localize(tz, nonexistent=method)
with pytest.raises(ValueError, match="argument must be one of"):
ser.tz_localize(tz, nonexistent=method)
with pytest.raises(ValueError, match="argument must be one of"):
df.tz_localize(tz, nonexistent=method)

else:
result = s.tz_localize(tz, nonexistent=method)
result = ser.tz_localize(tz, nonexistent=method)
expected = Series(1, index=DatetimeIndex([exp] * n, tz=tz))
tm.assert_series_equal(result, expected)

result = df.tz_localize(tz, nonexistent=method)
expected = expected.to_frame()
tm.assert_frame_equal(result, expected)

@pytest.mark.parametrize("tzstr", ["US/Eastern", "dateutil/US/Eastern"])
def test_series_tz_localize_empty(self, tzstr):
# GH#2248
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/series/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,16 @@ def test_series_add_tz_mismatch_converts_to_utc(self):
assert result.index.tz == pytz.UTC
tm.assert_series_equal(result, expected)

# TODO: redundant with test_series_add_tz_mismatch_converts_to_utc?
def test_series_arithmetic_mismatched_tzs_convert_to_utc(self):
base = pd.DatetimeIndex(["2011-01-01", "2011-01-02", "2011-01-03"], tz="UTC")
idx1 = base.tz_convert("Asia/Tokyo")[:2]
idx2 = base.tz_convert("US/Eastern")[1:]

res = Series([1, 2], index=idx1) + Series([1, 1], index=idx2)
expected = Series([np.nan, 3, np.nan], index=base)
tm.assert_series_equal(res, expected)

def test_series_add_aware_naive_raises(self):
rng = date_range("1/1/2011", periods=10, freq="H")
ser = Series(np.random.randn(len(rng)), index=rng)
Expand Down