When calling bandpower() with a Hypnogram object and string include labels, the returned DataFrame has integer stage codes in the index instead of the original string labels. This causes bandpower.xs("N3") to raise a KeyError.
bandpower = yasa.bandpower(raw, hypno=hyp, include=["N2", "N3", "REM"])
bandpower.index.get_level_values("Stage").unique()
# Index([2, 3, 4], dtype='int64') ← integers, not strings
bandpower.xs("N3")["Delta"]
# KeyError: 'N3'
This also breaks the example in the quickstart tutorial which uses bandpower.xs("N3").
Root cause: In spectral.py, string include labels are converted to integers for internal processing (line 178) but never mapped back to strings when building the output DataFrame.
Expected behavior: When include is passed as strings, the output DataFrame index should use those same string labels so that bandpower.xs("N3") works as documented.
When calling
bandpower()with a Hypnogram object and string include labels, the returned DataFrame has integer stage codes in the index instead of the original string labels. This causesbandpower.xs("N3")to raise aKeyError.This also breaks the example in the quickstart tutorial which uses
bandpower.xs("N3").Root cause: In
spectral.py, string include labels are converted to integers for internal processing (line 178) but never mapped back to strings when building the output DataFrame.Expected behavior: When include is passed as strings, the output DataFrame index should use those same string labels so that
bandpower.xs("N3")works as documented.