Skip to content

ENH: tilde expansion for write functions, #11438 #11458

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

Closed
wants to merge 1 commit into from
Closed

ENH: tilde expansion for write functions, #11438 #11458

wants to merge 1 commit into from

Conversation

aechase
Copy link
Contributor

@aechase aechase commented Oct 28, 2015

closes #11438
Added calls to _expand_user() in multiple Formatter classes so that writer functions, such as to_csv() and to_html(), can perform tilde expansion on file paths beginning ~/. This makes the writer functions consistent with the reader functions, such as read_csv(). I also changed the __init__() for CSVFormatter to conform to the pep8 width limit.

@jreback
Copy link
Contributor

jreback commented Oct 28, 2015

tests pls

@jreback jreback changed the title ENH: tilde expansion for write functions GH11438 ENH: tilde expansion for write functions, #11438 Oct 28, 2015
@jreback jreback added Enhancement IO Data IO issues that don't fit into a more specific label labels Oct 28, 2015
class CategoricalFormatter(object):

def __init__(self, categorical, buf=None, length=True,
na_rep='NaN', footer=True):
self.categorical = categorical
self.buf = buf if buf is not None else StringIO(u(""))
self.buf = _expand_user(self.buf)
Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't belong here

@jreback
Copy link
Contributor

jreback commented Oct 28, 2015

actually on 2nd thought.

I think you these should ONLY be used in core/frame.py/DataFrame.to_csv and to_html

I don't really like this here, as all of the other IO functions are localized in pandas/io/* but that's how it is for now.

@aechase
Copy link
Contributor Author

aechase commented Oct 28, 2015

I had the same thought, but then I assumed that would cause problems for Series.to_csv(). But, having now checked the code, I see that they are the same function, with each Series being temporarily converted to a DataFrame.

Should I put the _expand_user() calls in frame.py?

Regarding the tests: let me start out by saying that I am oh-so-close to being out of my depth here. The current suite seems to run OK (various DeprecationWarnings and RuntimeWarnings notwithstanding), but I'm a bit unclear as to how (or whether) I should create a new test function. That function would need to write and read some temporary files, but it looks like it would be difficult, if not impossible, to use testing.ensure_clean() to generate expanded and non-expanded file paths.

@jreback
Copy link
Contributor

jreback commented Oct 28, 2015

you might have a look at these: https://github.com/pydata/pandas/blob/master/pandas/io/tests/test_common.py

yeh this might be quite tricky to test

@jreback
Copy link
Contributor

jreback commented Nov 18, 2015

can you add a release note and we'll stick in 0.17.1

@jreback jreback added this to the 0.17.1 milestone Nov 18, 2015
Closes GH11438

Enables DataFrame.to_csv(), .to_html() and .to_latex() to perform tilde expansion on file paths.
@aechase
Copy link
Contributor Author

aechase commented Nov 19, 2015

@jreback looks like I might have caused some trouble editing the most recent version of the release notes file...

@jreback
Copy link
Contributor

jreback commented Nov 19, 2015

merged via ea758cd

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement 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.

Tilde expansion for paths (~/...) inconsistent between read_csv and to_csv
2 participants