-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Regression: DatetimeIndex ignores timezones #11736
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
so there are actually quite a number of tests, but not in formatting; in fact this has nothing to do with formatting. In 0.17.1, this 'works'
but is actually 'wrong'
is the correct result. However, this parsing of a tz-aware then 'setting' its value via the tz arg is very very odd. This is why E.g. what exactly do you mean by having a tz-aware date AND providing a tz? should it be localized, renamed, or converted? I think the |
Basically, pre 0.17.x behavior was correct - it doesn't throw away the tz info neither tries to covert when fed a TZ-aware ISO string. So, if I had analogous function using standard datetime API, it would be equivalent to:
Which is sensible behavior for such ISO datetime parser [1]. 0.17.0 behavior is to ignore the TZ and create a naive datetime series, which is bad because now we've lost tz information from the string. And I've now learned 0.17.1 behavior is even worse, since it's converting and keeping the tz info. Either you convert and turn into naive (drop tz info) or you localize (add the tz info), but never a mix of both.
I see. There are tests here (https://github.com/pydata/pandas/blob/master/pandas/tests/test_series.py#L112) but are not covering parsing an ISO datetime string either. The parsing seems to be happening here (https://github.com/pydata/pandas/blob/master/pandas/tseries/tools.py#L279), I'll come up with some test cases. [1] https://tools.ietf.org/html/rfc3339#section-4.2 |
@hcarvalhoalves no, the pre 0.17.x behavior is wrong. It is VERY confusing. This is why the main entry point is I don't know if passing a Since I have never seen this I doubt there are tests (or I would have had to resolve this when I added this feature). You are essentially 'naming' a tz. This is not a normal things to do. Either you have a string that has a tz in it with an offset, in which case you convert to UTC, THEN convert it, or you construct it in local time, then localize it. There are NO other operations. |
I see. You mean the expected usage is this?
If this is really intended and not a regression I'll close this specific issue - and another issue could be opened to not have DatetimeIndex fail silently when there's an offset in the string. |
no I would leave this open. I think this path is not very well tested and needs exercising / clarification. My point though is if you have text data, |
BUG: construct Series of all NaT w/tz xref pandas-dev#11736
closes #11693 xref #11736 Author: Varun <[email protected]> Author: Jeff Reback <[email protected]> Closes #12195 from jreback/concat_ts and squashes the following commits: eaad93a [Jeff Reback] BUG: DatetimeIndex constructor to handle dtype & tz with conflicts 90d71f6 [Varun] BUG GH11693 Support NaT series concatenation
xref #17697, keeping this issue open since it demonstrates the behavior with using |
Work around an old time zone related bug (pandas-dev/pandas#11736), which was fixed in Pandas 0.24.
Work around an old time zone related bug (pandas-dev/pandas#11736), which was fixed in Pandas 0.24.
In 0.16.2,
DatetimeIndex
functions used to handle the timezone correctly:In 0.17.0, it's now ignoring timezones:
This slipped thru since the tests are very simple and don't cover many cases:
https://github.com/pydata/pandas/blob/cda9da82a68aed42421f7f788fb0c1e949e7a60c/pandas/tests/test_format.py#L3342
I'll attempt a patch later but if someone can give pointers where the breaking change happened I appreciate.
The text was updated successfully, but these errors were encountered: