-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
line terminator issue (again) on windows when writing to_csv() #25048
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
So the reason for this behavior is two-fold:
Admittedly, this is an unfortunate corner case because we have no information going in what the newline terminator should be i.e., how would we know that we should use I'm inclined to suggest that we document this behavior in more detail for Windows because the workaround for your case is clear. Not sure if there is a straightforward fix to make all parties happy here. Thoughts? |
cc @chris-b1 |
Is there some way to introspect a file object for its newlines mode? Not finding an obvious way. I do think we need to fix this |
@chris-b1 : I don't think anyone is disagreeing with you on that. However, having read the documentation for At the very least, something should be documented to address this caveat for Windows if we can't find a way to introspect on a file object. |
Given this was a behavior change in |
This may be related to #25311 |
Are people on-board with documentation this as the expected behavior, and giving guidance for how to avoid it? If so, does anyone have time to put up a PR in time for 0.24.2? |
If we're shooting for next for 0.24.2 , I'll have time this weekend to look. |
It does seem like there isn't a way to work around this. python's documentation puts it on the user to pass |
I am experiencing similar issue when using to_csv to writing dat file to a linux server from my local windows machine. line_terminator does not seem to help. |
@nospoon81 can you give a bit more details? The new explanation added in #25624 does not help? |
Another addition to windows line-end saga:
Changes in Pandas 0.24.0, related to #20353, seem to cause some strange behaviour in this not so uncommom edge case:
Problem description
When using
df.to_csv()
to write to an exisitng file handle without explicitly settingnewline=''
(ornewline='\n'
) in the open statement an extra '\r' is added to the default (on windows) '\r\n' line-end:Expected output
Current output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.7.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 79 Stepping 1, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.24.0
pytest: 4.0.2
pip: 18.1
setuptools: 40.6.3
Cython: 0.29.2
numpy: 1.15.4
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 7.2.0
sphinx: 1.8.2
patsy: 0.5.1
dateutil: 2.7.5
pytz: 2018.7
blosc: None
bottleneck: 1.2.1
tables: 3.4.4
numexpr: 2.6.8
feather: None
matplotlib: 3.0.2
openpyxl: 2.5.12
xlrd: 1.2.0
xlwt: 1.3.0
xlsxwriter: 1.1.2
lxml.etree: 4.2.5
bs4: 4.6.3
html5lib: 1.0.1
sqlalchemy: 1.2.15
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None
The text was updated successfully, but these errors were encountered: