Skip to content

API: require tz equality or just tzawareness-compat in setitem-like methods? #37605

Closed
@jbrockmendel

Description

@jbrockmendel

There are a handful of methods that do casting/validation in DatetimeArray (and indirectly, Series and DatetimeIndex) methods:

__setitem__
shift
insert
fillna
take
searchsorted
__cmp__

In all cases, we upcast datetime64/datetime to Timestamp, try to parse strings, and check for tzawareness compat (i.e. raise if (self.tz is None) ^ (other.tz is None))

In the cases of searchsorted and cmp, we stop there, and don't require the actual timezones to match. In the other cases, we are stricter and raise if not tz_compare(self.tz, other.tz)

In #37299 we discussed the idea of making these uniform. I am generally positive on this, as it would make things simpler both for users and in the code. cc @jorisvandenbossche @jreback

Side-notes

  1. __sub__ doesn't do the same casting, but also requires tz match but could get by with only tzawareness compat, xref #31793 Add support for subtracting datetime from Timestamp #37329. BTW the stdlib datetime only requires tzawareness compat.

  2. In Series/DataFrame.__setitem__ we cast to object instead of raising on tz mismatch. For brevity I lump this in with "we raise on tz mismatch".

Metadata

Metadata

Assignees

No one assigned

    Labels

    API DesignEnhancementIndexingRelated to indexing on series/frames, not to indexes themselvesTimezonesTimezone data dtype

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions