Skip to content
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

Option to autocreate folders if path does not exist #13

Open
chendaniely opened this issue Jul 15, 2020 · 2 comments
Open

Option to autocreate folders if path does not exist #13

chendaniely opened this issue Jul 15, 2020 · 2 comments

Comments

@chendaniely
Copy link
Owner

While here was mainly used to read data. It's also useful to write data to locations.

However, it's a little clunky to create folders before using here.
For example:

pl.Path(here("./data/f1/f2/n1/n1", warn=False)).mkdir(parents=True, exist_ok=True)
df.to_csv(here("./data/f1/f2/n1/n1/data.csv", warn=False))

Will make sure all the folders for "./data/f1/f2/n1/n1" are created first before writing.
We can save on the explicit pathlib import and make the save a single line if here contains an option akin to create_dirs=True.
It would turn the above code into.

df.to_csv(here("./data/f1/f2/n1/n1/data.csv", create_dirs=True))

The create_dirs parameter would also set warn=False automatically (since you're most likely going to use this idiom to write to a new file).

@majidaldo
Copy link

Not sure this is a good idea and in here()'s scope. Should be the user's responsibility to create the context for here() to work. It's already a one-liner to pl.Path(here("./data/f1/f2/n1/n1", warn=False)).mkdir(parents=True, exist_ok=True). Have the user go through the mkdir ceremony.

@jamesmyatt
Copy link
Contributor

I don't think this is in scope

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants