From 6b01b7d4ae74f84f5c2a4e1f7b9ccda1bb1e2a91 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Sat, 29 Dec 2018 08:08:38 -0800 Subject: [PATCH 1/4] Fix+test timezone-preservation in DTA.repeat --- pandas/core/arrays/datetimelike.py | 2 +- pandas/tests/arrays/test_datetimes.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index a6f603d16affe..791cc6f0562b4 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -698,7 +698,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)._simple_new(values, dtype=self.dtype) # ------------------------------------------------------------------ # Null Handling diff --git a/pandas/tests/arrays/test_datetimes.py b/pandas/tests/arrays/test_datetimes.py index 80c87665236d3..44c81437cfdae 100644 --- a/pandas/tests/arrays/test_datetimes.py +++ b/pandas/tests/arrays/test_datetimes.py @@ -90,3 +90,10 @@ def test_setitem_clears_freq(self): tz='US/Central')) 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]) + tm.assert_equal(arr, repeated) From a9655192a859e6ae10170aba0335ede5cade80e3 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Sat, 29 Dec 2018 08:11:08 -0800 Subject: [PATCH 2/4] added whatsnew for #24265 --- doc/source/whatsnew/v0.24.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index affef80571fce..a84fd118061bc 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -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 ^^^^^^^^^ From 4741f2dee322e2e8e2b2012e62d0cabc02de1fa2 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Sat, 29 Dec 2018 09:31:55 -0800 Subject: [PATCH 3/4] dont go through simple_new --- pandas/core/arrays/datetimelike.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index 791cc6f0562b4..f927ec5a1f8e5 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -698,7 +698,7 @@ def repeat(self, repeats, *args, **kwargs): """ nv.validate_repeat(args, kwargs) values = self._data.repeat(repeats) - return type(self)._simple_new(values, dtype=self.dtype) + return type(self)(values.view('i8'), dtype=self.dtype) # ------------------------------------------------------------------ # Null Handling From 2a7a5f1ccf3cd9ae04e4edb213d8434a0fde1a83 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Sat, 29 Dec 2018 10:45:51 -0800 Subject: [PATCH 4/4] Fix test --- pandas/tests/arrays/test_datetimes.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pandas/tests/arrays/test_datetimes.py b/pandas/tests/arrays/test_datetimes.py index 7d3703999ab2f..be9b9fe70eede 100644 --- a/pandas/tests/arrays/test_datetimes.py +++ b/pandas/tests/arrays/test_datetimes.py @@ -118,7 +118,10 @@ def test_repeat_preserves_tz(self): arr = DatetimeArray(dti) repeated = arr.repeat([1, 1]) - tm.assert_equal(arr, repeated) + + # preserves tz and values, but not freq + expected = DatetimeArray(arr.asi8, freq=None, tz=arr.tz) + tm.assert_equal(repeated, expected) class TestSequenceToDT64NS(object):