read_json with table='orient' causes unexpected type coercion · Issue #21345 · pandas-dev/pandas (original) (raw)

Code Sample, a copy-pastable example if possible

import pandas as pd

df = pd.DataFrame([[1., 2., 3.], [1., 2., 3.], [1., 2., 3.]], columns=['a', 'b', 'c']) out = df.to_json(orient='table') result = pd.read_json(out, orient='table') pd.testing.assert_frame_equal(df, result)

Problem description

Assertion fails with error:

Attribute "dtype" are different
[left]:  float64
[right]: int64

Error is related to this method: https://github.com/pandas-dev/pandas/blob/master/pandas/io/json/json.py#L659

Expected Output

Expected result is passing assertion. Original DF and the JSON round-tripped DF should have same dtype.

Output of pd.show_versions()

INSTALLED VERSIONS

commit: 2461b90
python: 3.6.4.final.0
python-bits: 64
OS: Darwin
OS-release: 16.7.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.24.0.dev0+72.g2461b90a1.dirty
pytest: 3.6.0
pip: 9.0.1
setuptools: 28.8.0
Cython: 0.28.3
numpy: 1.14.3
scipy: 1.1.0
pyarrow: 0.9.0.post1
xarray: 0.10.6
IPython: 6.4.0
sphinx: 1.7.5
patsy: None
dateutil: 2.7.3
pytz: 2018.4
blosc: 1.5.1
bottleneck: 1.2.1
tables: 3.4.3
numexpr: 2.6.5
feather: 0.4.0
matplotlib: 2.2.2
openpyxl: 2.5.3
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.5
lxml: 4.2.1
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.2.8
pymysql: 0.8.1
psycopg2: None
jinja2: 2.10
s3fs: 0.1.5
fastparquet: 0.1.5
pandas_gbq: None
pandas_datareader: None