Skip to content

CLN: unify error message when parsing datetimes with mixed time zones with utc=False #57653

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

Merged

Conversation

natmokval
Copy link
Contributor

xref #57275, #55793

unified ValueError message when parsing datetimes with mixed time zones with utc=False
so far we get two different ValueError messages:

import pandas as pd
from datetime import datetime
import pytz

str_my ="2020-10-26 00:00:00+06:00"
ts = pd.Timestamp("2018-01-01", tz="US/Pacific")
dt = datetime(2020, 1, 1, 18, tzinfo=pytz.timezone("Australia/Melbourne"))

dt1 = pd.to_datetime([ts, str_my])
# ValueError: Mixed timezones detected. pass utc=True in to_datetime or tz='UTC' in DatetimeIndex to convert to a common timezone.
dt2 = pd.to_datetime([str_my, ts])
# ValueError: cannot parse datetimes with mixed time zones unless `utc=True`

dt1 = pd.to_datetime([dt, str_my], utc=False)
# ValueError: Mixed timezones detected. pass utc=True in to_datetime or tz='UTC' in DatetimeIndex to convert to a common timezone.
dt2 = pd.to_datetime([str_my, dt], utc=False)
# ValueError: cannot parse datetimes with mixed time zones unless `utc=True`

@natmokval natmokval marked this pull request as ready for review February 27, 2024 23:17
@@ -598,7 +598,8 @@ cpdef array_to_datetime(
is_same_offsets = len(out_tzoffset_vals) == 1
if not is_same_offsets:
raise ValueError(
"cannot parse datetimes with mixed time zones unless `utc=True`"
"Mixed timezones detected. pass utc=True in to_datetime "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Mixed timezones detected. pass utc=True in to_datetime "
"Mixed timezones detected. Pass utc=True in to_datetime "

And could you capitalize elsewhere too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for reviewing this PR. I capitalized the letter 'p'.

@mroeschke mroeschke added the Error Reporting Incorrect or improved errors from pandas label Feb 27, 2024
@MarcoGorelli MarcoGorelli added this to the 3.0 milestone Feb 28, 2024
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice one, thanks!

@mroeschke mroeschke merged commit aee49e9 into pandas-dev:main Feb 28, 2024
@mroeschke
Copy link
Member

Thanks @natmokval

pmhatre1 pushed a commit to pmhatre1/pandas-pmhatre1 that referenced this pull request May 7, 2024
… with utc=False (pandas-dev#57653)

* unify error msg for mixed offsets when utc=False

* capitalize the letter p in error message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants