-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: fix to_datetime failing to raise on mixed tznaive/tzaware datetimes #24663
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 1 commit
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 |
---|---|---|
|
@@ -16,6 +16,25 @@ | |
|
||
|
||
class TestDatetimeArrayConstructor(object): | ||
def test_mixing_naive_tzaware_raises(self): | ||
# GH#24569 | ||
arr = np.array([pd.Timestamp('2000'), pd.Timestamp('2000', tz='CET')]) | ||
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. Is there a test that verifies mixed tz example from the issue raises? I didn't see one quickly glancing over this file, but could be missing it or it could be elsewhere. If not, you could maybe parametrize over a @pytest.mark.parametrize('data', [
[pd.Timestamp('2000', tz='CET'), pd.Timestamp('2000')],
[pd.Timestamp('2000'), pd.Timestamp('2000', tz='CET')],
[pd.Timestamp('2000', tz="US/Central"), pd.Timestamp('2000', tz='CET')]])
def test_mixing_naive_tzaware_raises(self):
arr = np.array(data) 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. Or alternatively parametrizing over timezone pairs if it seems cleaner, e.g. @pytest.mark.parametrize('tz1, 'tz2', [("CET", None), (None, "CET"), ("US/Central", "CET")]) 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 this does does hit the case from this original issue, in the 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. Yes, agreed that the I think my comment was a bit unclear; what I was asking is if we have coverage for the working mixed tz example you also provided in the issue: 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. Not a pressing issue or anything though, so if it's not covered it we could just make it a follow-up item; don't want this to block other work. |
||
|
||
msg = ('Cannot mix tz-aware with tz-naive values|' | ||
'Tz-aware datetime.datetime cannot be converted ' | ||
'to datetime64 unless utc=True') | ||
|
||
for obj in [arr, arr[::-1]]: | ||
# check that we raise regardless of whether naive is found | ||
# before aware or vice-versa | ||
for meth in [DatetimeArray._from_sequence, | ||
sequence_to_dt64ns, | ||
pd.to_datetime, | ||
pd.DatetimeIndex]: | ||
TomAugspurger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
with pytest.raises(ValueError, match=msg): | ||
meth(obj) | ||
|
||
def test_from_pandas_array(self): | ||
arr = pd.array(np.arange(5, dtype=np.int64)) * 3600 * 10**9 | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jbrockmendel is there a reason we cannot remove this routine entirely in favor of using
array_to_datetime
? can you create an issue about this (though maybe you already did)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#24006 does this, but is on hold ATM