Skip to content

TST: avoid DST transitions when testing DateTimeIndex roundtrip #24736

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
Feb 2, 2019
Merged
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
19 changes: 7 additions & 12 deletions pandas/tests/indexes/datetimes/test_timezones.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,24 +434,19 @@ def test_dti_tz_localize_utc_conversion(self, tz):
with pytest.raises(pytz.NonExistentTimeError):
rng.tz_localize(tz)

@pytest.mark.parametrize('idx', [
date_range(start='2014-01-01', end='2014-12-31', freq='M'),
date_range(start='2014-01-01', end='2014-12-31', freq='D'),
date_range(start='2014-01-01', end='2014-03-01', freq='H'),
date_range(start='2014-08-01', end='2014-10-31', freq='T')
])
def test_dti_tz_localize_roundtrip(self, tz_aware_fixture, idx):
def test_dti_tz_localize_roundtrip(self, tz_aware_fixture):
# note: this tz tests that a tz-naive index can be localized
# and de-localized successfully, when there are no DST transitions
# in the range.
idx = date_range(start='2014-06-01', end='2014-08-30', freq='15T')
tz = tz_aware_fixture
localized = idx.tz_localize(tz)
expected = date_range(start=idx[0], end=idx[-1], freq=idx.freq,
tz=tz)
tm.assert_index_equal(localized, expected)
# cant localize a tz-aware object
with pytest.raises(TypeError):
localized.tz_localize(tz)

reset = localized.tz_localize(None)
tm.assert_index_equal(reset, idx)
assert reset.tzinfo is None
tm.assert_index_equal(reset, idx)

def test_dti_tz_localize_naive(self):
rng = date_range('1/1/2011', periods=100, freq='H')
Expand Down