-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Warn when creating Period
with a string that includes timezone information
#47990
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 3 commits
49ea3fb
d949d60
cd421e4
5d99f75
8de04d1
a067f84
57d8883
fe9222e
b9e119e
466ae26
372e9e4
edf7de3
4d8ee9b
ca24736
d398265
84621a0
55fbbab
441d17c
abf431e
cecc738
b5a2b8e
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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import numpy as np | ||
import pytest | ||
|
||
from pandas.errors import DateTimeWarning | ||
|
||
from pandas import ( | ||
NaT, | ||
Period, | ||
|
@@ -20,7 +22,7 @@ def test_required_arguments(self): | |
with pytest.raises(ValueError, match=msg): | ||
period_range("2011-1-1", "2012-1-1", "B") | ||
|
||
@pytest.mark.parametrize("freq", ["D", "W", "M", "Q", "A"]) | ||
@pytest.mark.parametrize("freq", ["D", "M", "Q", "A"]) | ||
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. The "W" here tests for functionality that is not properly implemented in Pandas. Namely creating a This is a bit sad because the given string is Pandas' string representation of a week period and it would be nice to have bi-directionality. 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. Could you address this in a separate PR just to keep this PR tightly scoped? 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 could but doing so would stall this PR until the "W" PR is merged. The two test cases I changed raise the warning introduced in this PR. How should we proceed? 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 sure I fully understand where and how a 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. The two tests that I propose to change create a 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. Sure, this appears to be an issue, but I don't understand why these "W" changes need to made in the same PR as adding the warning for Periods with timezones since they seem independent. Having them as separate PRs makes tracking issues easier in the long run. 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. This only applies to "W" because it has to do with what the string representation of a week period is and how it's parsed. Some part of that week string is interpreted as a timezone. If I remember correctly, it's the hyphen and the day ( 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. Ah okay thanks. That explanation makes sense. But it would be good to still keep testing 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. And ignore the warning in the test or what? The CI requires that the test suite doesn't throw warnings, no? It sounds like implementing that would make the test a little complex. I'd have to special-case the "W", so the warning is only ignored there and not for the other frequencies. In general, what's the point of testing for undocumented & broken functionality like this? Do we have reason to believe that library users are relying on parsing these kind of strings? To me the conversion from Period to String and back seems like a hack to write those tests quickly. Is this something we need to support going forward? 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. You can use Generally, we have seen all sorts of undocumented use cases and have gotten issues when those behaviors "broke". I imagine this should be supported eventually. |
||
def test_construction_from_string(self, freq): | ||
# non-empty | ||
expected = date_range( | ||
|
@@ -119,3 +121,13 @@ def test_errors(self): | |
msg = "periods must be a number, got foo" | ||
with pytest.raises(TypeError, match=msg): | ||
period_range(start="2017Q1", periods="foo") | ||
|
||
|
||
def test_range_tz(): | ||
# GH 47005 Time zone should be ignored with warning. | ||
with tm.assert_produces_warning(DateTimeWarning): | ||
pi_tz = period_range( | ||
"2022-01-01 06:00:00+02:00", "2022-01-01 09:00:00+02:00", freq="H" | ||
) | ||
pi_naive = period_range("2022-01-01 06:00:00", "2022-01-01 09:00:00", freq="H") | ||
tm.assert_index_equal(pi_tz, pi_naive) |
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.
move to 1.5 this is not a change we would backport
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.
I don't understand how the versioning works. Should this go into 1.5.3 or 1.6.0? I put it in
v1.5.3.rst
for now.