From 8c68e2abda6d639fd4eda6fe54a576cc7bec1b94 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Fri, 16 Nov 2018 15:00:12 +0100 Subject: [PATCH] fixes for changes in master --- pandas/core/arrays/datetimes.py | 9 --------- pandas/core/indexes/datetimelike.py | 6 +++++- pandas/tests/arrays/test_datetimelike.py | 7 +++---- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index bacbece718e9a..5531d6fa9ca08 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -386,15 +386,6 @@ def _resolution(self): # ---------------------------------------------------------------- # Array-Like / EA-Interface Methods - def __array__(self, dtype=None): - if is_object_dtype(dtype): - return np.array(list(self), dtype=object) - elif is_int64_dtype(dtype): - return self.asi8 - - # TODO: warn that conversion may be lossy? - return self._data.view(np.ndarray) # follow Index.__array__ - def __iter__(self): """ Return an iterator over the boxed values diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index a8719731426a0..3db0ca8b7b001 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -230,7 +230,11 @@ class DatetimeIndexOpsMixin(DatetimeLikeArrayMixin): def __array__(self, dtype=None): # TODO properly dispatch to EA - return Index.__array__(self) + if is_period_dtype(self): + return self._data.__array__(dtype=dtype) + if is_object_dtype(dtype): + return np.array(list(self), dtype=object) + return self._data def equals(self, other): """ diff --git a/pandas/tests/arrays/test_datetimelike.py b/pandas/tests/arrays/test_datetimelike.py index 0d1e53226da14..f5c294a41683d 100644 --- a/pandas/tests/arrays/test_datetimelike.py +++ b/pandas/tests/arrays/test_datetimelike.py @@ -168,7 +168,6 @@ def test_array2(self, datetime_index): tm.assert_numpy_array_equal(result, expected) def test_array_i8_dtype(self, tz_naive_fixture): - # GH#23524 tz = tz_naive_fixture dti = pd.date_range('2016-01-01', periods=3, tz=tz) arr = DatetimeArray(dti) @@ -180,10 +179,10 @@ def test_array_i8_dtype(self, tz_naive_fixture): result = np.array(arr, dtype=np.int64) tm.assert_numpy_array_equal(result, expected) - # check that we are not making copies when setting copy=False + # check that we are still making copies when setting copy=False result = np.array(arr, dtype='i8', copy=False) - assert result.base is expected.base - assert result.base is not None + assert result.base is not expected.base + assert result.base is None def test_from_dti(self, tz_naive_fixture): tz = tz_naive_fixture