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
BUG: read_csv - file left open after UnicodeDecodeError when sep=None #39024
Comments
thank you for the example! When I run your code on linux, it doesn't even end up in the except branch. I only get a warning that, the python engine should be used:
Running the code with edit: when you run the code without |
I found a different example which fails for a different reason ( import os
from pathlib import Path
import pandas
file = Path("non-utf8.csv")
file.write_bytes(b"\xe4\na\n1") # non utf-8 character
dataframe = pandas.read_csv(file, engine="python", sep=None) sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='non-utf8.csv' mode='r' encoding='utf-8'> |
@twoertwein thanks for looking into this!
Yes,
Yes,
|
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
Problem description
os.remove
raises a PermissionError on Windows because apparently the file handle is still open. This only happens when thesep=None
kwarg is used. Leaving out that kwarg gets the expected output.Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : 3e89b4c
python : 3.7.9.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : AMD64 Family 23 Model 1 Stepping 1, AuthenticAMD
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : None.None
pandas : 1.2.0
numpy : 1.19.2
pytz : 2020.5
dateutil : 2.8.1
pip : 20.2.4
setuptools : 49.6.0.post20201009
Cython : 0.29.21
pytest : 6.1.1
hypothesis : None
sphinx : 3.2.1
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : 1.3.0
numba : None
The text was updated successfully, but these errors were encountered: