-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Closed
Labels
Compatpandas objects compatability with Numpy or Python functionspandas objects compatability with Numpy or Python functionsDtype ConversionsUnexpected or buggy dtype conversionsUnexpected or buggy dtype conversionsEnhancement
Milestone
Description
Noticed this in Pandas v0.16.1 when JSON serializing a large nested dictionary containing mixes of arrays, numpy arrays, and pandas series. Calling tolist() on numpy arrays allows the standard library JSON serializer to serialize them, but this is not the case for pandas.
numpy.array.tolist converts all of the array's contents to native Python datatypes. For compatibility with numpy, pandas.Series.tolist should also convert its contents to native Python datatypes. Currently, the list returned by pandas contains elements which have types like numpy.int64 or numpy.float64.
For example:
>>> from pandas
>>> import numpy
>>> np_array = numpy.array([1, 2, 3])
>>> pd_series = pandas.Series([1,2,3])
>>> np_list = np_array.tolist()
>>> pd_list = pd_series.tolist()
>>> type(np_list[0])
<class 'int'>
>>> type(pd_list[0])
<class 'numpy.int64'>
Metadata
Metadata
Assignees
Labels
Compatpandas objects compatability with Numpy or Python functionspandas objects compatability with Numpy or Python functionsDtype ConversionsUnexpected or buggy dtype conversionsUnexpected or buggy dtype conversionsEnhancement