Skip to content

DTA/TDA/PA use self._data instead of self.asi8 for self._ndarray #36171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 7, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
REF: _ndarray use _data instead of asi8
  • Loading branch information
jbrockmendel committed Sep 6, 2020
commit 64e665e698e54abdd76c50619cd704c47cee0475
28 changes: 13 additions & 15 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from pandas.compat import set_function_name
from pandas.compat.numpy import function as nv
from pandas.errors import AbstractMethodError, NullFrequencyError, PerformanceWarning
from pandas.util._decorators import Appender, Substitution
from pandas.util._decorators import Appender, Substitution, cache_readonly
from pandas.util._validators import validate_fillna_kwargs

from pandas.core.dtypes.common import (
Expand Down Expand Up @@ -458,9 +458,7 @@ class DatetimeLikeArrayMixin(
# ------------------------------------------------------------------
# NDArrayBackedExtensionArray compat

# TODO: make this a cache_readonly; need to get around _index_data
# kludge in libreduction
@property
@cache_readonly
def _ndarray(self) -> np.ndarray:
return self._data

Expand Down Expand Up @@ -523,7 +521,7 @@ def __array__(self, dtype=None) -> np.ndarray:
# used for Timedelta/DatetimeArray, overwritten by PeriodArray
if is_object_dtype(dtype):
return np.array(list(self), dtype=object)
return self._data
return self._ndarray

def __getitem__(self, key):
"""
Expand All @@ -533,7 +531,7 @@ def __getitem__(self, key):

if lib.is_integer(key):
# fast-path
result = self._data[key]
result = self._ndarray[key]
if self.ndim == 1:
return self._box_func(result)
return self._simple_new(result, dtype=self.dtype)
Expand All @@ -554,7 +552,7 @@ def __getitem__(self, key):
key = check_array_indexer(self, key)

freq = self._get_getitem_freq(key)
result = self._data[key]
result = self._ndarray[key]
if lib.is_scalar(result):
return self._box_func(result)
return self._simple_new(result, dtype=self.dtype, freq=freq)
Expand Down Expand Up @@ -609,7 +607,7 @@ def __setitem__(

value = self._validate_setitem_value(value)
key = check_array_indexer(self, key)
self._data[key] = value
self._ndarray[key] = value
self._maybe_clear_freq()

def _maybe_clear_freq(self):
Expand Down Expand Up @@ -660,8 +658,8 @@ def astype(self, dtype, copy=True):

def view(self, dtype=None):
if dtype is None or dtype is self.dtype:
return type(self)(self._data, dtype=self.dtype)
return self._data.view(dtype=dtype)
return type(self)(self._ndarray, dtype=self.dtype)
return self._ndarray.view(dtype=dtype)

# ------------------------------------------------------------------
# ExtensionArray Interface
Expand Down Expand Up @@ -702,7 +700,7 @@ def _from_factorized(cls, values, original):
return cls(values, dtype=original.dtype)

def _values_for_argsort(self):
return self._data
return self._ndarray

# ------------------------------------------------------------------
# Validation Methods
Expand Down Expand Up @@ -954,9 +952,9 @@ def value_counts(self, dropna=False):
from pandas import Index, Series

if dropna:
values = self[~self.isna()]._data
values = self[~self.isna()]._ndarray
else:
values = self._data
values = self._ndarray

cls = type(self)

Expand Down Expand Up @@ -1047,9 +1045,9 @@ def fillna(self, value=None, method=None, limit=None):
else:
func = missing.backfill_1d

values = self._data
values = self._ndarray
if not is_period_dtype(self.dtype):
# For PeriodArray self._data is i8, which gets copied
# For PeriodArray self._ndarray is i8, which gets copied
# by `func`. Otherwise we need to make a copy manually
# to avoid modifying `self` in-place.
values = values.copy()
Expand Down