diff --git a/pandas/tests/series/methods/test_tz_convert.py b/pandas/tests/series/methods/test_tz_convert.py deleted file mode 100644 index d826dde646cfb..0000000000000 --- a/pandas/tests/series/methods/test_tz_convert.py +++ /dev/null @@ -1,17 +0,0 @@ -import numpy as np - -from pandas import ( - DatetimeIndex, - Series, -) -import pandas._testing as tm - - -class TestTZConvert: - def test_series_tz_convert_to_utc(self): - base = 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) - tm.assert_series_equal(res, Series([np.nan, 3, np.nan], index=base)) diff --git a/pandas/tests/series/methods/test_tz_localize.py b/pandas/tests/series/methods/test_tz_localize.py index a32c1fb8df502..b8a1ea55db4fe 100644 --- a/pandas/tests/series/methods/test_tz_localize.py +++ b/pandas/tests/series/methods/test_tz_localize.py @@ -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 diff --git a/pandas/tests/series/test_arithmetic.py b/pandas/tests/series/test_arithmetic.py index 103130484f0e1..e4f9366be8dd7 100644 --- a/pandas/tests/series/test_arithmetic.py +++ b/pandas/tests/series/test_arithmetic.py @@ -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)