-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
REF: Stop mixing DTA/TDA into DTI/TDI #24476
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
Changes from all commits
350b0ec
837c16a
e28ff51
ba61a0d
fdf1770
ed9e1de
ea3965d
8ceab31
5b95d78
60cd35d
bbbd778
238b386
9d01424
a5e5d65
21833f3
1ff0c4d
3faed22
e607edd
38e4bca
2afd6ab
43a162e
9ddf4bd
11dcef0
6627f56
f6a8951
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ | |
import pandas.core.common as com | ||
from pandas.core.indexes.base import Index | ||
from pandas.core.indexes.datetimelike import ( | ||
DatetimeIndexOpsMixin, DatetimelikeDelegateMixin) | ||
DatetimeIndexOpsMixin, DatetimelikeDelegateMixin, ea_passthrough) | ||
from pandas.core.indexes.numeric import Int64Index | ||
from pandas.core.ops import get_op_result_name | ||
import pandas.core.tools.datetimes as tools | ||
|
@@ -96,19 +96,13 @@ class DatetimeDelegateMixin(DatetimelikeDelegateMixin): | |
_delegate_class = DatetimeArray | ||
|
||
|
||
@delegate_names(DatetimeArray, ["to_period", "tz_localize", "tz_convert", | ||
"day_name", "month_name"], | ||
typ="method", overwrite=True) | ||
@delegate_names(DatetimeArray, | ||
DatetimeArray._field_ops, typ="property", overwrite=True) | ||
@delegate_names(DatetimeArray, | ||
DatetimeDelegateMixin._delegated_properties, | ||
typ="property") | ||
@delegate_names(DatetimeArray, | ||
DatetimeDelegateMixin._delegated_methods, | ||
typ="method", overwrite=False) | ||
class DatetimeIndex(DatetimeArray, DatetimeIndexOpsMixin, Int64Index, | ||
DatetimeDelegateMixin): | ||
class DatetimeIndex(DatetimeIndexOpsMixin, Int64Index, DatetimeDelegateMixin): | ||
""" | ||
Immutable ndarray of datetime64 data, represented internally as int64, and | ||
which can be boxed to Timestamp objects that are subclasses of datetime and | ||
|
@@ -268,6 +262,7 @@ def _join_i8_wrapper(joinf, **kwargs): | |
_object_ops = DatetimeArray._object_ops | ||
_field_ops = DatetimeArray._field_ops | ||
_datetimelike_ops = DatetimeArray._datetimelike_ops | ||
_datetimelike_methods = DatetimeArray._datetimelike_methods | ||
|
||
# -------------------------------------------------------------------- | ||
# Constructors | ||
|
@@ -294,8 +289,8 @@ def __new__(cls, data=None, | |
"endpoints is deprecated. Use " | ||
"`pandas.date_range` instead.", | ||
FutureWarning, stacklevel=2) | ||
|
||
return cls(dtarr, name=name) | ||
return cls._simple_new( | ||
dtarr._data, freq=dtarr.freq, tz=dtarr.tz, name=name) | ||
|
||
if is_scalar(data): | ||
raise TypeError("{cls}() must be called with a " | ||
|
@@ -331,7 +326,11 @@ def _simple_new(cls, values, name=None, freq=None, tz=None, dtype=None): | |
# DatetimeArray._simple_new will accept either i8 or M8[ns] dtypes | ||
assert isinstance(values, np.ndarray), type(values) | ||
|
||
result = super(DatetimeIndex, cls)._simple_new(values, freq, tz) | ||
dtarr = DatetimeArray._simple_new(values, freq=freq, tz=tz) | ||
result = object.__new__(cls) | ||
result._data = dtarr._data | ||
result._freq = dtarr.freq | ||
result._tz = dtarr.tz | ||
result.name = name | ||
# For groupby perf. See note in indexes/base about _index_data | ||
result._index_data = result._data | ||
|
@@ -340,6 +339,10 @@ def _simple_new(cls, values, name=None, freq=None, tz=None, dtype=None): | |
|
||
# -------------------------------------------------------------------- | ||
|
||
@property | ||
def dtype(self): | ||
return self._eadata.dtype | ||
|
||
@property | ||
def _values(self): | ||
# tz-naive -> ndarray | ||
|
@@ -360,6 +363,8 @@ def tz(self, value): | |
raise AttributeError("Cannot directly set timezone. Use tz_localize() " | ||
"or tz_convert() as appropriate") | ||
|
||
tzinfo = tz | ||
|
||
@property | ||
def size(self): | ||
# TODO: Remove this when we have a DatetimeTZArray | ||
|
@@ -670,7 +675,7 @@ def intersection(self, other): | |
def _get_time_micros(self): | ||
values = self.asi8 | ||
if self.tz is not None and not timezones.is_utc(self.tz): | ||
values = self._local_timestamps() | ||
values = self._eadata._local_timestamps() | ||
return fields.get_time_micros(values) | ||
|
||
def to_series(self, keep_tz=None, index=None, name=None): | ||
|
@@ -1139,12 +1144,64 @@ def _eadata(self): | |
_is_monotonic_increasing = Index.is_monotonic_increasing | ||
_is_monotonic_decreasing = Index.is_monotonic_decreasing | ||
_is_unique = Index.is_unique | ||
astype = DatetimeIndexOpsMixin.astype | ||
|
||
_timezone = cache_readonly(DatetimeArray._timezone.fget) | ||
is_normalized = cache_readonly(DatetimeArray.is_normalized.fget) | ||
_resolution = cache_readonly(DatetimeArray._resolution.fget) | ||
|
||
strftime = ea_passthrough("strftime") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This removed the docstring. Is there a TODO / issue to add it back? |
||
_has_same_tz = ea_passthrough("_has_same_tz") | ||
__array__ = ea_passthrough("__array__") | ||
|
||
@property | ||
def offset(self): | ||
""" | ||
get/set the frequency of the instance | ||
""" | ||
msg = ('{cls}.offset has been deprecated and will be removed ' | ||
'in a future version; use {cls}.freq instead.' | ||
.format(cls=type(self).__name__)) | ||
warnings.warn(msg, FutureWarning, stacklevel=2) | ||
return self.freq | ||
|
||
@offset.setter | ||
def offset(self, value): | ||
""" | ||
get/set the frequency of the instance | ||
""" | ||
msg = ('{cls}.offset has been deprecated and will be removed ' | ||
'in a future version; use {cls}.freq instead.' | ||
.format(cls=type(self).__name__)) | ||
warnings.warn(msg, FutureWarning, stacklevel=2) | ||
self.freq = value | ||
|
||
@property | ||
def freq(self): | ||
return self._freq | ||
|
||
@freq.setter | ||
def freq(self, value): | ||
if value is not None: | ||
# let DatetimeArray to validation | ||
self._eadata.freq = value | ||
|
||
self._freq = to_offset(value) | ||
|
||
def __getitem__(self, key): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In #24024 we move |
||
result = self._eadata.__getitem__(key) | ||
if is_scalar(result): | ||
return result | ||
elif result.ndim > 1: | ||
# To support MPL which performs slicing with 2 dim | ||
# even though it only has 1 dim by definition | ||
assert isinstance(result, np.ndarray), result | ||
return result | ||
return type(self)(result, name=self.name) | ||
|
||
@property | ||
def _box_func(self): | ||
return lambda x: Timestamp(x, tz=self.tz) | ||
|
||
# -------------------------------------------------------------------- | ||
|
||
@Substitution(klass='DatetimeIndex') | ||
|
@@ -1486,9 +1543,8 @@ def date_range(start=None, end=None, periods=None, freq=None, tz=None, | |
start=start, end=end, periods=periods, | ||
freq=freq, tz=tz, normalize=normalize, | ||
closed=closed, **kwargs) | ||
|
||
result = DatetimeIndex(dtarr, name=name) | ||
return result | ||
return DatetimeIndex._simple_new( | ||
dtarr._data, tz=dtarr.tz, freq=dtarr.freq, name=name) | ||
|
||
|
||
def bdate_range(start=None, end=None, periods=None, freq='B', tz=None, | ||
|
Uh oh!
There was an error while loading. Please reload this page.