Description
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
-
__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. -
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".