Allow Python 3's pathlib.Path as an alternative to str
vaneseltine opened this issue · 2 comments
vaneseltine commented
Describe the issue
In four places, pyreadr.py
requires that paths are provided as str
, and throws PyreadrError
if provided with a pathlib.Path
To Reproduce
Using Python 3:
>>> from pathlib import Path
>>> import pyreadr
>>> input_file = Path("./spam.rdata")
>>> pyreadr.read_r(input_file)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "[...]/pyreadr/pyreadr.py", line 44, in read_r
raise PyreadrError("path must be a string!")
pyreadr.custom_errors.PyreadrError: path must be a string!
Expected behavior
pathlib
has been part of the standard library since 3.4, and pathlib.Path("./breakfast.rdata")
should be as valid a path specification as "./breakfast.rdata"
for all supported versions of Python 3.
Solutions
Given that:
- pyreadr continues to support 2.7, which does not include
pathlib
- the path is must ultimately go as a string to
librdata
, which we leave alone - any pathlib backport would add an external dependency, which is not desired
...the main options appear to be:
- Expand the path handling to allow
pathlib.Path
specifically in addition tostr
path = str(path)
to convert whatever is provided into a string
Either would work but follow somewhat different interface philosophies.
ofajardo commented
Thanks for the suggestion. I solved it recently in my other library Pyreadstat, so I should be able to reproduce that here as well. Will do when I get a bit of time.
ofajardo commented
fixed in version 0.4.2