Repository navigation
Conversation
The dependency check passed a list to importlib.metadata.version(), which expects a single distribution name. It always raised TypeError, was swallowed by the blanket except, and left ElementTree unbound, so sleep_staging_shhs_fn could never parse SHHS labels. ElementTree is the standard library and the only XML API the function uses; elementpath was never referenced and is not a declared dependency. Import ElementTree at module top and drop the check.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Title: Fix SHHS sleep staging dependency check leaving XML parser undefined
Fixes #1282.
sleep_staging_shhs_fninpyhealth/tasks/sleep_staging.pycould not parse SHHS labels. Its dependency check passed a list toimportlib.metadata.version(), which takes one distribution name, so it always raisedTypeError. The bareexceptswallowed that,import xml.etree.ElementTree as ETnever ran, andET.fromstringraisedUnboundLocalError.The check guarded
elementpath, which the function never uses and the package does not declare. This PR removes the check and imports ElementTree at module level.Changes
pyhealth/tasks/sleep_staging.py: remove the dependency check and importxml.etree.ElementTreeat the top of the module.tests/core/test_sleep_staging_shhs.py: new tests. One checks thatETis bound at module level. One runssleep_staging_shhs_fnend to end with a stubbed EDF read and an SHHS-shaped XML annotation file, and checks the labels and saved epochs.docs/api/tasks/pyhealth.tasks.sleep_staging.rst: note that SHHS annotation parsing needs only the standard library.examples/eeg/sleep_staging/sleep_staging_shhs_contrawr.py: remove the unusedContraWRimport.The issue offers two fixes: call
version("elementpath"), or remove the check. I removed it, because a repaired check would either ask users to install a package the function does not need or add a new hard dependency. If you prefer to keep a check, I can restore it.Both new tests fail on the current code and pass with this change.