-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: to_period() freq was not infered #33406
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 4 commits
5cb07c8
a6f0cd5
10ac1de
aed8d13
4dcd4e3
e5973a8
1926be1
1b031a1
ac0ffdf
d823ce6
0b63811
55df3fc
ea2f5c7
5de3611
0274c62
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,3 +1,5 @@ | ||||||||||||||
import warnings | ||||||||||||||
|
||||||||||||||
import dateutil.tz | ||||||||||||||
from dateutil.tz import tzlocal | ||||||||||||||
import pytest | ||||||||||||||
|
@@ -75,6 +77,22 @@ def test_to_period_monthish(self): | |||||||||||||
with pytest.raises(ValueError, match=INVALID_FREQ_ERR_MSG): | ||||||||||||||
date_range("01-Jan-2012", periods=8, freq="EOM") | ||||||||||||||
|
||||||||||||||
def test_to_period_infer(self): | ||||||||||||||
# https://github.com/pandas-dev/pandas/issues/33358 | ||||||||||||||
rng = date_range( | ||||||||||||||
start="2019-12-22 06:40:00+00:00", | ||||||||||||||
end="2019-12-22 08:45:00+00:00", | ||||||||||||||
freq="5min", | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
# Using simple filter because we are not checking for the warning here | ||||||||||||||
warnings.simplefilter("ignore", UserWarning) | ||||||||||||||
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. what is the warning from? this would not be set like this if you really need to 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 warning raises when a user is attempting to convert a date_range to period, if the date_range have a timezone it will drop it in the conversion, the warning let the user know about that: pandas/pandas/core/arrays/datetimes.py Lines 1085 to 1090 in 3cca07c
Sure! will fix. 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 c, ok then |
||||||||||||||
|
||||||||||||||
pi1 = rng.to_period("5min") | ||||||||||||||
pi2 = rng.to_period() | ||||||||||||||
|
||||||||||||||
tm.assert_index_equal(pi1, pi2) | ||||||||||||||
|
||||||||||||||
def test_period_dt64_round_trip(self): | ||||||||||||||
dti = date_range("1/1/2000", "1/7/2002", freq="B") | ||||||||||||||
pi = dti.to_period() | ||||||||||||||
|
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.
@MomIsBestFriend why cant we just do
res = freq
here? (im trying to clean up usages ofbase_and_stride
)