Skip to content

Rename DatetimeArray and TimedeltaArray #24601

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 4 commits into from
Jan 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions pandas/arrays/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from pandas.core.arrays import (
IntervalArray, PeriodArray, Categorical, SparseArray, IntegerArray,
PandasArray,
DatetimeArrayMixin as DatetimeArray,
TimedeltaArrayMixin as TimedeltaArray,
DatetimeArray,
TimedeltaArray,
)


Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
ExtensionOpsMixin,
ExtensionScalarOpsMixin)
from .categorical import Categorical # noqa
from .datetimes import DatetimeArrayMixin # noqa
from .datetimes import DatetimeArray # noqa
from .interval import IntervalArray # noqa
from .period import PeriodArray, period_array # noqa
from .timedeltas import TimedeltaArrayMixin # noqa
from .timedeltas import TimedeltaArray # noqa
from .integer import ( # noqa
IntegerArray, integer_array)
from .sparse import SparseArray # noqa
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/arrays/array_.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ def array(data, # type: Sequence[object]
"""
from pandas.core.arrays import (
period_array, ExtensionArray, IntervalArray, PandasArray,
DatetimeArrayMixin,
TimedeltaArrayMixin,
DatetimeArray,
TimedeltaArray,
)
from pandas.core.internals.arrays import extract_array

Expand Down Expand Up @@ -228,14 +228,14 @@ def array(data, # type: Sequence[object]
elif inferred_dtype.startswith('datetime'):
# datetime, datetime64
try:
return DatetimeArrayMixin._from_sequence(data, copy=copy)
return DatetimeArray._from_sequence(data, copy=copy)
except ValueError:
# Mixture of timezones, fall back to PandasArray
pass

elif inferred_dtype.startswith('timedelta'):
# timedelta, timedelta64
return TimedeltaArrayMixin._from_sequence(data, copy=copy)
return TimedeltaArray._from_sequence(data, copy=copy)

# TODO(BooleanArray): handle this type

Expand Down
12 changes: 6 additions & 6 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,9 +1228,9 @@ def __add__(self, other):
return NotImplemented

if is_timedelta64_dtype(result) and isinstance(result, np.ndarray):
from pandas.core.arrays import TimedeltaArrayMixin
from pandas.core.arrays import TimedeltaArray
# TODO: infer freq?
return TimedeltaArrayMixin(result)
return TimedeltaArray(result)
return result

def __radd__(self, other):
Expand Down Expand Up @@ -1295,9 +1295,9 @@ def __sub__(self, other):
return NotImplemented

if is_timedelta64_dtype(result) and isinstance(result, np.ndarray):
from pandas.core.arrays import TimedeltaArrayMixin
from pandas.core.arrays import TimedeltaArray
# TODO: infer freq?
return TimedeltaArrayMixin(result)
return TimedeltaArray(result)
return result

def __rsub__(self, other):
Expand All @@ -1306,8 +1306,8 @@ def __rsub__(self, other):
# we need to wrap in DatetimeArray/Index and flip the operation
if not isinstance(other, DatetimeLikeArrayMixin):
# Avoid down-casting DatetimeIndex
from pandas.core.arrays import DatetimeArrayMixin
other = DatetimeArrayMixin(other)
from pandas.core.arrays import DatetimeArray
other = DatetimeArray(other)
return other - self
elif (is_datetime64_any_dtype(self) and hasattr(other, 'dtype') and
not is_datetime64_any_dtype(other)):
Expand Down
16 changes: 8 additions & 8 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def wrapper(self, other):
except ValueError:
other = np.array(other, dtype=np.object_)
elif not isinstance(other, (np.ndarray, ABCIndexClass, ABCSeries,
DatetimeArrayMixin)):
DatetimeArray)):
# Following Timestamp convention, __eq__ is all-False
# and __ne__ is all True, others raise TypeError.
return ops.invalid_comparison(self, other, op)
Expand Down Expand Up @@ -176,9 +176,9 @@ def wrapper(self, other):
return compat.set_function_name(wrapper, opname, cls)


class DatetimeArrayMixin(dtl.DatetimeLikeArrayMixin,
dtl.TimelikeOps,
dtl.DatelikeOps):
class DatetimeArray(dtl.DatetimeLikeArrayMixin,
dtl.TimelikeOps,
dtl.DatelikeOps):
"""
Pandas ExtensionArray for tz-naive or tz-aware datetime data.

Expand Down Expand Up @@ -718,7 +718,7 @@ def _add_delta(self, delta):
-------
result : DatetimeArray
"""
new_values = super(DatetimeArrayMixin, self)._add_delta(delta)
new_values = super(DatetimeArray, self)._add_delta(delta)
return type(self)._from_sequence(new_values, tz=self.tz, freq='infer')

# -----------------------------------------------------------------
Expand Down Expand Up @@ -1135,10 +1135,10 @@ def to_perioddelta(self, freq):
TimedeltaArray/Index
"""
# TODO: consider privatizing (discussion in GH#23113)
from pandas.core.arrays.timedeltas import TimedeltaArrayMixin
from pandas.core.arrays.timedeltas import TimedeltaArray
i8delta = self.asi8 - self.to_period(freq).to_timestamp().asi8
m8delta = i8delta.view('m8[ns]')
return TimedeltaArrayMixin(m8delta)
return TimedeltaArray(m8delta)

# -----------------------------------------------------------------
# Properties - Vectorized Timestamp Properties/Methods
Expand Down Expand Up @@ -1610,7 +1610,7 @@ def to_julian_date(self):
) / 24.0)


DatetimeArrayMixin._add_comparison_ops()
DatetimeArray._add_comparison_ops()


# -------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def to_timestamp(self, freq=None, how='start'):
-------
DatetimeArray/Index
"""
from pandas.core.arrays import DatetimeArrayMixin
from pandas.core.arrays import DatetimeArray

how = libperiod._validate_end_alias(how)

Expand All @@ -351,7 +351,7 @@ def to_timestamp(self, freq=None, how='start'):
new_data = self.asfreq(freq, how=how)

new_data = libperiod.periodarr_to_dt64arr(new_data.asi8, base)
return DatetimeArrayMixin._from_sequence(new_data, freq='infer')
return DatetimeArray._from_sequence(new_data, freq='infer')

# --------------------------------------------------------------------
# Array-like / EA-Interface Methods
Expand Down
20 changes: 10 additions & 10 deletions pandas/core/arrays/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def wrapper(self, other):
return compat.set_function_name(wrapper, opname, cls)


class TimedeltaArrayMixin(dtl.DatetimeLikeArrayMixin, dtl.TimelikeOps):
class TimedeltaArray(dtl.DatetimeLikeArrayMixin, dtl.TimelikeOps):
_typ = "timedeltaarray"
_scalar_type = Timedelta
__array_priority__ = 1000
Expand Down Expand Up @@ -348,7 +348,7 @@ def _add_delta(self, delta):
-------
result : TimedeltaArray
"""
new_values = super(TimedeltaArrayMixin, self)._add_delta(delta)
new_values = super(TimedeltaArray, self)._add_delta(delta)
return type(self)._from_sequence(new_values, freq='infer')

def _add_datetime_arraylike(self, other):
Expand All @@ -357,38 +357,38 @@ def _add_datetime_arraylike(self, other):
"""
if isinstance(other, np.ndarray):
# At this point we have already checked that dtype is datetime64
from pandas.core.arrays import DatetimeArrayMixin
other = DatetimeArrayMixin(other)
from pandas.core.arrays import DatetimeArray
other = DatetimeArray(other)

# defer to implementation in DatetimeArray
return other + self

def _add_datetimelike_scalar(self, other):
# adding a timedeltaindex to a datetimelike
from pandas.core.arrays import DatetimeArrayMixin
from pandas.core.arrays import DatetimeArray

assert other is not NaT
other = Timestamp(other)
if other is NaT:
# In this case we specifically interpret NaT as a datetime, not
# the timedelta interpretation we would get by returning self + NaT
result = self.asi8.view('m8[ms]') + NaT.to_datetime64()
return DatetimeArrayMixin(result)
return DatetimeArray(result)

i8 = self.asi8
result = checked_add_with_arr(i8, other.value,
arr_mask=self._isnan)
result = self._maybe_mask_results(result)
dtype = DatetimeTZDtype(tz=other.tz) if other.tz else _NS_DTYPE
return DatetimeArrayMixin(result, dtype=dtype, freq=self.freq)
return DatetimeArray(result, dtype=dtype, freq=self.freq)

def _addsub_offset_array(self, other, op):
# Add or subtract Array-like of DateOffset objects
try:
# TimedeltaIndex can only operate with a subset of DateOffset
# subclasses. Incompatible classes will raise AttributeError,
# which we re-raise as TypeError
return super(TimedeltaArrayMixin, self)._addsub_offset_array(
return super(TimedeltaArray, self)._addsub_offset_array(
other, op
)
except AttributeError:
Expand Down Expand Up @@ -813,7 +813,7 @@ def f(x):
return result


TimedeltaArrayMixin._add_comparison_ops()
TimedeltaArray._add_comparison_ops()


# ---------------------------------------------------------------------
Expand Down Expand Up @@ -860,7 +860,7 @@ def sequence_to_td64ns(data, copy=False, unit="ns", errors="raise"):
data = np.array(data, copy=False)
elif isinstance(data, ABCSeries):
data = data._values
elif isinstance(data, (ABCTimedeltaIndex, TimedeltaArrayMixin)):
elif isinstance(data, (ABCTimedeltaIndex, TimedeltaArray)):
inferred_freq = data.freq
data = data._data

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,8 @@ def construct_array_type(cls):
-------
type
"""
from pandas.core.arrays import DatetimeArrayMixin
return DatetimeArrayMixin
from pandas.core.arrays import DatetimeArray
return DatetimeArray

@classmethod
def construct_from_string(cls, string):
Expand Down
4 changes: 1 addition & 3 deletions pandas/core/indexes/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

from pandas.core.accessor import PandasDelegate, delegate_names
from pandas.core.algorithms import take_1d
from pandas.core.arrays import (
DatetimeArrayMixin as DatetimeArray, PeriodArray,
TimedeltaArrayMixin as TimedeltaArray)
from pandas.core.arrays import DatetimeArray, PeriodArray, TimedeltaArray
from pandas.core.base import NoNewAttributesMixin, PandasObject
from pandas.core.indexes.datetimes import DatetimeIndex
from pandas.core.indexes.timedeltas import TimedeltaIndex
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from pandas.core.accessor import delegate_names
from pandas.core.arrays.datetimes import (
DatetimeArrayMixin as DatetimeArray, _to_M8, validate_tz_from_dtype)
DatetimeArray, _to_M8, validate_tz_from_dtype)
from pandas.core.base import _shared_docs
import pandas.core.common as com
from pandas.core.indexes.base import Index
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

from pandas.core.accessor import delegate_names
from pandas.core.arrays import datetimelike as dtl
from pandas.core.arrays.timedeltas import (
TimedeltaArrayMixin as TimedeltaArray, _is_convertible_to_td)
from pandas.core.arrays.timedeltas import TimedeltaArray, _is_convertible_to_td
from pandas.core.base import _shared_docs
import pandas.core.common as com
from pandas.core.indexes.base import Index, _index_shared_docs
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@

import pandas.core.algorithms as algos
from pandas.core.arrays import (
Categorical, DatetimeArrayMixin as DatetimeArray, ExtensionArray,
TimedeltaArrayMixin as TimedeltaArray)
Categorical, DatetimeArray, ExtensionArray, TimedeltaArray)
from pandas.core.base import PandasObject
import pandas.core.common as com
from pandas.core.indexes.datetimes import DatetimeIndex
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,7 @@ def unique(self):

>>> pd.Series([pd.Timestamp('2016-01-01', tz='US/Eastern')
... for _ in range(3)]).unique()
<DatetimeArrayMixin>
<DatetimeArray>
['2016-01-01 00:00:00-05:00']
Length: 1, dtype: datetime64[ns, US/Eastern]

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/tools/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def _convert_listlike_datetimes(arg, box, format, name=None, tz=None,
- ndarray of Timestamps if box=False
"""
from pandas import DatetimeIndex
from pandas.core.arrays import DatetimeArrayMixin as DatetimeArray
from pandas.core.arrays import DatetimeArray
from pandas.core.arrays.datetimes import (
maybe_convert_dtype, objects_to_datetime64ns)

Expand Down
12 changes: 6 additions & 6 deletions pandas/tests/arithmetic/test_datetime64.py
Original file line number Diff line number Diff line change
Expand Up @@ -1981,15 +1981,15 @@ def test_dti_sub_tdi(self, tz_naive_fixture):
result = dti - tdi
tm.assert_index_equal(result, expected)

msg = 'cannot subtract .*TimedeltaArrayMixin'
msg = 'cannot subtract .*TimedeltaArray'
with pytest.raises(TypeError, match=msg):
tdi - dti

# sub with timedelta64 array
result = dti - tdi.values
tm.assert_index_equal(result, expected)

msg = 'cannot subtract DatetimeArrayMixin from'
msg = 'cannot subtract DatetimeArray from'
with pytest.raises(TypeError, match=msg):
tdi.values - dti

Expand All @@ -2005,7 +2005,7 @@ def test_dti_isub_tdi(self, tz_naive_fixture):
result -= tdi
tm.assert_index_equal(result, expected)

msg = 'cannot subtract .* from a TimedeltaArrayMixin'
msg = 'cannot subtract .* from a TimedeltaArray'
with pytest.raises(TypeError, match=msg):
tdi -= dti

Expand All @@ -2016,7 +2016,7 @@ def test_dti_isub_tdi(self, tz_naive_fixture):

msg = '|'.join(['cannot perform __neg__ with this index type:',
'ufunc subtract cannot use operands with types',
'cannot subtract DatetimeArrayMixin from'])
'cannot subtract DatetimeArray from'])
with pytest.raises(TypeError, match=msg):
tdi.values -= dti

Expand All @@ -2036,9 +2036,9 @@ def test_dti_isub_tdi(self, tz_naive_fixture):
def test_add_datetimelike_and_dti(self, addend, tz):
# GH#9631
dti = DatetimeIndex(['2011-01-01', '2011-01-02']).tz_localize(tz)
msg = ('cannot add DatetimeArrayMixin and {0}'
msg = ('cannot add DatetimeArray and {0}'
.format(type(addend).__name__)).replace('DatetimeIndex',
'DatetimeArrayMixin')
'DatetimeArray')
with pytest.raises(TypeError, match=msg):
dti + addend
with pytest.raises(TypeError, match=msg):
Expand Down
4 changes: 1 addition & 3 deletions pandas/tests/arrays/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import pandas.compat as compat

import pandas as pd
from pandas.core.arrays import (
DatetimeArrayMixin as DatetimeArray, PeriodArray,
TimedeltaArrayMixin as TimedeltaArray)
from pandas.core.arrays import DatetimeArray, PeriodArray, TimedeltaArray
import pandas.util.testing as tm


Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/arrays/test_datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pandas.core.dtypes.dtypes import DatetimeTZDtype

import pandas as pd
from pandas.core.arrays import DatetimeArrayMixin as DatetimeArray
from pandas.core.arrays import DatetimeArray
from pandas.core.arrays.datetimes import sequence_to_dt64ns
import pandas.util.testing as tm

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/arrays/test_timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest

import pandas as pd
from pandas.core.arrays import TimedeltaArrayMixin as TimedeltaArray
from pandas.core.arrays import TimedeltaArray
import pandas.util.testing as tm


Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/dtypes/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class TestABCClasses(object):
sparse_series = pd.Series([1, 2, 3]).to_sparse()
sparse_array = pd.SparseArray(np.random.randn(10))
sparse_frame = pd.SparseDataFrame({'a': [1, -1, None]})
datetime_array = pd.core.arrays.DatetimeArrayMixin(datetime_index)
timedelta_array = pd.core.arrays.TimedeltaArrayMixin(timedelta_index)
datetime_array = pd.core.arrays.DatetimeArray(datetime_index)
timedelta_array = pd.core.arrays.TimedeltaArray(timedelta_index)

def test_abc_types(self):
assert isinstance(pd.Index(['a', 'b', 'c']), gt.ABCIndex)
Expand Down
Loading