Uh oh!
There was an error while loading. Please reload this page.
Make wfdb.rdann, wfdb.rdrecord, wfdb.rdsamp also accept pathlib.Path objects as the input record_name - #346
Make wfdb.rdann, wfdb.rdrecord, wfdb.rdsamp also accept pathlib.Path objects as the input record_name#346wenh06 wants to merge 4 commits into
Conversation
bemoody
commented
Mar 21, 2022
Thank you! This looks like a great improvement. I'm not entirely familiar with One thing to be wary of is that "file names" or "record names" might be either filesystem paths or URL paths. Some existing functions permit Here, for example, it looks like you're passing a If we do want the I'm not necessarily opposed to either saying " |
wenh06
commented
Mar 23, 2022
I also think this is a bug: >>>wfdb.rdrecord("x_mitdb/x_111", pn_dir="mitdb", sampto=2000)
NetFileNotFoundError: 404Error: NotFoundforurl: https://physionet.org/files/mitdb/1.0.0/x_111.hea>>>wfdb.rdrecord("x_111", pn_dir="mitdb/1.0.0/x_mitdb/", sampto=2000)
<wfdb.io.record.Recordat0x7f6cd4ee7c50> |
wenh06
commented
Mar 23, 2022
I think there's a lot of work to do to better deal with the paths. For example, I found currently '/'notindb_diror '.'notinpn_dirI think it's better to specify a pattern for the database version and use DB_VERSION_PATTERN=re.compile("\d+.\d+\.\d+") |
cx1111
commented
Apr 25, 2022
Thanks very much for identifying the bugs. We're going to think a bit more about how we want the API to be in the next major version, such that the behavior is more explicit. Especially when adding cloud data sources. |
Ivorforce
left a comment
There was a problem hiding this comment.
Would love to see this merged!
| # local file | ||
| if pn_dir is None: | ||
| with open(record_name + '.' + extension, 'rb') as f: | ||
| with open(file_name, 'rb') as f: |
There was a problem hiding this comment.
paths offer a .open function, too, which might be more readable than using the global one.
| """ | ||
| # Check for valid record name | ||
| if '.' in record_name: | ||
| if '.' in str(record_name): |
There was a problem hiding this comment.
As directories might contain dots, maybe this wants to check for record_name.name instead.
wenh06
commented
May 29, 2022
I agree with you. I tried continuing to correct (enhance) path operations in other places for several hours but finally gave up. I hope that path operations would be designed in a more uniform and modern way in the next major version. |

Currently, the functions
wfdb.rdann,wfdb.rdrecord,wfdb.rdsamponly acceptstrfor the inputrecord_name, as they havestrspecific operations.wfdb.rdheadercurrently acceptspathlib.Pathobjects as inputrecord_namesince theos.pathmodule is able to handlepathlib.Pathas well asstrtype input.For example, on a linux machine
would raise error
Sometimes one would like to work locally with
pathlib, which was introduced in Python 3.4 (PEP 428), to better handle the file paths.