Skip to content

fixed bug in tz_localize to throw an error if the argument to the ambiguous parameter is not one of the 4 correct options #49856

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

Closed
wants to merge 0 commits into from

Conversation

jcaoun
Copy link
Contributor

@jcaoun jcaoun commented Nov 23, 2022

Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

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

Given #49565 (comment), I do believe the original issue is behaving as expected and a fix isn't needed here.

If you are looking for issues to tackle, I would recommend searching for issues that have good first issue and avoid issues that still have need triage

@MarcoGorelli
Copy link
Member

closing as per #49565 (comment), but thanks anyway for the pR

import pandas as pd
import unittest

class MyTestCase(unittest.TestCase):
Copy link
Member

Choose a reason for hiding this comment

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

this isn't the right location for tests, can you search for similar tests within the pandas test suite and add it there?

Also, you can use pytest.mark.parametrize to parametrize over arguments, no need to write 6 different tests

Copy link
Member

Choose a reason for hiding this comment

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

this comment still needs addressing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can disregard floor_timestamp_tests.py. The test cases in pandas/tests/scalar/timestamp/test_timezones.py cover the bug already and they are passing on my end

Copy link
Member

Choose a reason for hiding this comment

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

ok - will you remove it?

if ambiguous == 'infer':
raise ValueError('Cannot infer offset with only one time.')

if ambiguous != True and ambiguous != False and ambiguous != 'NaT' and ambiguous != 'raise':
Copy link
Member

Choose a reason for hiding this comment

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

let's write this as

if not isinstance(ambiguous, bool) and ambiguous not in {'NaT', 'raise'}:

Copy link
Contributor Author

@jcaoun jcaoun left a comment

Choose a reason for hiding this comment

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

I modified timestamps.pyx to include the changes you suggested, as well as modified test_timezones.py and made sure those test cases passed

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.

thanks for updating!

this is failing a lot of tests, could you take a lot please?

import pandas as pd
import unittest

class MyTestCase(unittest.TestCase):
Copy link
Member

Choose a reason for hiding this comment

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

this comment still needs addressing

@jcaoun
Copy link
Contributor Author

jcaoun commented Dec 1, 2022

I believe the test cases were failing after I merged with the main branch to keep it up to date, but I fixed the issue and they should be passing now

@MarcoGorelli MarcoGorelli self-requested a review December 2, 2022 10:03
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.

can you run the pre-commit checks and undo having commented-out lines please?

Comment on lines 146 to 129
tz = warsaw
tz = "Europe/Warsaw"
Copy link
Member

Choose a reason for hiding this comment

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

why does this need to change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't change that so I'm not sure, it changed when I merged with the main branch

Copy link
Member

Choose a reason for hiding this comment

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

looks like something went wrong when merging, please try again

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like there were some changes to these files on the pandas-dev main branch, I'll sync with my branch to get it up to date first

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, so I merged with with the pandas/dev main branch, then re-added my changed with tests and pre-commit passing. I accidentally closed this while merging so if you can't re-open, the new pull request is here: #50024

Comment on lines 78 to 90
with pytest.raises(pytz.AmbiguousTimeError, match=msg):
ts.tz_localize("dateutil/US/Central")

if ZoneInfo is not None:
try:
tz = ZoneInfo("US/Central")
except KeyError:
# no tzdata
pass
else:
with pytest.raises(pytz.AmbiguousTimeError, match=msg):
ts.tz_localize(tz)

Copy link
Member

Choose a reason for hiding this comment

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

why delete this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This also got deleted when I merged with the main branch

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

Successfully merging this pull request may close these issues.

BUG: when flooring, ambiguous parameter unnecessarily used (and raising Error)
3 participants