-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: csv newline \n \r\n in Window with opened file #37757
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
Comments
thanks @noklam for your report! As a potential temporary workaround, do you mind testing with fs.open('iris_fsspec.csv', 'wb') as f:
df.to_csv(f) |
@twoertwein It will throws error instead.
|
yes, sorry - binary handles will be supported in 1.2. I feel that this workaround might give you the same result as without the This issue doesn't seem to happen on Linux. |
this old issue seems to describing the problem. the careiage return somehow get converted |
Is there |
@twoertwein No.
I updated the issue as I found the problem is not specific for This suffers from the same problem.
|
https://github.com/pandas-dev/pandas/blob/master/pandas/core/generic.py#L3220-L3224 Pandas doc actually mention if opening a file, it should be opened with newline='', any idea why is that ? This seems fix the problem |
Probably it comes from this: https://docs.python.org/3/library/csv.html#csv.writer |
thanks @ivanovmg, so I think this is not a bug. specifying the newline should be the solution, |
Should we close this issue then? |
I have checked that this issue has not already been reported.
Related issue: Saving and reloading a csv on Windows with a \n-character in a field replaces \n with \r\n. #22497, the issues looks related, but it is 2 years old and does not have any update.
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
https://github.com/noklam/fsspec_pandas_bug_demo # if you need to download the data
Problem description
The output csv behavior is inconsistent
Expected Output
Expected to have identical output.
Output of
pd.show_versions()
[paste the output of
pd.show_versions()
here leaving a blank line after the details tag]OS: Window 10
INSTALLED VERSIONS
commit : 67a3d42
python : 3.8.2.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.17763
machine : AMD64
processor : Intel64 Family 6 Model 85 Stepping 4, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : English_Hong Kong SAR.1252
pandas : 1.1.4
numpy : 1.19.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1
setuptools : 46.3.1.post20200515
Cython : None
pytest : None
hypothesis : None
sphinx : 3.2.1
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10.3
IPython : 7.15.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 0.6.3
fastparquet : None
gcsfs : None
matplotlib : 3.3.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 0.17.1
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 1.3.17
tables : None
tabulate : 0.8.7
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: