-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DEPR: disallow parsing datetimes with mixed time zones unless utc=True
#57275
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
Changes from 14 commits
7539b80
4bd4969
7bcde02
a55d861
2220aa3
c2e0976
dee337b
b0b970b
95203cd
6a5cc06
730f10f
fdd22db
3783ea7
76574a6
00483ef
7410a9b
5bc7ae8
848edd9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -723,14 +723,6 @@ def to_datetime( | |
offsets (typically, daylight savings), see :ref:`Examples | ||
<to_datetime_tz_examples>` section for details. | ||
|
||
.. warning:: | ||
|
||
In a future version of pandas, parsing datetimes with mixed time | ||
zones will raise an error unless `utc=True`. | ||
Please specify `utc=True` to opt in to the new behaviour | ||
and silence this warning. To create a `Series` with mixed offsets and | ||
`object` dtype, please use `apply` and `datetime.datetime.strptime`. | ||
|
||
See also: pandas general documentation about `timezone conversion and | ||
localization | ||
<https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html | ||
|
@@ -812,7 +804,9 @@ def to_datetime( | |
When another datetime conversion error happens. For example when one | ||
of 'year', 'month', day' columns is missing in a :class:`DataFrame`, or | ||
when a Timezone-aware :class:`datetime.datetime` is found in an array-like | ||
of mixed time offsets, and ``utc=False``. | ||
of mixed time offsets, and ``utc=False``, or when parsing datetimes | ||
with mixed time zones unless ``utc=True``. Parsing datetimes with mixed | ||
time zones, please specify ``utc=True`` to opt in to the new behaviour. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there's a word missing in this sentence? Like, "If parsing"? Also, no need to say "to opt in to the new behaviour" - this is the new behaviour :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the comment. I corrected the wording as you suggested. |
||
|
||
See Also | ||
-------- | ||
|
@@ -932,35 +926,32 @@ def to_datetime( | |
- However, timezone-aware inputs *with mixed time offsets* (for example | ||
issued from a timezone with daylight savings, such as Europe/Paris) | ||
are **not successfully converted** to a :class:`DatetimeIndex`. | ||
Parsing datetimes with mixed time zones will show a warning unless | ||
`utc=True`. If you specify `utc=False` the warning below will be shown | ||
and a simple :class:`Index` containing :class:`datetime.datetime` | ||
objects will be returned: | ||
Parsing datetimes with mixed time zones will raise a ValueError unless | ||
``utc=True``: | ||
|
||
>>> pd.to_datetime( | ||
... ["2020-10-25 02:00 +0200", "2020-10-25 04:00 +0100"] | ||
... ) # doctest: +SKIP | ||
FutureWarning: In a future version of pandas, parsing datetimes with mixed | ||
time zones will raise an error unless `utc=True`. Please specify `utc=True` | ||
to opt in to the new behaviour and silence this warning. To create a `Series` | ||
with mixed offsets and `object` dtype, please use `apply` and | ||
`datetime.datetime.strptime`. | ||
Index([2020-10-25 02:00:00+02:00, 2020-10-25 04:00:00+01:00], | ||
dtype='object') | ||
ValueError: cannot parse datetimes with mixed time zones unless `utc=True` | ||
|
||
- To create a :class:`Series` with mixed offsets and ``object`` dtype, please use | ||
:meth:`Series.apply` and :func:`datetime.datetime.strptime`: | ||
|
||
>>> import datetime as dt | ||
>>> ser = pd.Series(["2020-10-25 02:00 +0200", "2020-10-25 04:00 +0100"]) | ||
>>> ser.apply(lambda x: dt.datetime.strptime(x, "%Y-%m-%d %H:%M %z")) | ||
0 2020-10-25 02:00:00+02:00 | ||
1 2020-10-25 04:00:00+01:00 | ||
dtype: object | ||
|
||
- A mix of timezone-aware and timezone-naive inputs is also converted to | ||
a simple :class:`Index` containing :class:`datetime.datetime` objects: | ||
- A mix of timezone-aware and timezone-naive inputs will also raise a ValueError | ||
unless ``utc=True``: | ||
|
||
>>> from datetime import datetime | ||
>>> pd.to_datetime( | ||
... ["2020-01-01 01:00:00-01:00", datetime(2020, 1, 1, 3, 0)] | ||
... ) # doctest: +SKIP | ||
FutureWarning: In a future version of pandas, parsing datetimes with mixed | ||
time zones will raise an error unless `utc=True`. Please specify `utc=True` | ||
to opt in to the new behaviour and silence this warning. To create a `Series` | ||
with mixed offsets and `object` dtype, please use `apply` and | ||
`datetime.datetime.strptime`. | ||
Index([2020-01-01 01:00:00-01:00, 2020-01-01 03:00:00], dtype='object') | ||
ValueError: cannot parse datetimes with mixed time zones unless `utc=True` | ||
|
||
| | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.