Bug: SHHS sleep staging can raise IndexError when signal epochs exceed available labels Copy title
维护者通常 3 天内回复
评估
调研方向
Start in pyhealth/tasks/sleep_staging.py at the epoch loop in sleep_staging_shhs_fn(), and compare it with sleep_staging_sleepedf_fn(), which already caps the range by label count. Pull request #1288 is already open against this issue, so check it before starting. Done means the loop no longer raises IndexError when there are fewer labels than complete epochs, and a regression test covers that case.
由索引模型根据 Issue 内容生成。
描述
Description
In pyhealth/tasks/sleep_staging.py, the sleep_staging_shhs_fn() function iterates over all complete signal epochs without checking whether a corresponding annotation exists.
The current implementation is:
for slice_index in range(X.shape[1] // sample_length):
epoch_signal = X[
:, slice_index * sample_length : (slice_index + 1) * sample_length
]
epoch_label = Y[slice_index]
Here, the loop count depends only on the signal length, while Y is populated independently from the XML annotation file.
If the number of complete signal epochs exceeds the number of available labels, accessing Y[slice_index] raises IndexError.
Steps to Reproduce
The following minimal example reproduces the indexing behavior without requiring the SHHS dataset:
import numpy as np
sample_length = 125 * 30
# Three complete signal epochs
X = np.zeros((2, sample_length * 3))
# Only two annotation labels
Y = ["0", "1"]
for slice_index in range(X.shape[1] // sample_length):
epoch_signal = X[
:, slice_index * sample_length : (slice_index + 1) * sample_length
]
epoch_label = Y[slice_index]
Observed Behavior
The third iteration attempts to access Y[2] and raises:
IndexError: list index out of range
This reproduces the indexing logic used in sleep_staging_shhs_fn(). An end-to-end failure with a real SHHS recording has not been verified.
Expected Behavior
The function should handle differences between signal duration and annotation coverage without unexpectedly raising an indexing error.
If annotations are shorter than the signal, the function should either:
- Process only epochs with corresponding labels, or
- Raise a clear validation error explaining the mismatch.
Suggested Fix
If processing only labeled epochs is the intended behavior, limit the loop to the number of available labels:
num_signal_epochs = X.shape[1] // sample_length
num_labeled_epochs = len(Y)
for slice_index in range(min(num_signal_epochs, num_labeled_epochs)):
...
Alternatively, explicitly validate the signal and annotation lengths before processing.
A regression test should cover recordings with fewer annotations than complete signal epochs.
Environment
- Repository:
sunlabuiuc/PyHealth - File:
pyhealth/tasks/sleep_staging.py - Function:
sleep_staging_shhs_fn() - Affected behavior: Signal epoch and annotation length mismatch
- Verification: Minimal indexing reproduction; source inspection
- Full SHHS dataset test: Not performed
Additional Context
The neighboring sleep_staging_sleepedf_fn() already limits its iteration using:
range(min(X.shape[1] // sample_length, len(labels)))
Applying a similar safeguard to the SHHS implementation would provide consistent handling of annotation length mismatches.
- 主要语言
- Python
- 星标
- 1.7k
- 派生
- 803
- 平均合并
- 5 天 20 小时
- 30 天内合并 PR
- 56
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
sunlabuiuc/PyHealth 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 77/100
sunlabuiuc/PyHealth#1333 · 1 条评论 ·
维护者通常 3 天内回复
-
难度 4/5 3-5 天 新手友好度 30/100
sunlabuiuc/PyHealth#1297 ·
维护者通常 3 天内回复
-
难度 4/5 3-5 天 新手友好度 22/100
sunlabuiuc/PyHealth#1295 · 1 条评论 ·
维护者通常 3 天内回复
-
难度 3/5 1-2 天 新手友好度 42/100
sunlabuiuc/PyHealth#1294 · 1 条评论 ·
维护者通常 3 天内回复
-
Internal transfers are counted as readmissions可能已有人在做 @thebean27 于 21 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 35/100
sunlabuiuc/PyHealth#1269 · 3 条评论 ·
维护者通常 3 天内回复
查看 sunlabuiuc/PyHealth 的全部 Issue
相似的 Issue
-
filesystem: `file://C:/...` bucket_url is read as a UNC share named `C:` and silently lists no files未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
comp/desktop desktop/shell os/windows P3 tool/file type/bug
难度 2/5 1-3 小时 新手友好度 76/100
NousResearch/hermes-agent#145928 ·
维护者通常 1 天内回复
-
integration:coding-agents
难度 1/5 1 小时以内 新手友好度 83/100
vectorize-io/hindsight#6151 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
FormalLanguageConstrainedPathQuerying/FLPQ_Data#174 ·
维护者通常 1 天内回复
-
[VLM] granite_vision preset produces empty output and runs ~3× slower with Granite Vision 3.3-2B than with Granite Vision 4.1-4B可能已有人在做 @prassu017 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 74/100
docling-project/docling#5068 · 4 条评论 ·
维护者通常 1 天内回复