-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Fix default encoding for CSVFormatter.save #17821
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: Fix default encoding for CSVFormatter.save #17821
Conversation
6e725bc
to
8263456
Compare
Codecov Report
@@ Coverage Diff @@
## master #17821 +/- ##
==========================================
- Coverage 91.26% 91.24% -0.03%
==========================================
Files 163 163
Lines 49980 49985 +5
==========================================
- Hits 45613 45607 -6
- Misses 4367 4378 +11
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #17821 +/- ##
==========================================
- Coverage 91.26% 91.2% -0.06%
==========================================
Files 163 163
Lines 49980 50019 +39
==========================================
+ Hits 45613 45621 +8
- Misses 4367 4398 +31
Continue to review full report at Codecov.
|
pandas/io/formats/format.py
Outdated
writer_kwargs['encoding'] = self.encoding | ||
self.writer = UnicodeWriter(f, **writer_kwargs) | ||
else: | ||
if encoding is 'ascii': |
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.
String equality check instead of identity check (i.e. use ==
).
df = DataFrame({'col': [u"AAAAA", u"ÄÄÄÄÄ", u"ßßßßß", u"聞聞聞聞聞"]}) | ||
|
||
with tm.ensure_clean('test.csv') as path: | ||
if pd.compat.PY2: |
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.
Add a comment about why we're raising an error and what should be done to avoid this error (i.e. the encoding
argument parameter should be correct).
8263456
to
0cd7bf7
Compare
@gfyoung Thanks for your review. Fixed! |
else: | ||
encoding = 'utf-8' | ||
else: | ||
encoding = self.encoding |
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.
Not sure if this is overkill, but you can do encoding = self.encoding or ('ascii' if compat.PY2 else 'utf-8')
to condense this whole block of if-else logic.
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.
IMO, matter of taste here. I prefer the block-logic because its easier to read I find.
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.
see comments
AFAICT, none of those issues were closed by this one. |
Sorry, I also added the whatsnew note |
@jreback @TomAugspurger This PR does not solve these issue, I think. |
The CI failure here was from the matplotlib 2.1 release. It'll be fixed when the merge commit is tested. Thanks @Licht-T |
* BUG: Fix default encoding for CSVFormatter.save * TST: Add to_csv defualt encoding test * DOC: Add comments on to_csv defualt encoding test * DOC: added release note * DOC: Add the fixing to_csv default encoding to whatsnew note * Revert "DOC: Add the fixing to_csv default encoding to whatsnew note" This reverts commit 039f2cf.
* BUG: Fix default encoding for CSVFormatter.save * TST: Add to_csv defualt encoding test * DOC: Add comments on to_csv defualt encoding test * DOC: added release note * DOC: Add the fixing to_csv default encoding to whatsnew note * Revert "DOC: Add the fixing to_csv default encoding to whatsnew note" This reverts commit 039f2cf.
* BUG: Fix default encoding for CSVFormatter.save * TST: Add to_csv defualt encoding test * DOC: Add comments on to_csv defualt encoding test * DOC: added release note * DOC: Add the fixing to_csv default encoding to whatsnew note * Revert "DOC: Add the fixing to_csv default encoding to whatsnew note" This reverts commit 039f2cf.
git diff upstream/master -u -- "*.py" | flake8 --diff