-
Notifications
You must be signed in to change notification settings - Fork 303
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
Make wfdb.rdann, wfdb.rdrecord, wfdb.rdsamp also accept pathlib.Path objects as the input record_name #346
base: main
Are you sure you want to change the base?
Conversation
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 " |
I also think this is a bug: >>> wfdb.rdrecord("x_mitdb/x_111", pn_dir="mitdb", sampto=2000)
NetFileNotFoundError: 404 Error: Not Found for url: 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.Record at 0x7f6cd4ee7c50> |
I think there's a lot of work to do to better deal with the paths. For example, I found currently '/' not in db_dir or '.' not in pn_dir I think it's better to specify a pattern for the database version and use DB_VERSION_PATTERN = re.compile("\d+.\d+\.\d+") |
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
paths offer a .open
function, too, which might be more readable than using the global one.
@@ -4373,7 +4377,7 @@ def wrsamp(record_name, fs, units, sig_name, p_signal=None, d_signal=None, | |||
|
|||
""" | |||
# Check for valid record name | |||
if '.' in record_name: | |||
if '.' in str(record_name): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As directories might contain dots, maybe this wants to check for record_name.name instead.
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.rdsamp
only acceptstr
for the inputrecord_name
, as they havestr
specific operations.wfdb.rdheader
currently acceptspathlib.Path
objects as inputrecord_name
since theos.path
module is able to handlepathlib.Path
as well asstr
type 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.