Skip to content

BUG: sys.setprofile breaks read_csv #41069

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
2 of 3 tasks
PetrochukM opened this issue Apr 21, 2021 · 1 comment · Fixed by #41105
Closed
2 of 3 tasks

BUG: sys.setprofile breaks read_csv #41069

PetrochukM opened this issue Apr 21, 2021 · 1 comment · Fixed by #41105
Labels
Bug IO CSV read_csv, to_csv
Milestone

Comments

@PetrochukM
Copy link

  • 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

@PetrochukM PetrochukM added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 21, 2021
@mzeitlin11
Copy link
Member

Thanks for the report @PetrochukM! Can confirm on master, this is pretty strange indeed

@mzeitlin11 mzeitlin11 added IO CSV read_csv, to_csv and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 22, 2021
@jreback jreback added this to the 1.3 milestone Apr 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO CSV read_csv, to_csv
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants