|
13 | 13 | from pandas._libs.tslibs import (
|
14 | 14 | ccalendar, conversion, fields, parsing, timezones)
|
15 | 15 | import pandas.compat as compat
|
16 |
| -from pandas.core.accessor import delegate_names |
17 | 16 | from pandas.util._decorators import Appender, Substitution, cache_readonly
|
18 | 17 |
|
19 | 18 | from pandas.core.dtypes.common import (
|
|
25 | 24 | from pandas.core.dtypes.generic import ABCSeries
|
26 | 25 | from pandas.core.dtypes.missing import isna
|
27 | 26 |
|
| 27 | +from pandas.core.accessor import delegate_names |
28 | 28 | from pandas.core.arrays import datetimelike as dtl
|
29 | 29 | from pandas.core.arrays.datetimes import (
|
30 | 30 | DatetimeArrayMixin as DatetimeArray, _to_m8)
|
31 | 31 | from pandas.core.base import _shared_docs
|
32 | 32 | import pandas.core.common as com
|
33 | 33 | from pandas.core.indexes.base import Index, _index_shared_docs
|
34 | 34 | from pandas.core.indexes.datetimelike import (
|
35 |
| - DatetimeIndexOpsMixin, wrap_array_method, |
36 |
| - wrap_field_accessor, DatelikeIndexMixin, DatetimelikeDelegateMixin) |
| 35 | + DatelikeIndexMixin, DatetimeIndexOpsMixin, DatetimelikeDelegateMixin, |
| 36 | + wrap_array_method, wrap_field_accessor) |
37 | 37 | from pandas.core.indexes.numeric import Int64Index
|
38 | 38 | from pandas.core.ops import get_op_result_name
|
39 | 39 | import pandas.core.tools.datetimes as tools
|
@@ -185,6 +185,20 @@ class DatetimeIndex(DatelikeIndexMixin,
|
185 | 185 | """
|
186 | 186 | _typ = 'datetimeindex'
|
187 | 187 | _join_precedence = 10
|
| 188 | + # TODO: dispatch |
| 189 | + @classmethod |
| 190 | + def _generate_range(cls, start, end, periods, freq, tz=None, |
| 191 | + normalize=False, ambiguous="raise", |
| 192 | + closed=None): |
| 193 | + return cls._simple_new( |
| 194 | + DatetimeArray._generate_range( |
| 195 | + start, end, periods, freq, tz=tz, |
| 196 | + normalize=normalize, ambiguous=ambiguous, |
| 197 | + closed=closed, |
| 198 | + ) |
| 199 | + ) |
| 200 | + _box_func = DatetimeArray._box_func |
| 201 | + _box_values = DatetimeArray._box_values |
188 | 202 |
|
189 | 203 | def _join_i8_wrapper(joinf, **kwargs):
|
190 | 204 | return DatetimeIndexOpsMixin._join_i8_wrapper(joinf, dtype='M8[ns]',
|
@@ -321,24 +335,23 @@ def _simple_new(cls, values, name=None, freq=None, tz=None,
|
321 | 335 | if we are passed a non-dtype compat, then coerce using the constructor
|
322 | 336 | """
|
323 | 337 | # DatetimeArray._simple_new will accept either i8 or M8[ns] dtypes
|
324 |
| - assert isinstance(values, np.ndarray), type(values) |
| 338 | + values = DatetimeArray(values, dtype=dtype, freq=freq, tz=tz) |
| 339 | + # assert isinstance(values, np.ndarray), type(values) |
325 | 340 |
|
326 | 341 | result = super(DatetimeIndex, cls)._simple_new(values, freq, tz,
|
327 | 342 | **kwargs)
|
328 | 343 | result.name = name
|
329 | 344 | result._reset_identity()
|
330 | 345 | return result
|
331 | 346 |
|
| 347 | + @property |
| 348 | + def values(self): |
| 349 | + return self._data._data |
332 | 350 | # --------------------------------------------------------------------
|
333 | 351 |
|
334 | 352 | @property
|
335 | 353 | def _values(self):
|
336 |
| - # tz-naive -> ndarray |
337 |
| - # tz-aware -> DatetimeIndex |
338 |
| - if self.tz is not None: |
339 |
| - return self |
340 |
| - else: |
341 |
| - return self.values |
| 354 | + return self._data |
342 | 355 |
|
343 | 356 | @property
|
344 | 357 | def tz(self):
|
|
0 commit comments