Skip to content

ENH/BUG: pass formatting params thru to to_csv #5414

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

Merged
merged 1 commit into from
Feb 17, 2014
Merged

ENH/BUG: pass formatting params thru to to_csv #5414

merged 1 commit into from
Feb 17, 2014

Conversation

patricktokeeffe
Copy link
Contributor

Add support for passing remaining csv.writer formatting parameters thru to DataFrame.to_csv().

Maybe write tests for this? That much is over my head currently.

@jtratner
Copy link
Contributor

jtratner commented Nov 2, 2013

Can't just add this...needs to be supported by C parser too (and therefore needs tests, etc)

@patricktokeeffe
Copy link
Contributor Author

Yea, I didn't expect it to be that easy. Is it better etiquette to close this PR and reopen later or just leave it hanging?

@jtratner
Copy link
Contributor

jtratner commented Nov 7, 2013

oh this is to_csv -- just need to put together some tests for this.

@jreback
Copy link
Contributor

jreback commented Dec 5, 2013

does this close an issue?

need tests for this

@patricktokeeffe
Copy link
Contributor Author

I realized this commit was doing two things so I refactored into a separate PR (#6034). I'm still a little lost on what kind of test to make though since these params are just passed internally to com.UnicodeWriter or csv.writer.

The only thing that occurs to me is to write an output file using the new parameters then read it back in and make sure the write occurred correctly. Is that overkill? Any tips or hints what to model the test(s) on?

@patricktokeeffe
Copy link
Contributor Author

This PR seems to cover #4528 too

@patricktokeeffe
Copy link
Contributor Author

I tried using self.assertRaises as a context manager which doesn't work for python2.6. Any tips on compatibility?

@patricktokeeffe
Copy link
Contributor Author

Specifically it fails like this:

Traceback (most recent call last):
  File "/home/travis/virtualenv/python2.6_with_system_site_packages/lib/python2.6/site-packages/pandas/tests/test_format.py", line 1729, in test_to_csv_quotechar
    df.to_csv(path, quoting=1, quotechar=None)
  File "/usr/lib/python2.6/contextlib.py", line 34, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/travis/virtualenv/python2.6_with_system_site_packages/lib/python2.6/site-packages/pandas/util/testing.py", line 372, in ensure_clean
    yield filename
  File "/home/travis/virtualenv/python2.6_with_system_site_packages/lib/python2.6/site-packages/pandas/tests/test_format.py", line 1728, in test_to_csv_quotechar
    with self.assertRaises(TypeError):
TypeError: failUnlessRaises() takes at least 3 arguments (2 given)

@TomAugspurger
Copy link
Contributor

@patricktokeeffe
Copy link
Contributor Author

Thanks @TomAugspurger

@jreback
Copy link
Contributor

jreback commented Feb 16, 2014

@patricktokeeffe pls rebase, and move the release notes to 0.14 section. thanks

which issues does this cover?

- Add `quotechar`, `doublequote`, and `escapechar` parameters
- Add tests for each new param
- Update relevant docs
@patricktokeeffe
Copy link
Contributor Author

@jreback I sent this PR without creating an issue. It does cover #4528 though the idea mentioned there of adding a csv dialect argument is a good one not included in this PR.

jreback added a commit that referenced this pull request Feb 17, 2014
ENH/BUG: pass formatting params thru to `to_csv`
@jreback jreback merged commit 973e076 into pandas-dev:master Feb 17, 2014
@jreback
Copy link
Contributor

jreback commented Feb 17, 2014

thanks nice little fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design IO CSV read_csv, to_csv IO Data IO issues that don't fit into a more specific label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants