Skip to content

Commit 14056cf

Browse files
TomAugspurgerPingviinituutti
authored andcommitted
CLN: Remove _eadata (pandas-dev#24625)
* remove eadata
1 parent e9cbd3d commit 14056cf

File tree

8 files changed

+32
-45
lines changed

8 files changed

+32
-45
lines changed

pandas/core/indexes/datetimelike.py

+18-26
Original file line numberDiff line numberDiff line change
@@ -73,34 +73,30 @@ class DatetimeIndexOpsMixin(ExtensionOpsMixin):
7373
DatetimeLikeArrayMixin._maybe_mask_results)
7474
__iter__ = ea_passthrough(DatetimeLikeArrayMixin.__iter__)
7575

76-
@property
77-
def _eadata(self):
78-
return self._data
79-
8076
@property
8177
def freq(self):
8278
"""
8379
Return the frequency object if it is set, otherwise None.
8480
"""
85-
return self._eadata.freq
81+
return self._data.freq
8682

8783
@freq.setter
8884
def freq(self, value):
89-
# validation is handled by _eadata setter
90-
self._eadata.freq = value
85+
# validation is handled by _data setter
86+
self._data.freq = value
9187

9288
@property
9389
def freqstr(self):
9490
"""
9591
Return the frequency object as a string if it is set, otherwise None.
9692
"""
97-
return self._eadata.freqstr
93+
return self._data.freqstr
9894

9995
def unique(self, level=None):
10096
if level is not None:
10197
self._validate_index_level(level)
10298

103-
result = self._eadata.unique()
99+
result = self._data.unique()
104100

105101
# Note: if `self` is already unique, then self.unique() should share
106102
# a `freq` with self. If not already unique, then self.freq must be
@@ -113,7 +109,7 @@ def _create_comparison_method(cls, op):
113109
Create a comparison method that dispatches to ``cls.values``.
114110
"""
115111
def wrapper(self, other):
116-
result = op(self._eadata, maybe_unwrap_index(other))
112+
result = op(self._data, maybe_unwrap_index(other))
117113
return result
118114

119115
wrapper.__doc__ = op.__doc__
@@ -122,7 +118,7 @@ def wrapper(self, other):
122118

123119
@property
124120
def _ndarray_values(self):
125-
return self._eadata._ndarray_values
121+
return self._data._ndarray_values
126122

127123
# ------------------------------------------------------------------------
128124
# Abstract data attributes
@@ -131,12 +127,12 @@ def _ndarray_values(self):
131127
def values(self):
132128
# type: () -> np.ndarray
133129
# Note: PeriodArray overrides this to return an ndarray of objects.
134-
return self._eadata._data
130+
return self._data._data
135131

136132
@property
137133
@Appender(DatetimeLikeArrayMixin.asi8.__doc__)
138134
def asi8(self):
139-
return self._eadata.asi8
135+
return self._data.asi8
140136

141137
# ------------------------------------------------------------------------
142138

@@ -485,7 +481,7 @@ def _add_datetimelike_methods(cls):
485481

486482
def __add__(self, other):
487483
# dispatch to ExtensionArray implementation
488-
result = self._eadata.__add__(maybe_unwrap_index(other))
484+
result = self._data.__add__(maybe_unwrap_index(other))
489485
return wrap_arithmetic_op(self, other, result)
490486

491487
cls.__add__ = __add__
@@ -497,13 +493,13 @@ def __radd__(self, other):
497493

498494
def __sub__(self, other):
499495
# dispatch to ExtensionArray implementation
500-
result = self._eadata.__sub__(maybe_unwrap_index(other))
496+
result = self._data.__sub__(maybe_unwrap_index(other))
501497
return wrap_arithmetic_op(self, other, result)
502498

503499
cls.__sub__ = __sub__
504500

505501
def __rsub__(self, other):
506-
result = self._eadata.__rsub__(maybe_unwrap_index(other))
502+
result = self._data.__rsub__(maybe_unwrap_index(other))
507503
return wrap_arithmetic_op(self, other, result)
508504

509505
cls.__rsub__ = __rsub__
@@ -534,7 +530,6 @@ def repeat(self, repeats, axis=None):
534530
nv.validate_repeat(tuple(), dict(axis=axis))
535531
freq = self.freq if is_period_dtype(self) else None
536532
return self._shallow_copy(self.asi8.repeat(repeats), freq=freq)
537-
# TODO: dispatch to _eadata
538533

539534
@Appender(_index_shared_docs['where'] % _index_doc_kwargs)
540535
def where(self, cond, other=None):
@@ -599,10 +594,10 @@ def astype(self, dtype, copy=True):
599594
# Ensure that self.astype(self.dtype) is self
600595
return self
601596

602-
new_values = self._eadata.astype(dtype, copy=copy)
597+
new_values = self._data.astype(dtype, copy=copy)
603598

604599
# pass copy=False because any copying will be done in the
605-
# _eadata.astype call above
600+
# _data.astype call above
606601
return Index(new_values,
607602
dtype=new_values.dtype, name=self.name, copy=False)
608603

@@ -637,7 +632,7 @@ def shift(self, periods, freq=None):
637632
Index.shift : Shift values of Index.
638633
PeriodIndex.shift : Shift values of PeriodIndex.
639634
"""
640-
result = self._eadata._time_shift(periods, freq=freq)
635+
result = self._data._time_shift(periods, freq=freq)
641636
return type(self)(result, name=self.name)
642637

643638

@@ -675,9 +670,6 @@ def maybe_unwrap_index(obj):
675670
unwrapped object
676671
"""
677672
if isinstance(obj, ABCIndexClass):
678-
if isinstance(obj, DatetimeIndexOpsMixin):
679-
# i.e. PeriodIndex/DatetimeIndex/TimedeltaIndex
680-
return obj._eadata
681673
return obj._data
682674
return obj
683675

@@ -712,16 +704,16 @@ def _delegate_class(self):
712704
raise AbstractMethodError
713705

714706
def _delegate_property_get(self, name, *args, **kwargs):
715-
result = getattr(self._eadata, name)
707+
result = getattr(self._data, name)
716708
if name not in self._raw_properties:
717709
result = Index(result, name=self.name)
718710
return result
719711

720712
def _delegate_property_set(self, name, value, *args, **kwargs):
721-
setattr(self._eadata, name, value)
713+
setattr(self._data, name, value)
722714

723715
def _delegate_method(self, name, *args, **kwargs):
724-
result = operator.methodcaller(name, *args, **kwargs)(self._eadata)
716+
result = operator.methodcaller(name, *args, **kwargs)(self._data)
725717
if name not in self._raw_methods:
726718
result = Index(result, name=self.name)
727719
return result

pandas/core/indexes/datetimes.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,12 @@ def _simple_new(cls, values, name=None, freq=None, tz=None, dtype=None):
341341

342342
@property
343343
def dtype(self):
344-
return self._eadata.dtype
344+
return self._data.dtype
345345

346346
@property
347347
def tz(self):
348348
# GH 18595
349-
return self._eadata.tz
349+
return self._data.tz
350350

351351
@tz.setter
352352
def tz(self, value):
@@ -475,7 +475,7 @@ def union(self, other):
475475
if isinstance(result, DatetimeIndex):
476476
# TODO: we shouldn't be setting attributes like this;
477477
# in all the tests this equality already holds
478-
result._eadata._dtype = this.dtype
478+
result._data._dtype = this.dtype
479479
if (result.freq is None and
480480
(this.freq is not None or other.freq is not None)):
481481
result.freq = to_offset(result.inferred_freq)
@@ -508,7 +508,7 @@ def union_many(self, others):
508508
if isinstance(this, DatetimeIndex):
509509
# TODO: we shouldn't be setting attributes like this;
510510
# in all the tests this equality already holds
511-
this._eadata._dtype = dtype
511+
this._data._dtype = dtype
512512
return this
513513

514514
def _can_fast_union(self, other):
@@ -643,7 +643,7 @@ def intersection(self, other):
643643
def _get_time_micros(self):
644644
values = self.asi8
645645
if self.tz is not None and not timezones.is_utc(self.tz):
646-
values = self._eadata._local_timestamps()
646+
values = self._data._local_timestamps()
647647
return fields.get_time_micros(values)
648648

649649
def to_series(self, keep_tz=None, index=None, name=None):
@@ -1139,7 +1139,7 @@ def offset(self, value):
11391139
self.freq = value
11401140

11411141
def __getitem__(self, key):
1142-
result = self._eadata.__getitem__(key)
1142+
result = self._data.__getitem__(key)
11431143
if is_scalar(result):
11441144
return result
11451145
elif result.ndim > 1:

pandas/core/indexes/timedeltas.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def _make_wrapped_arith_op(opname):
3636
meth = getattr(TimedeltaArray, opname)
3737

3838
def method(self, other):
39-
result = meth(self._eadata, maybe_unwrap_index(other))
39+
result = meth(self._data, maybe_unwrap_index(other))
4040
return wrap_arithmetic_op(self, other, result)
4141

4242
method.__name__ = opname
@@ -307,7 +307,7 @@ def _box_func(self):
307307
return lambda x: Timedelta(x, unit='ns')
308308

309309
def __getitem__(self, key):
310-
result = self._eadata.__getitem__(key)
310+
result = self._data.__getitem__(key)
311311
if is_scalar(result):
312312
return result
313313
return type(self)(result, name=self.name)
@@ -321,7 +321,7 @@ def astype(self, dtype, copy=True):
321321
# Have to repeat the check for 'timedelta64' (not ns) dtype
322322
# so that we can return a numeric index, since pandas will return
323323
# a TimedeltaIndex when dtype='timedelta'
324-
result = self._eadata.astype(dtype, copy=copy)
324+
result = self._data.astype(dtype, copy=copy)
325325
if self.hasnans:
326326
return Index(result, name=self.name)
327327
return Index(result.astype('i8'), name=self.name)

pandas/core/series.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -477,10 +477,7 @@ def _values(self):
477477
"""
478478
Return the internal repr of this data.
479479
"""
480-
result = self._data.internal_values()
481-
if isinstance(result, DatetimeIndex):
482-
result = result._eadata
483-
return result
480+
return self._data.internal_values()
484481

485482
def _formatting_values(self):
486483
"""

pandas/tests/arithmetic/test_timedelta64.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,7 @@ def test_tdi_rmul_arraylike(self, other, box_with_array):
14751475

14761476
tdi = TimedeltaIndex(['1 Day'] * 10)
14771477
expected = timedelta_range('1 days', '10 days')
1478-
expected._eadata.freq = None
1478+
expected._data.freq = None
14791479

14801480
tdi = tm.box_expected(tdi, box)
14811481
expected = tm.box_expected(expected, xbox)

pandas/tests/arrays/test_datetimes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_from_pandas_array(self):
2121

2222
result = DatetimeArray._from_sequence(arr, freq='infer')
2323

24-
expected = pd.date_range('1970-01-01', periods=5, freq='H')._eadata
24+
expected = pd.date_range('1970-01-01', periods=5, freq='H')._data
2525
tm.assert_datetime_array_equal(result, expected)
2626

2727
def test_mismatched_timezone_raises(self):

pandas/tests/indexes/datetimes/test_astype.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,7 @@ def test_astype_category(self, tz):
318318
pd.Timestamp('2000-01-02', tz=tz)])
319319
tm.assert_index_equal(result, expected)
320320

321-
# TODO: use \._data following composition changeover
322-
result = obj._eadata.astype('category')
321+
result = obj._data.astype('category')
323322
expected = expected.values
324323
tm.assert_categorical_equal(result, expected)
325324

pandas/tests/indexes/timedeltas/test_astype.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ def test_astype_category(self):
9595
pd.Timedelta('2H')])
9696
tm.assert_index_equal(result, expected)
9797

98-
# TODO: Use \._data following composition changeover
99-
result = obj._eadata.astype('category')
98+
result = obj._data.astype('category')
10099
expected = expected.values
101100
tm.assert_categorical_equal(result, expected)
102101

0 commit comments

Comments
 (0)