Repository navigation
Add record-specific download and listing names - #794
Conversation
tompollard
left a comment
There was a problem hiding this comment.
Thanks. Choosing download_records over download_database and pointing whole-project downloads to physionet.download both make sense to me. Since these are meant to be the long-term names, there are a couple of behaviours I'd fix before they're public. I tested them against the demo_database fixture.
The two functions read database differently.
wfdb.download_records("demo/sub", out) # sub is a subfolder; latest version inserted
wfdb.list_records("demo/sub") # treated as a versioned path: requests demo/sub/...
wfdb.list_records("demo/1.0/sub") # works
wfdb.download_records("demo/1.0/sub", out) # builds demo/1.0/1.0/subSo the same string can't be passed to both, and download_records can't download a specific version. Could both take database as a slug with an optional subfolder, plus a keyword-only version=None (None meaning latest)? Then list_records("mitdb", version="1.0.0") and download_records("mitdb", out, version="1.0.0") would work the same way.
records="100" is read one character at a time. The hint list[str] | str suggests a single name works, but dl_database loops over anything other than "all", so it looks for records 1, 0 and 0 (in the fixture it asked for 1.hea). Wrapping a single string in a list, or accepting only a list (with None meaning all) and raising TypeError otherwise, would avoid this.
Smaller points:
download_recordskeepsdl_database's two progress lines per record, which is a lot of output for a large database. A new name is a good point to make it quiet by default, or to addverbose.- For nested databases,
RECORDSlists folders such as30/, whichdl_databaseexpands butlist_recordsreturns as they are. Either expand them, or say in the docstring that folder entries can appear. - Tests that pass the same
databasestring to both functions, and one withrecords="100", would cover the first two points.
|
Thanks, these are good catches. I pushed dc17f27:
The full offline suite passes (1,171 tests), as do Ruff and the warnings-as-errors docs build. |
tompollard
left a comment
There was a problem hiding this comment.
Thanks, dc17f27 covers everything. list_records and download_records now read "demo/sub" the same way, with or without version=. records="100" is a single record, and anything that isn't a string, a list or None raises TypeError. download_records is quiet by default, and folder entries in RECORDS are documented. I also checked that records=[] doesn't fall through to downloading the whole project, since physionet.download returns early when the selection is empty. The offline suite, Ruff and the strict docs build pass locally.
A few optional points, since these are the long-term names:
records="all"now looks for a record namedall. People coming fromdl_databaseare likely to try it, so treating it likeNoneor raising a clear error would help.records=("100",)raisesTypeError. Accepting any sequence of strings (other than a single string) would be friendlier.records=Nonemeans all records, whileannotators=Nonemeans no annotations. It's documented, butNonemeaning opposite things for neighbouring options may trip people up. One alternative isannotators=Nonefor all andannotators=[]for none.
Ready to merge.
|
I took another look at the new API's defaults in b54773b. I also changed The offline suite passes (1,175 tests), as do Ruff and the strict docs build. |
tompollard
left a comment
There was a problem hiding this comment.
Thanks, the changes in b54773b look good. None no longer means opposite things, any sequence of names works, and the empty-selection no-op is tested. Since these names should get the interface right rather than carry over dl_database's behaviour, there are a few more things I'd change before release:
- Return what was downloaded.
download_recordsstill returnsNone, asdl_databasedoes, so afterrecords="all"the caller can't tell what was saved or where. Returning the list of saved file paths would make the result directly usable, for example to pass intoread_record. (physionet.downloadalready returns its destination.) - Treat folder names in
recordsthe same way as the default.records="all"now useslist_records, which expands nested folders at every level. An explicit folder such asrecords=["sub/"]still goes throughdl_database's one-level expansion, sorecords=["30/"]on a database like MIMIC-III Waveform leaves the next level of folders unexpanded. Could folder names inrecordsbe expanded with the same code, or rejected with a pointer tolist_records? - Nested listings are slow. MIMIC-III Waveform's top-level
RECORDSlists 67,830 folders, each with its ownRECORDS, solist_records("mimic3wdb")(anddownload_records("mimic3wdb")by default) now makes about 67,830 requests one after another, wherelist_recordspreviously made one. Fetching folders in parallel with a small thread pool, as the downloads do, would help. At minimum, the docstring should say that listing a nested database can take a long time.
The offline suite, Ruff and the strict docs build pass locally.
|
Thanks, these were worth fixing before the new API is released. I pushed 8fbd0e2:
The full offline suite passes (1,176 tests), as do Ruff and the strict docs build. The additional sibling-folder test passes in the focused suite (58 tests). |
tompollard
left a comment
There was a problem hiding this comment.
Thanks, 8fbd0e2 covers all three points. download_records returns the selected paths (with no duplicates when a folder and a record inside it are both selected), folder names in records use the same full expansion as "all", and nested listings now run eight requests at a time in their original order. I also tested a MIMIC-III Waveform-style layout, with top-level entries like 30/000/ each containing a RECORDS file: the listing completed without a deadlock and returned the records in order. The offline suite, Ruff and the strict docs build pass locally.
One optional tidy-up: _return_files adds a private option to dl_database's public signature. Moving the file selection into an internal helper used by both functions would avoid that, but it's fine as a follow-up.
Ready to merge once CI is green.
dl_database no longer needs a private _return_files option. Both dl_database and download_records now call _download_database, which returns the selected files.
Summary
Add
wfdb.download_recordsandwfdb.list_recordsas readable names for WFDB-specific operations.download_recordsselects the headers, signal files, segments, and optional annotations needed for records in a PhysioNet database, then uses the existing PhysioNet-backed transfer path.list_recordsreads the database'sRECORDSfile. The existingdl_databaseandget_record_listfunctions keep working without warnings.I chose
download_recordsrather than the proposeddownload_databasename in #672 because this function requires aRECORDSfile and selects WFDB files. For a whole PhysioNet dataset, including CSVs, PDFs, and other files,physionet.downloadis the clearer API. I left genericdownload_filesandlist_databasesnames out of this PR for the same reason. This keeps the package dependency direction aswfdb→physionet.Both new functions take a database slug with an optional subfolder and a separate keyword-only
versionargument. Omittingversionuses the latest database version.list_recordsexpands nestedRECORDSfolders and returns concrete record paths; sibling folders are read concurrently in a bounded pool.download_recordsaccepts one record name, a sequence of names, or a folder name ending in/. Its defaultrecords="all"expands nested folders, and an empty sequence downloads nothing. It returns the selected saved file paths. Annotations are opt in:annotators=Noneskips them;annotators="all"includes every type. It is quiet by default, withverbose=Trueavailable for progress messages. The legacydl_databasekeeps its existing defaults and return value.Checks