open...() functions should accept pathlib.Path
See original GitHub issueMinimal, reproducible code sample, a copy-pastable example if possible
from pathlib import Path
store = Path('/path/to/store')
zarr.open_group(store)
…gives:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-8-4a4272aec66c> in <module>()
----> 1 codon_position = zarr.open_group(output_dir / 'codon_position.zarr.zip')
2 codon_position.tree()
~/github/wtsi-team112/vector-ops/deps/conda/envs/vector-ops/lib/python3.6/site-packages/zarr/hierarchy.py in open_group(store, mode, cache_attrs, synchronizer, path)
1117
1118 elif mode == 'a':
-> 1119 if contains_array(store, path=path):
1120 err_contains_array(path)
1121 if not contains_group(store, path=path):
~/github/wtsi-team112/vector-ops/deps/conda/envs/vector-ops/lib/python3.6/site-packages/zarr/storage.py in contains_array(store, path)
70 prefix = _path_to_prefix(path)
71 key = prefix + array_meta_key
---> 72 return key in store
73
74
TypeError: argument of type 'PosixPath' is not iterable
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:
- Value of
zarr.__version__
: 2.2.0 - Version of Python interpreter: 3.6
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:14 (9 by maintainers)
Top Results From Across the Web
open...() functions should accept pathlib.Path #261 - GitHub
I think it could make sens that if we receive a Path, then it should be opened with the directory store. Pathlib is...
Read more >How to Open a File in Python: open(), pathlib, and More
Open a File with the pathlib Module ; my_file = Path('/path/to/file') ; >>> my_file.open() ; Traceback (most recent call last): ; "<pyshell#16>", ...
Read more >pathlib — Object-oriented filesystem paths — Python 3.11.1 ...
New in version 3.4. This module offers classes representing filesystem paths with semantics appropriate for different operating systems.
Read more >Python Path – How to Use the Pathlib Module with Examples
To understand how you can construct a basic path using Pathlib, let's create a new Python file called example.py and put it inside...
Read more >Python 3's pathlib Module: Taming the File System
In this tutorial, you will see how to work with file paths—names of directories and files—in Python. You will learn new ways to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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
Path
s.Most software I’ve been using accepts path objects. Would a minimal pull request be accepted?