-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
Column information lost in to_json() if data frame is empty #7445
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
Thanks @aizvorski I can confirm this bug, and I agree about the expected output. The JSON handling is producing its output by looping over the dataframe values array, which is why in this case the labels end up being ignored during serialisation. @jreback I'm on vacation until mid July but I'll see if I can get this fixed for 0.15. There's also the other JSON issues / features I've been meaning to do since pre 0.14...I'll see if I can knock them out at the same time. |
closed by #9805 >>> pd.DataFrame({'test':[]}, index=[]).to_json(orient='columns')
'{"test":{}}' |
closes pandas-dev#7445 Author: Matt Roeschke <emailformattr@gmail.com> Closes pandas-dev#14893 from mroeschke/test_7445 and squashes the following commits: 740cafe [Matt Roeschke] TST: to_json keeps column info with empty dataframe (pandas-dev#7445)
Create empty dataframe with a column and write it out with to_json(), then read it back in:
I think the expected string is '{"test":{}}'
This situation arises when code filters data frames and writes them out, while not being very careful to make sure the filtered frames contain at least one row.
The text was updated successfully, but these errors were encountered: