Skip to content

BUG: sys.setprofile breaks read_csv #41069

Closed
@PetrochukM

Description

@PetrochukM
  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

import pathlib
import sys

import pandas

text = """I am able.
One powerful way.
"Trouble concentrating, television?"
"Maybe, or. You and family, or your best work."
assessment!
more about them and help.
"The more you say, the better I'll be"
"""
file_name = "boo.csv"
pathlib.Path(file_name).write_text(text)

pandas.read_csv(file_name, names=("text",))
print("Works!")

sys.setprofile(lambda *a, **k: None)
print("And it's broken...")
pandas.read_csv(file_name, names=("text",))

Problem description

Pandas.read_csv breaks if I run sys.setprofile(lambda *a, **k: None)...

Works!
And it's broken...
Traceback (most recent call last):
  File "bam.py", line 22, in <module>
    pandas.read_csv(file_name, names=("text",))
  File "/Users/michaelp/Code/Text-to-Speech/venv/lib/python3.8/site-packages/pandas/io/parsers.py", line 610, in read_csv
    return _read(filepath_or_buffer, kwds)
  File "/Users/michaelp/Code/Text-to-Speech/venv/lib/python3.8/site-packages/pandas/io/parsers.py", line 468, in _read
    return parser.read(nrows)
  File "/Users/michaelp/Code/Text-to-Speech/venv/lib/python3.8/site-packages/pandas/io/parsers.py", line 1057, in read
    index, columns, col_dict = self._engine.read(nrows)
  File "/Users/michaelp/Code/Text-to-Speech/venv/lib/python3.8/site-packages/pandas/io/parsers.py", line 2496, in read
    alldata = self._rows_to_cols(content)
  File "/Users/michaelp/Code/Text-to-Speech/venv/lib/python3.8/site-packages/pandas/io/parsers.py", line 3189, in _rows_to_cols
    self._alert_malformed(msg, row_num + 1)
  File "/Users/michaelp/Code/Text-to-Speech/venv/lib/python3.8/site-packages/pandas/io/parsers.py", line 2948, in _alert_malformed
    raise ParserError(msg)
pandas.errors.ParserError: Expected 3 fields in line 6, saw 5

Expected Output

read_csv shouldn't be affected by setprofile.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 2cb9652
python : 3.8.8.final.0
python-bits : 64
OS : Darwin
OS-release : 20.3.0
Version : Darwin Kernel Version 20.3.0: Thu Jan 21 00:07:06 PST 2021; root:xnu-7195.81.3~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.2.4
numpy : 1.20.2
pytz : 2021.1
dateutil : 2.8.1
pip : 21.0.1
setuptools : 49.2.1
Cython : None
pytest : 6.2.3
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.22.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.4.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 3.0.0
pyxlsb : None
s3fs : None
scipy : 1.6.2
sqlalchemy : None
tables : None
tabulate : 0.8.9
xarray : None
xlrd : None
xlwt : None
numba : 0.53.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions