REF: DatetimeLikeArray by TomAugspurger · Pull Request #24024 · pandas-dev/pandas (original) (raw)

TODO:


n.b.: right now I have a few other PRs in this branch (#23601, #23990, #24023). The eventual diff is at TomAugspurger/pandas@disown-tz-only-target...TomAugspurger:disown-tz-only-rebased.

Also, I would say this isn't quite ready for review yet, but I've been promising it for a while. I'm going to try to split off a bit more into separate PRs.


This implements DatetimeArray and TimedeltaArray, arrays for storing datetime
(tz naive or aware) and timedelta data.

High-level Design:

Everything here applies equally to TimedeltaIndex / TimedeltaArray, other than
references to DatetimeTZDtype. We don't have an ExtensionType for Timedelta.

DatetimeIndex's data is now a DatetimeArray, rather than an ndarray, and its dtype
is dtype::Union['datetime64[ns]', DatetimeTZDtype].

Class Hierarchy: We've split DatetimeIndex to compose a DatetimeArray,
rather than inherit it.

Old - DatetimeIndex: dti_master

New - DatetimeIndex: dti_pr

New - DatetimeArray: dta_pr

Internals I've mostly given up here... Things are basically as they were
before, with the exception that DatetimeTZBlock now extends ExtensionBlock. In particular tz-naive data is still stored in a DatetimeBlock, and is still
consolidatable. This isn't elegant, but we've lived with it for this long.
Future releases can clean it up, possibly when we rewrite / cythonize the block
manager, possibly before.

Types of changes

  1. Some changes from x.view('i8') to x.astype('i8', copy=False) to
    support getting i8 values from {ndarray, DatetimeIndex, DatetimeArray}.
    We could revert those if we implemented DatetimeArray.view, but I don't
    think we should. However, this is slower than .view for ndarrays, so
    I'm going to find another way.
  2. Many places where we did series.values instead of series._values.
  3. Moves from PeriodArray / PeriodIndex to a base class. I've annotated these
    with NB: Moved from...
  4. Test skips / xfails. I intended to resolve all of these over the next few
    days.

TODO:

Closes #23185
Closes #23932
closes #24465