Skip to content

BUG: cannot use category dtype in pandas read_json method #40063

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
1 task done
alison199 opened this issue Feb 25, 2021 · 1 comment
Closed
1 task done

BUG: cannot use category dtype in pandas read_json method #40063

alison199 opened this issue Feb 25, 2021 · 1 comment
Labels
Categorical Categorical Data Type Duplicate Report Duplicate issue or pull request IO JSON read_json, to_json, json_normalize

Comments

@alison199
Copy link

alison199 commented Feb 25, 2021

  • I have confirmed this bug exists on the latest version of pandas.

import pandas as pd

print(pd.version)

1.2.2

Problem described in other places:

  1. pd.read_json ignores 'category' dtypes #21892
  2. BUG: Using categorical dtype in read_json #25573
  3. Fix read_json category dtype #30728

Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

import pandas as pd

content = '[{"score": 1,"color":"red"},{"score":10,"color":"green"}]'
dtypes_dict = {'score': 'uint8', 'colour': 'category'}

data_frame = pd.read_json(content, dtype=dtypes_dict)
print(data_frame.dtypes)

Problem description

When I run the above, I get the following dtypes for the dataframe columns:

score uint8
color object

Expected Output

score uint8
color category

@alison199 alison199 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 25, 2021
@jreback
Copy link
Contributor

jreback commented Feb 25, 2021

duplicate of #21892

@jreback jreback added Duplicate Report Duplicate issue or pull request Categorical Categorical Data Type IO JSON read_json, to_json, json_normalize and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 25, 2021
@jreback jreback added this to the No action milestone Feb 25, 2021
@jreback jreback closed this as completed Feb 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Categorical Categorical Data Type Duplicate Report Duplicate issue or pull request IO JSON read_json, to_json, json_normalize
Projects
None yet
Development

No branches or pull requests

2 participants