Skip to content
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

Conversation

natmokval
Copy link
Contributor

@natmokval natmokval commented Oct 18, 2023

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.

@natmokval natmokval changed the title BUG: read_json_table period for dep recated freq M BUG: conversion a JSON field descriptor into pandas type for deprecated offsets frequency 'M' Oct 18, 2023
@natmokval natmokval marked this pull request as ready for review October 19, 2023 09:13
@mroeschke mroeschke added IO JSON read_json, to_json, json_normalize Frequency DateOffsets labels Oct 19, 2023
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 noticing and fixing! just got a question

Comment on lines 211 to 212
# GH#9586 rename frequency M to ME for offsets
field["freq"] = freq_to_period_freqstr(1, field["freq"])
Copy link
Member

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'?

Copy link
Contributor Author

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"),
Copy link
Member

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'?

Copy link
Contributor Author

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

Comment on lines 212 to 215
# 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)
Copy link
Member

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?

Copy link
Contributor Author

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.

@MarcoGorelli MarcoGorelli added this to the 2.2 milestone Oct 24, 2023
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.

nice one, thanks @natmokval !

@MarcoGorelli MarcoGorelli merged commit 6ef695f into pandas-dev:main Oct 24, 2023
33 checks passed
@natmokval
Copy link
Contributor Author

Thank you @MarcoGorelli for reviewing this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Frequency DateOffsets IO JSON read_json, to_json, json_normalize
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants