-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
API: require tz equality or just tzawareness-compat in setitem-like methods? #37605
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
Comments
Personally, I would go for "tz-awareness compat" requirement for all cases, I think. I don't think there are really "ambiguous" cases about what the result would be if all involved are tz-aware? (which if of course not the same with mixed tz-awareness) |
im on board with going all-tzawareness-compat. Assuming we get consensus on that, should we do a deprecation cycle or Just Do It? |
yeah i think should deprecate now +1 in strict |
@jreback to be clear, joris and I are advocating for the non-strict version |
@TomAugspurger @simonjayhawkins @WillAyd @mroeschke any preferences here? |
If the non-strict route was chosen, what would be the resulting timezone after these operations? |
|
I guess either choice is okay with me with slight preference for full strict |
I'm +1 on this as well. if we can standardize on one function for checking compatibility in all these cases, it will be easier to maintain and also have more test coverage |
Hi team, I recently bumped into this warning and after reading the change notes and relevant code changes (not very familiar with this area), I am not quite following. This LOC of mine gives me warning.
Thanks |
what warning? what dtype does |
The warning comes from here:
The Specifically,
|
To keep the current behavior, in 2.0 you'll need to do |
Thanks a lot ! |
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".The text was updated successfully, but these errors were encountered: