Skip to content

read_json segfaults with Python 3.7 #22817

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

Closed
hmgaudecker opened this issue Sep 24, 2018 · 5 comments
Closed

read_json segfaults with Python 3.7 #22817

hmgaudecker opened this issue Sep 24, 2018 · 5 comments
Labels
Compat pandas objects compatability with Numpy or Python functions IO JSON read_json, to_json, json_normalize Segfault Non-Recoverable Error

Comments

@hmgaudecker
Copy link

Code Sample, a copy-pastable example if possible

Python 3.7.0 (default, Jun 28 2018, 13:15:42) 
[GCC 7.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
>>> pd.__version__
'0.23.4'
>>> pd.read_json(
...     '''{
...         "tsk_buy_sell": "Wie häufig kommt Einkaufen / Beschaffen / Verkaufen bei Ihrer Arbeit vor?",
...         "tsk_consult": "Wie häufig kommt Beraten / Informieren bei Ihrer Arbeit vor?",
...         "tsk_hospitality": "Wie häufig kommt Bewirten / Beherbergen / Speisenbereiten bei Ihrer Arbeit vor?",
...         "tsk_information_search": "Wie häufig kommt Informationen sammeln / Recherchieren / Dokumentieren bei Ihrer Arbeit vor?",
...         "tsk_law": "Gesetze auslegen, Vorschriften anwenden",
...         "tsk_marketing_pr": "Werben, Marketing oeffentlichkeitsarbeit, PR",
...         "tsk_operate": "Wie häufig kommt Überwachen / Steuern von Maschinen / Anlagen / techn. Prozessen bei Ihrer Arbeit vor?",
...         "tsk_organise": "Wie häufig kommt Organisieren / Planen und Vorbereiten von Arbeitsprozessen bei Ihrer Arbeit vor?",
...         "tsk_persuade": "Wie häufig müssen Sie andere überzeugen und Kompromisse aushandeln?",
...         "tsk_produce": "Wie häufig kommt Herstellen / Produzieren von Waren und Gütern bei Ihrer Arbeit vor?",
...         "tsk_quality_check": "Wie häufig kommt Messen / Prüfen / Qualitätskontrolle bei Ihrer Arbeit vor?",
...         "tsk_repair": "Wie häufig kommt Reparieren / Instandsetzen bei Ihrer Arbeit vor?",
...         "tsk_research_construct": "Wie häufig kommt Entwickeln / Forschen / Konstruieren bei Ihrer Arbeit vor?",
...         "tsk_supervision": "Haben Sie Mitarbeiter und Mitarbeiterinnen, für die Sie direkte Vorgesetzte sind?",
...         "tsk_teach": "Wie häufig kommt Ausbilden / Lehren / Unterrichten / Erziehen bei Ihrer Arbeit vor?",
...         "tsk_means_of_transportation": "Arbeit mit Transportmitteln"
...     }''',
...     typ='series',
...     orient='index'
... )
tsk_buy_sell                   Wie häufig kommt Einkaufen / Beschaffen / Verk...
tsk_consult                    Wie häufig kommt Beraten / Informieren bei Ihr...
tsk_hospitality                Wie häufig kommt Bewirten / Beherbergen / Spei...
tsk_information_search         Wie häufig kommt Informationen sammeln / Reche...
tsk_law                                  Gesetze auslegen, Vorschriften anwenden
tsk_marketing_pr                    Werben, Marketing oeffentlichkeitsarbeit, PR
tsk_operate                    Wie häufig kommt Überwachen / Steuern von Masc...
tsk_organise                   Wie häufig kommt Organisieren / Planen und Vor...
tsk_persuade                   Wie häufig müssen Sie andere überzeugen und Ko...
tsk_produce                    Wie häufig kommt Herstellen / Produzieren von ...
tsk_quality_check              Wie häufig kommt Messen / Prüfen / Qualitätsko...
tsk_repair                     Wie häufig kommt Reparieren / Instandsetzen be...
tsk_research_construct         Wie häufig kommt Entwickeln / Forschen / Konst...
tsk_supervision                Haben Sie Mitarbeiter und Mitarbeiterinnen, fü...
tsk_teach                      Wie häufig kommt Ausbilden / Lehren / Unterric...
tsk_means_of_transportation                          Arbeit mit Transportmitteln
dtype: object
>>> 
Segmentation fault (core dumped)

Expected Output

Same thing, without the segfault. Everything works fine in a Python 3.6 conda environment.

Also noted by @bsolomon1124 in #11344

Output of pd.show_versions()

commit: None
python: 3.6.6.final.0
python-bits: 64
OS: Linux
OS-release: 4.13.0-46-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.23.4
pytest: None
pip: 10.0.1
setuptools: 40.2.0
Cython: None
numpy: 1.15.1
scipy: None
pyarrow: None
xarray: None
IPython: 6.5.0
sphinx: 1.7.9
patsy: None
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 1.0.1
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@troels
Copy link
Contributor

troels commented Sep 25, 2018

Hi @hmgaudecker

I can replicate this, but the problem doesn't seem to be in the json-module. The following small program coredumps for me:

import pandas as pd

s = pd.Series(['Wie häufig kommt Beraten / Informieren bei Ihrer Arbeit vor?'], dtype='object')
s.astype('float64')

Small variations make it stop crashing. I believe something is writing to a stray pointer, perhaps inside of numpy. Likely somehow related to the ä-character, but I can't quite pinpoint how.

@hmgaudecker
Copy link
Author

Great, thanks. So the problem is that read_json attempts a type conversion internally and only continues with the object dtype upon failure?

@troels
Copy link
Contributor

troels commented Sep 25, 2018

Well, the problem is that somewhere on the way to detecting what type actually is in the columns, pandas or numpy fails in their memory handling. Either by writing outside an area of memory they have allocated or by e.g. freeing some memory that is still is being used. The bug is in C or Cython-code but not in the json-module.

My example code is just supposed to throw an exception, not dump core.

@troels
Copy link
Contributor

troels commented Sep 27, 2018

This is in fact a cpython 3.7.0 bug in float() and will be fixed in python 3.7.1, which will be released in a week or two:

https://bugs.python.org/issue34087

@jbrockmendel jbrockmendel added Compat pandas objects compatability with Numpy or Python functions IO JSON read_json, to_json, json_normalize labels Sep 29, 2018
@jbrockmendel jbrockmendel added the Segfault Non-Recoverable Error label Nov 9, 2018
@WillAyd
Copy link
Member

WillAyd commented Apr 15, 2019

Closing as this was a Python bug which has since been resolved

@WillAyd WillAyd closed this as completed Apr 15, 2019
@WillAyd WillAyd added this to the No action milestone Apr 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat pandas objects compatability with Numpy or Python functions IO JSON read_json, to_json, json_normalize Segfault Non-Recoverable Error
Projects
None yet
Development

No branches or pull requests

4 participants