Skip to content

BUG: missing values encoded in pandas.Int64Dtype not supported by json table scheme #40255

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
2 of 3 tasks
enryH opened this issue Mar 5, 2021 · 2 comments · Fixed by #50332
Closed
2 of 3 tasks

BUG: missing values encoded in pandas.Int64Dtype not supported by json table scheme #40255

enryH opened this issue Mar 5, 2021 · 2 comments · Fixed by #50332
Labels
Bug IO JSON read_json, to_json, json_normalize NA - MaskedArrays Related to pd.NA and nullable extension arrays

Comments

@enryH
Copy link
Contributor

enryH commented Mar 5, 2021

  • I have checked that this issue has not already been reported.

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

  • (optional) I have confirmed this bug exists on the master branch of pandas.


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
data = {'A' : [1, 2, 2, pd.NA, 4, 8, 8, 8, 8, 9],
 'B': [pd.NA] * 10}
data = pd.DataFrame(data)
data = data.astype(pd.Int64Dtype()) # in my example I get this from data.convert_dtypes()
data_json = data.to_json(orient='table', indent=4)
pd.read_json(data_json, orient='table') #ValueError: Cannot convert non-finite values (NA or inf) to integer

Problem description

I am investigating different json-ouput formats for my use-case. I expect as an end-user that if I can write a json with pandas, I can also read it in without an error.

Background: I used pd.convert_dtypes on a larger DataFrame, where some columns are populated by identical values. convert_dtypes converted some of them having only missing to pd.Int64Dtype. I tried understand why this is failing und could replicate the issue using the above example having identical dtypes as in my use-case.

Expected Output

      A     B
0     1  <NA>
1     2  <NA>
2     2  <NA>
3  <NA>  <NA>
4     4  <NA>
5     8  <NA>
6     8  <NA>
7     8  <NA>
8     8  <NA>
9     9  <NA> 

Output of pd.show_versions()

INSTALLED VERSIONS

commit : f2c8480
python : 3.8.5.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : Intel64 Family 6 Model 165 Stepping 2, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : Danish_Denmark.1252

pandas : 1.2.3
numpy : 1.18.5
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.4
setuptools : 50.3.1.post20201107
Cython : None
pytest : None
hypothesis : None
sphinx : 3.5.1
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.19.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.2
numexpr : None
odfpy : None
openpyxl : 3.0.5
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.5.2
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@enryH enryH added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 5, 2021
@attack68 attack68 added the IO JSON read_json, to_json, json_normalize label Mar 5, 2021
@attack68
Copy link
Contributor

attack68 commented Mar 5, 2021

can you provide more descriptive title

@enryH enryH changed the title BUG: (hopefully) BUG: missing values encoded in pandas.Int64Dtype not supported by json table scheme Mar 5, 2021
@lithomas1 lithomas1 added the NA - MaskedArrays Related to pd.NA and nullable extension arrays label Mar 6, 2021
@lithomas1
Copy link
Member

xref #29752
cc @jorisvandenbossche

@lithomas1 lithomas1 removed the Needs Triage Issue that has not been reviewed by a pandas team member label Mar 25, 2021
@lithomas1 lithomas1 self-assigned this Mar 25, 2021
@lithomas1 lithomas1 removed their assignment Apr 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO JSON read_json, to_json, json_normalize NA - MaskedArrays Related to pd.NA and nullable extension arrays
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants