Skip to content

Commit e0f978d

Browse files
mroeschkejreback
authored andcommitted
TST: Clean old timezone issues PT2 (#21612)
1 parent 73ab162 commit e0f978d

File tree

10 files changed

+99
-10
lines changed

10 files changed

+99
-10
lines changed

doc/source/whatsnew/v0.24.0.txt

+14-10
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,6 @@ Datetimelike
164164
^^^^^^^^^^^^
165165

166166
- Fixed bug where two :class:`DateOffset` objects with different ``normalize`` attributes could evaluate as equal (:issue:`21404`)
167-
- Bug in :class:`Index` with ``datetime64[ns, tz]`` dtype that did not localize integer data correctly (:issue:`20964`)
168-
- Bug in :meth:`DatetimeIndex.shift` where an ``AssertionError`` would raise when shifting across DST (:issue:`8616`)
169-
- Bug in :class:`Timestamp` constructor where passing an invalid timezone offset designator (``Z``) would not raise a ``ValueError``(:issue:`8910`)
170-
- Bug in :meth:`Timestamp.replace` where replacing at a DST boundary would retain an incorrect offset (:issue:`7825`)
171-
- Bug in :meth:`DatetimeIndex.reindex` when reindexing a tz-naive and tz-aware :class:`DatetimeIndex` (:issue:`8306`)
172-
- Bug in :meth:`DatetimeIndex.resample` when downsampling across a DST boundary (:issue:`8531`)
173167

174168
Timedelta
175169
^^^^^^^^^
@@ -181,9 +175,15 @@ Timedelta
181175
Timezones
182176
^^^^^^^^^
183177

184-
-
185-
-
186-
-
178+
- Bug in :meth:`DatetimeIndex.shift` where an ``AssertionError`` would raise when shifting across DST (:issue:`8616`)
179+
- Bug in :class:`Timestamp` constructor where passing an invalid timezone offset designator (``Z``) would not raise a ``ValueError``(:issue:`8910`)
180+
- Bug in :meth:`Timestamp.replace` where replacing at a DST boundary would retain an incorrect offset (:issue:`7825`)
181+
- Bug in :meth:`Series.replace` with ``datetime64[ns, tz]`` data when replacing ``NaT`` (:issue:`11792`)
182+
- Bug in :class:`Timestamp` when passing different string date formats with a timezone offset would produce different timezone offsets (:issue:`12064`)
183+
- Bug when comparing a tz-naive :class:`Timestamp` to a tz-aware :class:`DatetimeIndex` which would coerce the :class:`DatetimeIndex` to tz-naive (:issue:`12601`)
184+
- Bug in :meth:`Series.truncate` with a tz-aware :class:`DatetimeIndex` which would cause a core dump (:issue:`9243`)
185+
- Bug in :class:`Series` constructor which would coerce tz-aware and tz-naive :class:`Timestamp`s to tz-aware (:issue:`13051`)
186+
- Bug in :class:`Index` with ``datetime64[ns, tz]`` dtype that did not localize integer data correctly (:issue:`20964`)
187187

188188
Offsets
189189
^^^^^^^
@@ -217,7 +217,10 @@ Indexing
217217

218218
- The traceback from a ``KeyError`` when asking ``.loc`` for a single missing label is now shorter and more clear (:issue:`21557`)
219219
- When ``.ix`` is asked for a missing integer label in a :class:`MultiIndex` with a first level of integer type, it now raises a ``KeyError`` - consistently with the case of a flat :class:`Int64Index` - rather than falling back to positional indexing (:issue:`21593`)
220-
-
220+
- Bug in :meth:`DatetimeIndex.reindex` when reindexing a tz-naive and tz-aware :class:`DatetimeIndex` (:issue:`8306`)
221+
- Bug in :class:`DataFrame` when setting values with ``.loc`` and a timezone aware :class:`DatetimeIndex` (:issue:`11365`)
222+
- Bug when indexing :class:`DatetimeIndex` with nanosecond resolution dates and timezones (:issue:`11679`)
223+
221224
-
222225

223226
MultiIndex
@@ -245,6 +248,7 @@ Groupby/Resample/Rolling
245248
^^^^^^^^^^^^^^^^^^^^^^^^
246249

247250
- Bug in :func:`pandas.core.groupby.GroupBy.first` and :func:`pandas.core.groupby.GroupBy.last` with ``as_index=False`` leading to the loss of timezone information (:issue:`15884`)
251+
- Bug in :meth:`DatetimeIndex.resample` when downsampling across a DST boundary (:issue:`8531`)
248252
-
249253
-
250254

pandas/conftest.py

+17
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,20 @@ def mock():
320320
return importlib.import_module("unittest.mock")
321321
else:
322322
return pytest.importorskip("mock")
323+
324+
325+
@pytest.fixture(params=['__eq__', '__ne__', '__le__',
326+
'__lt__', '__ge__', '__gt__'])
327+
def all_compare_operators(request):
328+
"""
329+
Fixture for dunder names for common compare operations
330+
331+
* >=
332+
* >
333+
* ==
334+
* !=
335+
* <
336+
* <=
337+
"""
338+
339+
return request.param

pandas/tests/frame/test_indexing.py

+10
Original file line numberDiff line numberDiff line change
@@ -2248,6 +2248,16 @@ def test_setitem_datetimelike_with_inference(self):
22482248
index=list('ABCDEFGH'))
22492249
assert_series_equal(result, expected)
22502250

2251+
@pytest.mark.parametrize('idxer', ['var', ['var']])
2252+
def test_setitem_datetimeindex_tz(self, idxer, tz_naive_fixture):
2253+
# GH 11365
2254+
tz = tz_naive_fixture
2255+
idx = date_range(start='2015-07-12', periods=3, freq='H', tz=tz)
2256+
expected = DataFrame(1.2, index=idx, columns=['var'])
2257+
result = DataFrame(index=idx, columns=['var'])
2258+
result.loc[:, idxer] = expected
2259+
tm.assert_frame_equal(result, expected)
2260+
22512261
def test_at_time_between_time_datetimeindex(self):
22522262
index = date_range("2012-01-01", "2012-01-05", freq='30min')
22532263
df = DataFrame(randn(len(index), 5), index=index)

pandas/tests/indexes/datetimes/test_arithmetic.py

+4
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ def test_comparison_tzawareness_compat(self, op):
276276
with pytest.raises(TypeError):
277277
op(dz, ts)
278278

279+
# GH 12601: Check comparison against Timestamps and DatetimeIndex
280+
with pytest.raises(TypeError):
281+
op(ts, dz)
282+
279283
@pytest.mark.parametrize('op', [operator.eq, operator.ne,
280284
operator.gt, operator.ge,
281285
operator.lt, operator.le])

pandas/tests/indexes/datetimes/test_date_range.py

+9
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,15 @@ def test_construct_over_dst(self):
292292
freq='H', tz='US/Pacific')
293293
tm.assert_index_equal(result, expected)
294294

295+
def test_construct_with_different_start_end_string_format(self):
296+
# GH 12064
297+
result = date_range('2013-01-01 00:00:00+09:00',
298+
'2013/01/01 02:00:00+09:00', freq='H')
299+
expected = DatetimeIndex([Timestamp('2013-01-01 00:00:00+09:00'),
300+
Timestamp('2013-01-01 01:00:00+09:00'),
301+
Timestamp('2013-01-01 02:00:00+09:00')])
302+
tm.assert_index_equal(result, expected)
303+
295304

296305
class TestGenRangeGeneration(object):
297306

pandas/tests/indexing/test_datetime.py

+14
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,17 @@ def test_series_partial_set_period(self):
252252
check_stacklevel=False):
253253
result = ser.loc[keys]
254254
tm.assert_series_equal(result, exp)
255+
256+
def test_nanosecond_getitem_setitem_with_tz(self):
257+
# GH 11679
258+
data = ['2016-06-28 08:30:00.123456789']
259+
index = pd.DatetimeIndex(data, dtype='datetime64[ns, America/Chicago]')
260+
df = DataFrame({'a': [10]}, index=index)
261+
result = df.loc[df.index[0]]
262+
expected = Series(10, index=['a'], name=df.index[0])
263+
tm.assert_series_equal(result, expected)
264+
265+
result = df.copy()
266+
result.loc[df.index[0], 'a'] = -1
267+
expected = DataFrame(-1, index=index, columns=['a'])
268+
tm.assert_frame_equal(result, expected)

pandas/tests/scalar/timestamp/test_timestamp.py

+8
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,14 @@ def test_construct_timestamp_near_dst(self, offset):
542542
result = Timestamp(expected, tz='Europe/Helsinki')
543543
assert result == expected
544544

545+
@pytest.mark.parametrize('arg', [
546+
'2013/01/01 00:00:00+09:00', '2013-01-01 00:00:00+09:00'])
547+
def test_construct_with_different_string_format(self, arg):
548+
# GH 12064
549+
result = Timestamp(arg)
550+
expected = Timestamp(datetime(2013, 1, 1), tz=pytz.FixedOffset(540))
551+
assert result == expected
552+
545553

546554
class TestTimestamp(object):
547555

pandas/tests/series/test_constructors.py

+8
Original file line numberDiff line numberDiff line change
@@ -1185,3 +1185,11 @@ def test_constructor_range_dtype(self, dtype):
11851185
expected = Series([0, 1, 2, 3, 4], dtype=dtype or 'int64')
11861186
result = Series(range(5), dtype=dtype)
11871187
tm.assert_series_equal(result, expected)
1188+
1189+
def test_constructor_tz_mixed_data(self):
1190+
# GH 13051
1191+
dt_list = [Timestamp('2016-05-01 02:03:37'),
1192+
Timestamp('2016-04-30 19:03:37-0700', tz='US/Pacific')]
1193+
result = Series(dt_list)
1194+
expected = Series(dt_list, dtype=object)
1195+
tm.assert_series_equal(result, expected)

pandas/tests/series/test_replace.py

+7
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ def test_replace_gh5319(self):
108108
pd.Timestamp('20120101'))
109109
tm.assert_series_equal(result, expected)
110110

111+
# GH 11792: Test with replacing NaT in a list with tz data
112+
ts = pd.Timestamp('2015/01/01', tz='UTC')
113+
s = pd.Series([pd.NaT, pd.Timestamp('2015/01/01', tz='UTC')])
114+
result = s.replace([np.nan, pd.NaT], pd.Timestamp.min)
115+
expected = pd.Series([pd.Timestamp.min, ts], dtype=object)
116+
tm.assert_series_equal(expected, result)
117+
111118
def test_replace_with_single_list(self):
112119
ser = pd.Series([0, 1, 2, 3, 4])
113120
result = ser.replace([1, 2, 3])

pandas/tests/series/test_timezones.py

+8
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,11 @@ def test_getitem_pydatetime_tz(self, tzstr):
300300
dt = datetime(2012, 12, 24, 17, 0)
301301
time_datetime = tslib._localize_pydatetime(dt, tz)
302302
assert ts[time_pandas] == ts[time_datetime]
303+
304+
def test_series_truncate_datetimeindex_tz(self):
305+
# GH 9243
306+
idx = date_range('4/1/2005', '4/30/2005', freq='D', tz='US/Pacific')
307+
s = Series(range(len(idx)), index=idx)
308+
result = s.truncate(datetime(2005, 4, 2), datetime(2005, 4, 4))
309+
expected = Series([1, 2, 3], index=idx[1:4])
310+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)