-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
read_json changes dtype (int => float) #12866
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
both other orients recover this, I don't know why
|
Indeed, I would be interested in understanding the reason of the different behaviour for |
The default
So this is as expected unless the default of converting object types to float when deserialising is changed. Could attempt |
@Komnomnomnom right, do we know its an part of an index at that point? (I don't remember). actually
|
Yes it is happening after deserialisation (the c code) has finished. It actually does try to convert to In [61]: from pandas import Index
In [62]: data = Index([u'0', u'1', u'2'], dtype='object')
In [63]: data.astype('float64').astype('int64')
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-63-7bbb22a22b83> in <module>()
----> 1 data.astype('float64').astype('int64')
/home/kieran/.virtualenvs/py27/lib/python2.7/site-packages/pandas/core/index.pyc in astype(self, dtype)
3828 raise TypeError('Setting %s dtype to anything other than '
3829 'float64 or object is not supported' %
-> 3830 self.__class__)
3831 return Index(self._values, name=self.name, dtype=dtype)
3832
TypeError: Setting <class 'pandas.core.index.Float64Index'> dtype to anything other than float64 or object is not supported |
@Komnomnomnom sorry, that is a bug. let me create another issue for that. |
Hi there!
This might be a well-known problem but could not find a track/explaination about it. When reading a json to create a pandas object (Series or DataFrame), the index dtype is changed from int to float.
The doc only mentions the inverse trans-typing:
Is this behaviour expected as well? Is the only solution giving the
read_json
adtype
argument?Code Sample, a copy-pastable example if possible
Expected Output
I would like to recover the integer index for the new
Series
:Output of
pd.show_versions()
Thanks!
The text was updated successfully, but these errors were encountered: