-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Index lost when serializing to json #42152
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
Comments
The JSON table schema spec requires that the set of fields forming the primary key is unique: https://specs.frictionlessdata.io/table-schema/#missing-values I am surprised that we don't raise a |
Thanks @TomAugspurger for the explanation. It makes sense to have a well designed primary key in a table. I can solve my problem by redesigning the index. However this means that not all valid pandas |
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.
When serializing a pandas
DataFrame
to json the index is usally serialized by use of theprimary_key
in the json. In some cases this does not work. For example:The json string
js
:The
new
data frame created by reading the json doesn't have the same index.Output of
pd.show_versions()
INSTALLED VERSIONS
commit : 2cb9652
python : 3.8.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-74-generic
Version : #83-Ubuntu SMP Sat May 8 02:35:39 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.2.4
numpy : 1.20.2
pytz : 2019.3
dateutil : 2.7.3
pip : 21.1.1
setuptools : 45.2.0
Cython : None
pytest : 6.2.4
hypothesis : None
sphinx : 3.5.4
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.13.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 2021.04.0
fastparquet : None
gcsfs : None
matplotlib : 3.4.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.6.3
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: