Skip to content

Commit

Permalink
BUG: Fix+test timezone-preservation in DTA.repeat (pandas-dev#24483)
Browse files Browse the repository at this point in the history
Also add whatsnew for pandas-devgh-24265
  • Loading branch information
jbrockmendel authored and Pingviinituutti committed Feb 28, 2019
1 parent f56966a commit 9a83cd7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.24.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,7 @@ Datetimelike
- Bug in :attr:`Series.dt` where the cache would not update properly after an in-place operation (:issue:`24408`)
- Bug in :class:`PeriodIndex` where comparisons against an array-like object with length 1 failed to raise ``ValueError`` (:issue:`23078`)
- Bug in :meth:`DatetimeIndex.astype`, :meth:`PeriodIndex.astype` and :meth:`TimedeltaIndex.astype` ignoring the sign of the ``dtype`` for unsigned integer dtypes (:issue:`24405`).
- 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`)

Timedelta
^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ def repeat(self, repeats, *args, **kwargs):
"""
nv.validate_repeat(args, kwargs)
values = self._data.repeat(repeats)
return type(self)(values, dtype=self.dtype)
return type(self)(values.view('i8'), dtype=self.dtype)

# ------------------------------------------------------------------
# Null Handling
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/arrays/test_datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ def test_setitem_clears_freq(self):
a[0] = pd.Timestamp("2000", tz="US/Central")
assert a.freq is None

def test_repeat_preserves_tz(self):
dti = pd.date_range('2000', periods=2, freq='D', tz='US/Central')
arr = DatetimeArray(dti)

repeated = arr.repeat([1, 1])

# preserves tz and values, but not freq
expected = DatetimeArray(arr.asi8, freq=None, tz=arr.tz)
tm.assert_equal(repeated, expected)


class TestSequenceToDT64NS(object):

Expand Down

0 comments on commit 9a83cd7

Please sign in to comment.