Skip to content

Make to_csv return a string if no path or buffer is provided. #6406

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
Mar 9, 2014

Conversation

filmor
Copy link
Contributor

@filmor filmor commented Feb 19, 2014

Fixes #6061.

@jreback
Copy link
Contributor

jreback commented Feb 19, 2014

this needs a test to validate that the return value is in fact a string.

@@ -943,7 +943,7 @@ def grouper(x):

class CSVFormatter(object):

def __init__(self, obj, path_or_buf, sep=",", na_rep='', float_format=None,
def __init__(self, obj, buf=None, sep=",", na_rep='', float_format=None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't change this argument name, leave it as is

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it sensible to have this the same in all formatters?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the other ones are wrong actually (see to_hdf,to_msgpack,to_json). Those I agree their is some incosistency. put back the path_or_buf...I'll make an issue to harmonize the rest of them (it doesn't matter much really because you are rarely specifying this by kw).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually it IS pretty consistent with path_or_buf, except for the ones which only (current) take a fname, e.g. to_stat, and to_excel. all the others take just a buffer

@filmor
Copy link
Contributor Author

filmor commented Mar 1, 2014

I added a test and reverted to the path_or_buf argument.

@jreback jreback added this to the 0.14.0 milestone Mar 1, 2014
@jreback
Copy link
Contributor

jreback commented Mar 1, 2014

@jorisvandenbossche @cpcloud think we need any more tests on this?

@jreback
Copy link
Contributor

jreback commented Mar 9, 2014

can you add a release note (API section on this)

@filmor
Copy link
Contributor Author

filmor commented Mar 9, 2014

Done.

jreback added a commit that referenced this pull request Mar 9, 2014
Make to_csv return a string if no path or buffer is provided.
@jreback jreback merged commit 391ed32 into pandas-dev:master Mar 9, 2014
@jreback
Copy link
Contributor

jreback commented Mar 9, 2014

thanks!

@filmor filmor deleted the patch-2 branch March 9, 2014 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement IO CSV read_csv, to_csv Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging this pull request may close these issues.

df.to_csv should mirror df.to_html
2 participants