Skip to content

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

Merged
merged 2 commits into from
Jan 9, 2019

Conversation

jbrockmendel
Copy link
Member

@codecov
Copy link

codecov bot commented Jan 7, 2019

Codecov Report

Merging #24663 into master will increase coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #24663      +/-   ##
==========================================
+ Coverage   92.37%   92.37%   +<.01%     
==========================================
  Files         166      166              
  Lines       52382    52382              
==========================================
+ Hits        48388    48389       +1     
+ Misses       3994     3993       -1
Flag Coverage Δ
#multiple 90.8% <ø> (ø) ⬆️
#single 43.01% <ø> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/util/testing.py 88.09% <0%> (+0.09%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4bf3a0e...a910a33. Read the comment docs.

@codecov
Copy link

codecov bot commented Jan 7, 2019

Codecov Report

Merging #24663 into master will increase coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #24663      +/-   ##
==========================================
+ Coverage   92.37%   92.37%   +<.01%     
==========================================
  Files         166      166              
  Lines       52382    52382              
==========================================
+ Hits        48388    48389       +1     
+ Misses       3994     3993       -1
Flag Coverage Δ
#multiple 90.8% <ø> (ø) ⬆️
#single 43.01% <ø> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/util/testing.py 88.09% <0%> (+0.09%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4bf3a0e...72e46b2. Read the comment docs.

@@ -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')])
Copy link
Member

@jschendel jschendel Jan 7, 2019

Choose a reason for hiding this comment

The 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 data variable that does both orders for aware/naive and the aware/aware case and get ride of the for obj loop, i.e.

@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)

Copy link
Member

Choose a reason for hiding this comment

The 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")])

Copy link
Contributor

Choose a reason for hiding this comment

The 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 DatetimeArray._from_sequence case.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, agreed that the DatetimeArray._from_sequence case hits the original issue.

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: mix = np.array([pd.Timestamp('2000', tz="US/Central"), pd.Timestamp('2000', tz='CET')]). I didn't see a test for that anywhere, and figured we could shoehorn it into this test if it's indeed not covered.

Copy link
Member

Choose a reason for hiding this comment

The 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.

@TomAugspurger TomAugspurger added Datetime Datetime data dtype Timezones Timezone data dtype labels Jan 7, 2019
@TomAugspurger TomAugspurger added this to the 0.24.0 milestone Jan 7, 2019
@@ -167,6 +167,7 @@ def datetime_to_datetime64(values: object[:]):
int64_t[:] iresult
npy_datetimestruct dts
_TSObject _ts
bint found_naive = False
Copy link
Contributor

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)

Copy link
Member Author

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

@TomAugspurger
Copy link
Contributor

This is good to go? Do the updates to the tests satisfy
https://github.com/pandas-dev/pandas/pull/24663/files#r245769417 @jschendel?

@jreback jreback merged commit 42b3182 into pandas-dev:master Jan 9, 2019
@jreback
Copy link
Contributor

jreback commented Jan 9, 2019

thanks @jbrockmendel

@jreback
Copy link
Contributor

jreback commented Jan 9, 2019

@jschendel I think your concerns are satisfied but if not pls raise an issue / PR.

@jbrockmendel jbrockmendel deleted the fseq branch January 9, 2019 14:48
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Timezones Timezone data dtype
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DatetimeArray._from_sequence with mixture of tz-naive and tz-aware data.
4 participants