-
-
Notifications
You must be signed in to change notification settings - Fork 329
open...() functions should accept pathlib.Path #261
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
Comments
Imagine @martindurant has thoughts on this one. 😉 |
Yeah... Maybe I'm just too old for pathlib, but wouldn't it be easier for the user to coerce the object to str in the line passing it to zarr rather than zarr having to check for another condition? |
Passing pathlib paths around is becoming more common, at least the error message should be something more sane I think (e.g TypeError) |
Note that fsspec does support Path objects now, except they don't really make sense for anything non-local. From zarr's point of view, a Path should probably be assumed to be local, and so invoke the directory-store directly rather than going via fsspec. |
Most software I've been using accepts path objects. Would a minimal pull request be accepted? |
I ran into this issue but got a less intuitive error message: minimal example
error message
|
It's not obvious to me that accepting Path is useful (but I don't use pathlib myself). It is important to note that the path supplied could, in principle, be a remote or other complex path, of the type handles by fsspec, which cannot be represented by Path. The first line of each open functin would then read |
@martindurant Thank you for the clarification! I fully understand that accepting a What do you think? |
I see things like
In general, if you submit arguments with unexpected types to any function in python, strange things might happen. I would think it inappropriate to check the types of the inputs, which would have to be done in every location. Of course, the caveat still applies: I don't use pathlib, so I don't see the benefit (my interior model must predate it). |
@martindurant I see your point. I kind of assume that when a path argument accepts |
I think it could make sens that if we receive a Path, then it should be opened with the directory store. Pathlib is more and more common, and I would strongly recommend it when you know you are working with Path inside libraries; I've personally started to convert most of the libraries I use that take string to work with Path internally, and I'm much happier. We should also consider that Path might be coming from higher up, like someone may be using |
I xarray were to support Path (do they?), I would expect that to be done with
and we would just be repeating this. |
Basic support was released in 2.9.0: https://zarr.readthedocs.io/en/stable/release.html#enhancements I think this can be closed unless there's desire to base more of the internals on |
Thanks, @clbarnes! |
Minimal, reproducible code sample, a copy-pastable example if possible
...gives:
Problem description
Functions that accept a string path for the store argument should also accept Path object.
Version and installation information
Please provide the following:
zarr.__version__
: 2.2.0The text was updated successfully, but these errors were encountered: