Skip to content

REF: use asi8 instead of _data in PeriodArray #23416

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

Closed
wants to merge 7 commits into from
26 changes: 13 additions & 13 deletions pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,15 @@ def _concat_same_type(cls, to_concat):
freq = {x.freq for x in to_concat}
assert len(freq) == 1
freq = list(freq)[0]
values = np.concatenate([x._data for x in to_concat])
values = np.concatenate([x.asi8 for x in to_concat])
return cls(values, freq=freq)

# --------------------------------------------------------------------
# Data / Attributes
@property
def nbytes(self):
# TODO(DatetimeArray): remove
return self._data.nbytes
return self.asi8.nbytes

@cache_readonly
def dtype(self):
Expand All @@ -279,7 +279,7 @@ def dtype(self):
@property
def _ndarray_values(self):
# Ordinals
return self._data
return self.asi8

@property
def asi8(self):
Expand Down Expand Up @@ -372,7 +372,7 @@ def __setitem__(
msg = ("'value' should be a 'Period', 'NaT', or array of those. "
"Got '{}' instead.".format(type(value).__name__))
raise TypeError(msg)
self._data[key] = value
self.asi8[key] = value

def take(self, indices, allow_fill=False, fill_value=None):
if allow_fill:
Expand All @@ -391,15 +391,15 @@ def take(self, indices, allow_fill=False, fill_value=None):
msg = "'fill_value' should be a Period. Got '{}'."
raise ValueError(msg.format(fill_value))

new_values = algos.take(self._data,
new_values = algos.take(self.asi8,
indices,
allow_fill=allow_fill,
fill_value=fill_value)

return type(self)(new_values, self.freq)

def isna(self):
return self._data == iNaT
return self.asi8 == iNaT

def fillna(self, value=None, method=None, limit=None):
# TODO(#20300)
Expand All @@ -425,7 +425,7 @@ def fillna(self, value=None, method=None, limit=None):
if mask.any():
if method is not None:
func = pad_1d if method == 'pad' else backfill_1d
new_values = func(self._data, limit=limit,
new_values = func(self.asi8, limit=limit,
mask=mask)
new_values = type(self)(new_values, freq=self.freq)
else:
Expand All @@ -437,15 +437,15 @@ def fillna(self, value=None, method=None, limit=None):
return new_values

def copy(self, deep=False):
return type(self)(self._data.copy(), freq=self.freq)
return type(self)(self.asi8.copy(), freq=self.freq)

def value_counts(self, dropna=False):
from pandas import Series, PeriodIndex

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

cls = type(self)

Expand Down Expand Up @@ -638,7 +638,7 @@ def repeat(self, repeats, *args, **kwargs):
"""
# TODO(DatetimeArray): remove
nv.validate_repeat(args, kwargs)
values = self._data.repeat(repeats)
values = self.asi8.repeat(repeats)
return type(self)(values, self.freq)

# Delegation...
Expand All @@ -660,7 +660,7 @@ def astype(self, dtype, copy=True):
elif is_string_dtype(dtype) and not is_categorical_dtype(dtype):
return self._format_native_types()
elif is_integer_dtype(dtype):
values = self._data
values = self.asi8

if values.dtype != dtype:
# int32 vs. int64
Expand Down Expand Up @@ -689,7 +689,7 @@ def flags(self):
# We need this since reduction.SeriesBinGrouper uses values.flags
# Ideally, we wouldn't be passing objects down there in the first
# place.
return self._data.flags
return self.asi8.flags

# ------------------------------------------------------------------
# Arithmetic Methods
Expand Down