-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Fix line_terminator option #23608
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
Conversation
Hello @BenRussert! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on January 16, 2019 at 06:09 Hours UTC |
This line won't ever reach 'os.linesep' if the default argument is '\n'. I noticed the issue because windows to_csv, and to_clipboard write I've only tried the tests locally on ubuntu, but I wonder if this will break tests for people running on windows if |
Codecov Report
@@ Coverage Diff @@
## master #23608 +/- ##
=======================================
Coverage 92.38% 92.38%
=======================================
Files 166 166
Lines 52358 52358
=======================================
Hits 48373 48373
Misses 3985 3985
Continue to review full report at Codecov.
|
@BenRussert : Good start! Definitely going to need some tests. |
@BenRussert can you add some tests for this |
b192086
to
f3deb4e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor nits on my end. FYI if you merge master going forward you shouldn't need to force push changes which makes tracking easier
@@ -30,7 +30,7 @@ class CSVFormatter(object): | |||
def __init__(self, obj, path_or_buf=None, sep=",", na_rep='', | |||
float_format=None, cols=None, header=True, index=True, | |||
index_label=None, mode='w', nanRep=None, encoding=None, | |||
compression='infer', quoting=None, line_terminator='\n', | |||
compression='infer', quoting=None, line_terminator=None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is going to need a doc-string versionchanged, and an update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On closer look, #24290 covered this. In fact, the same PR may have corrected the entire issue as long as the CSVFormatter
class is always called with line_terminator=None
.
I made a minor docs update to reflect that PR, let me know if you had something else in mind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the reference issue is off? in any event, your change looks fine.
is there an associated issue? |
can you merge master |
@jreback DId you want me to push a merge commit? Or rebase and force? |
the former |
@@ -561,3 +561,20 @@ def test_to_csv_compression(self, compression_only, | |||
result = pd.read_csv(path, index_col=0, | |||
compression=read_compression) | |||
tm.assert_frame_equal(result, df) | |||
|
|||
|
|||
def test_csv_formatter_line_terminator_default(monkeypatch): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than this, can you just modify the appropriate tests to pass in ['\n', os.linesep, None] as parameters (we might already have this)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modify the appropriate tests to pass
@jreback There isn't an existing test of the CSVFormatter
directly.
The intent of the PR is to ensure that if no line_terminator
is specified, the default is os.linesep
. Currently, CSVFormatter
must be called with line_terminator=None
or else \n
will be used.
When I opened this PR, I was looking at v0.24.3
, so I didn't realize the bug had been fixed in #21406 by calling the CSVFormatter
class with line_terminator=None
. I thought I might as well continue the PR so future devs don't have to remember to call CSVFormatter(line_terminator=None)
if they expect the platform specific os.linesep
behavior. Since most devs use \n
platforms, it would be easy to miss this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think this test is necessary and slightly confusing, can you remove.
@@ -30,7 +30,7 @@ class CSVFormatter(object): | |||
def __init__(self, obj, path_or_buf=None, sep=",", na_rep='', | |||
float_format=None, cols=None, header=True, index=True, | |||
index_label=None, mode='w', nanRep=None, encoding=None, | |||
compression='infer', quoting=None, line_terminator='\n', | |||
compression='infer', quoting=None, line_terminator=None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the reference issue is off? in any event, your change looks fine.
@@ -561,3 +561,20 @@ def test_to_csv_compression(self, compression_only, | |||
result = pd.read_csv(path, index_col=0, | |||
compression=read_compression) | |||
tm.assert_frame_equal(result, df) | |||
|
|||
|
|||
def test_csv_formatter_line_terminator_default(monkeypatch): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think this test is necessary and slightly confusing, can you remove.
@BenRussert can you update your OP to reflect which issue this addresses? Somewhat confused reading through the comments as to what problem this solves |
I'll just close and say that #24290 fixed what I was going after. The default argument vs calling with |
git diff upstream/master -u -- "*.py" | flake8 --diff