Skip to content

ENH: Create directories when missing in to_* methods #42255

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 10 commits into from

Conversation

rgkimball
Copy link

@rgkimball rgkimball commented Jun 26, 2021

This is the most fundamental approach to creating new folders when a user specifies a path that is missing in file creation methods like to_csv, to_excel, to_feather etc. We can do this in io/common.py:get_handle() conditionally when the file buffer provided is in a writable mode.

@feefladder
Copy link
Contributor

feefladder commented Jun 26, 2021

So do we want default behaviour to be that directories are always created or an extra argument like mkdirs=True that needs to be passed? I tried to do it that way, but passing the argument through gave a lot of changes, and I thought the conclusion from #24306 was to just add it to the documentation. However, I think the change in behaviour is most welcome 🎉

I can add that to the documentation. Then that would be in all to_something that can be a file?

@rgkimball
Copy link
Author

Exposing an argument to control this might be helpful and shouldn't be too much work (and would allow us to reinstate the two tests I removed). I'll defer to the maintainers as to whether this should be on or off by default, but I agree that changing these to create missing directories by default is much more intuitive for novice users.

@feefladder
Copy link
Contributor

Then I'll also wait with the documentation until this is resolved :)

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

so I would start with a note in the docs about this

would also accept a better error message for cases like this (not sure how hard this is to detect that if you create the parent folders). (separate PR)

I don't think automatic creation of directories is a great idea to do so automatically, so after the 2 above could consider via a keyword (yes some work for this). but please propose before you do the PR.

@jreback jreback added the IO Data IO issues that don't fit into a more specific label label Jul 1, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Aug 1, 2021

This pull request is stale because it has been open for thirty days with no activity. Please update or respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Aug 1, 2021
@mroeschke
Copy link
Member

Thanks for the PR, but as mentioned, the team isn't keen on supporting an API that creates directories and instead would prefer a documentation approach like in https://github.com/pandas-dev/pandas/pull/42250/files. Closing.

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

Successfully merging this pull request may close these issues.

to_csv - allow to create folders.
4 participants