Skip to content

Commit 1ebfd8a

Browse files
jbrockmendelgfyoung
authored andcommitted
BUG: Fix+test timezone-preservation in DTA.repeat (pandas-dev#24483)
Also add whatsnew for pandas-devgh-24265
1 parent 02a97c0 commit 1ebfd8a

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

doc/source/whatsnew/v0.24.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,7 @@ Datetimelike
13671367
- Bug in :attr:`Series.dt` where the cache would not update properly after an in-place operation (:issue:`24408`)
13681368
- Bug in :class:`PeriodIndex` where comparisons against an array-like object with length 1 failed to raise ``ValueError`` (:issue:`23078`)
13691369
- Bug in :meth:`DatetimeIndex.astype`, :meth:`PeriodIndex.astype` and :meth:`TimedeltaIndex.astype` ignoring the sign of the ``dtype`` for unsigned integer dtypes (:issue:`24405`).
1370+
- Fixed bug in :meth:`Series.max` with ``datetime64[ns]``-dtype failing to return ``NaT`` when nulls are present and ``skipna=False`` is passed (:issue:`24265`)
13701371

13711372
Timedelta
13721373
^^^^^^^^^

pandas/core/arrays/datetimelike.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ def repeat(self, repeats, *args, **kwargs):
699699
"""
700700
nv.validate_repeat(args, kwargs)
701701
values = self._data.repeat(repeats)
702-
return type(self)(values, dtype=self.dtype)
702+
return type(self)(values.view('i8'), dtype=self.dtype)
703703

704704
# ------------------------------------------------------------------
705705
# Null Handling

pandas/tests/arrays/test_datetimes.py

+10
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ def test_setitem_clears_freq(self):
113113
a[0] = pd.Timestamp("2000", tz="US/Central")
114114
assert a.freq is None
115115

116+
def test_repeat_preserves_tz(self):
117+
dti = pd.date_range('2000', periods=2, freq='D', tz='US/Central')
118+
arr = DatetimeArray(dti)
119+
120+
repeated = arr.repeat([1, 1])
121+
122+
# preserves tz and values, but not freq
123+
expected = DatetimeArray(arr.asi8, freq=None, tz=arr.tz)
124+
tm.assert_equal(repeated, expected)
125+
116126

117127
class TestSequenceToDT64NS(object):
118128

0 commit comments

Comments
 (0)