Skip to content
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

BUG: mixed-type mixed-timezone/awareness #55793

Merged
merged 7 commits into from
Nov 9, 2023

Conversation

jbrockmendel
Copy link
Member

Surfaced while implementing #55564.

Two implementation notes:

  1. The implementation here is pretty ugly because we have to work around an existing deprecation. I chose to avoid changing the behavior in any of the cases that currently warn. Once that deprecation is enforced, we'll be able to simplify this quite a bit.

  2. This takes a stand on API/PERF: when to check for mismatched tzs/awareness in array_to_datetime #55779 for checking once at the end instead of inside the loop.

@mroeschke mroeschke added the Timezones Timezone data dtype label Nov 1, 2023
Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

Really like the design you've set up with managing the parse state in its own class. Just a few comments but otherwise over to @MarcoGorelli

if not tz_compare(tz_out, tz_out2):
# e.g. test_to_datetime_mixed_tzs_mixed_types
raise ValueError(
"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.

Just to be clear this won't affect the object dtype case right? Maybe worth adding a test that is still possible if not already in the suite

Copy link
Member

Choose a reason for hiding this comment

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

as in, pd.Index([datetime(2020, 1, 1, tzinfo=zoneinfo.ZoneInfo('US/Central')), datetime(2020, 1, 1, tzinfo=timezone.utc)])? I don't think it should affect it, but yeah, a little test with this wouldn't hurt

Copy link
Member Author

Choose a reason for hiding this comment

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

updated with test

@@ -14,6 +14,8 @@ cdef class DatetimeParseState:
cdef:
bint found_tz
bint found_naive
bint found_naive_str
Copy link
Member

Choose a reason for hiding this comment

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

Is it easy to add comments inline with these members or as part of the class? I can see the distinction between found_native and found_naive_str being unclear over time

Copy link
Member Author

Choose a reason for hiding this comment

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

will update with comment(s). we'll be able to simplify this a ton in 3.0 once deprecation are enforced

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, like the solid testing - just got two minor comments

# both_strs-> paths that were previously already deprecated with warning
# issued in _array_to_datetime_object
both_strs = isinstance(aware_val, str) and isinstance(naive_val, str)
isinstance(aware_val, str) or isinstance(naive_val, str)
Copy link
Member

Choose a reason for hiding this comment

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

what's this statement doing?

Copy link
Member Author

Choose a reason for hiding this comment

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

probably left over from a previous commit, will remove

if not tz_compare(tz_out, tz_out2):
# e.g. test_to_datetime_mixed_tzs_mixed_types
raise ValueError(
"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.

as in, pd.Index([datetime(2020, 1, 1, tzinfo=zoneinfo.ZoneInfo('US/Central')), datetime(2020, 1, 1, tzinfo=timezone.utc)])? I don't think it should affect it, but yeah, a little test with this wouldn't hurt

@mroeschke mroeschke added this to the 2.2 milestone Nov 9, 2023
@mroeschke mroeschke merged commit 5cedf87 into pandas-dev:main Nov 9, 2023
34 checks passed
@mroeschke
Copy link
Member

Thanks @jbrockmendel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Timezones Timezone data dtype
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: no mixed naive/aware checks with mixed string/datetime
4 participants