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

Pathlib support for the IO registry #1983

Open
wasade opened this issue Mar 20, 2024 · 0 comments
Open

Pathlib support for the IO registry #1983

wasade opened this issue Mar 20, 2024 · 0 comments

Comments

@wasade
Copy link
Collaborator

wasade commented Mar 20, 2024

The read and potentially the write methods of the IO registry may not be aware of how to interact with pathlib.Path:

(skdev-py310) 8:34:48 (dtmcdonald@there):scikit-bio@biom_format$ cat foo.fasta 
>a
ATGC
>b
TTGC
(skdev-py310) 8:34:53 (dtmcdonald@there):scikit-bio@biom_format$ python
Python 3.10.13 (main, Sep 11 2023, 08:39:02) [Clang 14.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import skbio, pathlib
>>> list(skbio.read('foo.fasta', format='fasta'))
[Sequence
---------------------
Metadata:
    'description': ''
    'id': 'a'
Stats:
    length: 4
---------------------
0 ATGC, Sequence
---------------------
Metadata:
    'description': ''
    'id': 'b'
Stats:
    length: 4
---------------------
0 TTGC]
>>> list(skbio.read(pathlib.Path('foo.fasta'), format='fasta'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/dtmcdonald/ResearchWork/software/scikit-bio/skbio/io/registry.py", line 1180, in read
    return io_registry.read(file, format=format, into=into, verify=verify, **kwargs)
  File "/Users/dtmcdonald/ResearchWork/software/scikit-bio/skbio/io/registry.py", line 495, in read
    return (x for x in itertools.chain([next(gen)], gen))
  File "/Users/dtmcdonald/ResearchWork/software/scikit-bio/skbio/io/registry.py", line 518, in _read_gen
    with _resolve_file(file, **io_kwargs) as (file, _, _):
  File "/Users/dtmcdonald/miniconda3/envs/skdev-py310/lib/python3.10/contextlib.py", line 135, in __enter__
    return next(self.gen)
  File "/Users/dtmcdonald/ResearchWork/software/scikit-bio/skbio/io/util.py", line 222, in _resolve_file
    file, source, is_binary_file = _resolve(file, **kwargs)
  File "/Users/dtmcdonald/ResearchWork/software/scikit-bio/skbio/io/util.py", line 77, in _resolve
    raise IOSourceError("Could not open source: %r (mode: %r)" % (file, mode))
skbio.io._exception.IOSourceError: Could not open source: PosixPath('foo.fasta') (mode: 'r')
>>>
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

1 participant