Skip to content

TST: Add unit tests for older timezone issues #21491

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 6 commits into from
Jun 18, 2018
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
5 changes: 5 additions & 0 deletions doc/source/whatsnew/v0.23.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ Bug Fixes
**Timezones**
- Bug in :class:`Timestamp` and :class:`DatetimeIndex` where passing a :class:`Timestamp` localized after a DST transition would return a datetime before the DST transition (:issue:`20854`)
- Bug in comparing :class:`DataFrame`s with tz-aware :class:`DatetimeIndex` columns with a DST transition that raised a ``KeyError`` (:issue:`19970`)
- Bug in :meth:`DatetimeIndex.shift` where an ``AssertionError`` would raise when shifting across DST (:issue:`8616`)
- Bug in :class:`Timestamp` constructor where passing an invalid timezone offset designator (``Z``) would not raise a ``ValueError``(:issue:`8910`)
- Bug in :meth:`Timestamp.replace` where replacing at a DST boundary would retain an incorrect offset (:issue:`7825`)
- Bug in :meth:`DatetimeIndex.reindex` when reindexing a tz-naive and tz-aware :class:`DatetimeIndex` (:issue:`8306`)
- Bug in :meth:`DatetimeIndex.resample` when downsampling across a DST boundary (:issue:`8531`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should put those in 0.23.2, as we didn't fix them in there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see #21407

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These all didn't get fixed by #21407 per se. These issues may have been fixed by other prior PR's in other releases. What should our whatsnew policy be on cleaning up these older issues that have already been fixed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if it is needed to list them at all. But if we list them, I would rather add them eg to the 0.24.0 (or 0.23.0) file than to the 0.23.2 file. For those bug fix releases, the list is much shorter and it is often more valuable to actually look which bugs/regressions have been fixed compared to 0.23.0 (in the 0.24.0 or 0.23.0 files the list is huge anyways ...)


**Other**

Expand Down
24 changes: 23 additions & 1 deletion pandas/tests/indexes/datetimes/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import operator

import pytest

import pytz
import numpy as np

import pandas as pd
Expand Down Expand Up @@ -476,6 +476,28 @@ def test_dti_shift_localized(self, tzstr):
result = dr_tz.shift(1, '10T')
assert result.tz == dr_tz.tz

def test_dti_shift_across_dst(self):
# GH 8616
idx = date_range('2013-11-03', tz='America/Chicago',
periods=7, freq='H')
s = Series(index=idx[:-1])
result = s.shift(freq='H')
expected = Series(index=idx[1:])
tm.assert_series_equal(result, expected)

@pytest.mark.parametrize('shift, result_time', [
[0, '2014-11-14 00:00:00'],
[-1, '2014-11-13 23:00:00'],
[1, '2014-11-14 01:00:00']])
def test_dti_shift_near_midnight(self, shift, result_time):
# GH 8616
dt = datetime(2014, 11, 14, 0)
dt_est = pytz.timezone('EST').localize(dt)
s = Series(data=[1], index=[dt_est])
result = s.shift(shift, freq='H')
expected = Series(1, index=DatetimeIndex([result_time], tz='EST'))
tm.assert_series_equal(result, expected)

# -------------------------------------------------------------
# Binary operations DatetimeIndex and timedelta-like

Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/scalar/timestamp/test_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,12 @@ def test_constructor_nanosecond(self, result):
expected = expected + Timedelta(nanoseconds=1)
assert result == expected

@pytest.mark.parametrize('z', ['Z0', 'Z00'])
def test_constructor_invalid_Z0_isostring(self, z):
# GH 8910
with pytest.raises(ValueError):
Timestamp('2014-11-02 01:00{}'.format(z))

@pytest.mark.parametrize('arg', ['year', 'month', 'day', 'hour', 'minute',
'second', 'microsecond', 'nanosecond'])
def test_invalid_date_kwarg_with_string_input(self, arg):
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/scalar/timestamp/test_unary_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,13 @@ def test_replace_across_dst(self, tz, normalize):
ts2b = normalize(ts2)
assert ts2 == ts2b

def test_replace_dst_border(self):
# Gh 7825
t = Timestamp('2013-11-3', tz='America/Chicago')
result = t.replace(hour=3)
expected = Timestamp('2013-11-3 03:00:00', tz='America/Chicago')
assert result == expected

# --------------------------------------------------------------

@td.skip_if_windows
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/series/indexing/test_alter_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,15 @@ def test_reindex_fill_value():
assert_series_equal(result, expected)


def test_reindex_datetimeindexes_tz_naive_and_aware():
# GH 8306
idx = date_range('20131101', tz='America/Chicago', periods=7)
newidx = date_range('20131103', periods=10, freq='H')
s = Series(range(7), index=idx)
with pytest.raises(TypeError):
s.reindex(newidx, method='ffill')


def test_rename():
# GH 17407
s = Series(range(1, 6), index=pd.Index(range(2, 7), name='IntIndex'))
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/test_resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -2084,6 +2084,17 @@ def test_resample_dst_anchor(self):
freq='D', tz='Europe/Paris')),
'D Frequency')

def test_downsample_across_dst(self):
# GH 8531
tz = pytz.timezone('Europe/Berlin')
dt = datetime(2014, 10, 26)
dates = date_range(tz.localize(dt), periods=4, freq='2H')
result = Series(5, index=dates).resample('H').mean()
expected = Series([5., np.nan] * 3 + [5.],
index=date_range(tz.localize(dt), periods=7,
freq='H'))
tm.assert_series_equal(result, expected)

def test_resample_with_nat(self):
# GH 13020
index = DatetimeIndex([pd.NaT,
Expand Down