BUG: strange string causes segmentation fault on df.to_json · Issue #50307 · pandas-dev/pandas (original) (raw)

Pandas version checks

Reproducible Example

import pandas as pd string = chr(56000) print(repr(string)) # This is a valid Python string, but can't be printed normally df = pd.DataFrame({'A': [string]}) df.to_json()

Issue Description

When I run this from the command line, it causes a segmentation fault:

zsh: segmentation fault  python main.py

Expected Behavior

It should not segmentation fault. Perhaps it throws some error saying it can't to_json it, but it probably shouldn't crash the whole Python runtime (e.g. you can't even recover with a try catch).

Installed Versions

INSTALLED VERSIONS

commit : 8dab54d
python : 3.9.9.final.0
python-bits : 64
OS : Darwin
OS-release : 21.6.0
Version : Darwin Kernel Version 21.6.0: Wed Aug 10 14:28:23 PDT 2022; root:xnu-8020.141.5~2/RELEASE_ARM64_T6000
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.5.2
numpy : 1.23.5
pytz : 2022.6
dateutil : 2.8.2
setuptools : 56.0.0
pip : 21.2.4
Cython : None
pytest : 7.2.0
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.0.2
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.7.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : 3.0.10
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None