Skip to content

to_json raises 'Unhandled numpy dtype 15' with complex values. #12554

@gregory-marton

Description

@gregory-marton

Code Sample, a copy-pastable example if possible

import pandas
df = pandas.DataFrame({'a': [complex(3, -1)]})
df.to_json()

Expected Output

'{"a":{"0":3-1j}}'

Actual output:

--------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) <ipython-input-3-b53888fd1707> in <module>() ----> 1 df.to_json() .../lib/python2.7/site-packages/pandas/core/generic.pyc in to_json(self, path_or_buf, orient, date_format, double_precision, force_ascii, date_unit, default_handler) 892 force_ascii=force_ascii, 893 date_unit=date_unit, --> 894 default_handler=default_handler) 895 896 def to_hdf(self, path_or_buf, key, **kwargs): .../lib/python2.7/site-packages/pandas/io/json.pyc in to_json(path_or_buf, obj, orient, date_format, double_precision, force_ascii, date_unit, default_handler) 33 obj, orient=orient, date_format=date_format, 34 double_precision=double_precision, ensure_ascii=force_ascii, ---> 35 date_unit=date_unit, default_handler=default_handler).write() 36 else: 37 raise NotImplementedError("'obj' should be a Series or a DataFrame") .../lib/python2.7/site-packages/pandas/io/json.pyc in write(self) 76 date_unit=self.date_unit, 77 iso_dates=self.date_format == 'iso', ---> 78 default_handler=self.default_handler) 79 80 RuntimeError: Unhandled numpy dtype 15 

output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 2.7.11.final.0 python-bits: 64 OS: Darwin OS-release: 15.0.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_US.UTF-8 pandas: 0.17.1 nose: 1.3.7 pip: 8.0.3 setuptools: 19.7 Cython: 0.23.4 numpy: 1.8.2 scipy: 0.15.1 statsmodels: 0.6.1 IPython: 4.0.1 sphinx: 1.3.3 patsy: 0.4.1 dateutil: 2.4.2 pytz: 2015.7 blosc: None bottleneck: None tables: None numexpr: None matplotlib: 1.4.3 openpyxl: None xlrd: None xlwt: None xlsxwriter: None lxml: None bs4: None html5lib: None httplib2: None apiclient: None sqlalchemy: None pymysql: None psycopg2: None Jinja2: None 

Metadata

Metadata

Assignees

No one assigned

    Labels

    ComplexComplex NumbersDtype ConversionsUnexpected or buggy dtype conversionsIO JSONread_json, to_json, json_normalizeNeeds DiscussionRequires discussion from core team before further action

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions