Closed hayd closed 11 years ago
was a bug, but ran into another feature/bug
here's my new test:
df = pd.read_csv('https://raw.github.com/hayd/lahman2012/master/csvs/Teams.csv')
s = df.to_json()
result = pd.read_json(s)
result.index = result.index.astype(int)
result = result.reindex(columns=df.columns,index=df.index)
assert_frame_equal(result,df)
so, I am not sure json guarantees order? and should I try to do automatic index conversion on other types (I am doing it on datetimes now)?
Guess it's not so surprising, python dictionaries don't... (I don't think?). Quite a big file to test against!
Not sure, what were you thinking?
I think @cpcloud had sort of the same problem in html, he added infer_types
kw....now I am doing that for dates now; I mean its not hard to do a soft conversion, e.g. no forcing......
do all valid json objects have a total ordering in python? if they do why not guarantee ordering, unless of course that goes against json spec...
python dicts don't because there are hashable objects that don't define an ordering eg complex numbers, custom objects, among other erasons
Hmmm, different bug?
In [5]: pd.read_json('[{"a": 1, "b": 2}, {"b":2, "a" :1}]')
Out[5]:
0 1
a 1 2
b 2 1
which one is more useful to round-trip exactly?
biggie = DataFrame(np.zeros((200, 4)),
columns=[str(i) for i in range(4)],
index=[str(i) for i in range(200)])
biggie2 = DataFrame(np.zeros((200,4)),
columns=range(4),
index=range(200))
@cpcloud any thoughts?
roundtrip doesn't look like it can be invertible...they both json'd the same because of json's rules about keys in objects (must be string).
I am going to setup some options so the second will roundtrip hence convert_axes=True
while the 1st will work if you pass convert_axes=False
this might present a problem for nested json, no? that's a different beast though so for "frame/series-able" json that's probably ok
conversion is done at the end so should worl
fixed by #3876
closing this as incorporated in #3876
This csv (from the baseball database) reads ok to a DataFrame, pastes ok to a json.
cc #3804