-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
BUG: conversion a JSON field descriptor into pandas type for deprecated offsets frequency 'M' #55581
BUG: conversion a JSON field descriptor into pandas type for deprecated offsets frequency 'M' #55581
Conversation
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.
thanks for noticing and fixing! just got a question
pandas/io/json/_table_schema.py
Outdated
# GH#9586 rename frequency M to ME for offsets | ||
field["freq"] = freq_to_period_freqstr(1, field["freq"]) |
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.
what if field['freq']
is '2M'
?
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.
thanks, you are right, it doesn't work for '2M'. I corrected the definition of convert_json_field_to_pandas_type
and updated my test.
# GH#9586 | ||
df = DataFrame( | ||
{"ints": [1, 2]}, | ||
index=pd.PeriodIndex(["2011-01", "2011-08"], freq="2M"), |
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.
could we check it works for both '2M'
and 'M'
?
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.
yeah, sure, I added parameterization to the test, for 'M'
and '2M'
.
pandas/io/json/_table_schema.py
Outdated
# GH#9586 rename frequency M to ME for offsets | ||
freq_name = re.split("[0-9]*", field["freq"], maxsplit=1)[1] | ||
freq_n = field["freq"][: field["freq"].index(freq_name)] | ||
freq = freq_to_period_freqstr(freq_n, freq_name) |
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.
having a regular expression here looks a bit complex - would it work to do
offset = to_offset(field['freq'])
freq_n, freq_name = offset.n, offset.name
freq = freq_to_period_freqstr(freq_n, freq_name)
instead?
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.
thank you, it works very well. I replaced the regular expression with to_offset and updated my PR.
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.
nice one, thanks @natmokval !
Thank you @MarcoGorelli for reviewing this PR. |
xref #52064
when converting a JSON field descriptor into its corresponding pandas type we don't check if we have deprecated for offsets frequency "M".
corrected the definition of
convert_json_field_to_pandas_type
, added a test.