pandas 3.0: three remaining set_index(<str column>.values) calls still raise TypeError (custom-labels paths)
维护者通常 1 天内回复
评估
调研方向
阅读wfdb/io/annotation.py中label_triplets_to_df、set_custom_labels和get_contained_labels附近的三个set_index调用位置。使用pd.set_option("future.infer_string", True)在pandas 2.2.3中复现,并检查自定义标签处理路径。完成标准是:在pandas字符串语义下,三个路径都能正常工作,且不再出现报告的TypeError。
由索引模型根据 Issue 内容生成。
描述
Description
#561 (v4.3.1) fixed the module-level ann_class_table.set_index(...) that crashed import wfdb under pandas 3 string semantics — thank you! However, three sibling patterns remain in wfdb/io/annotation.py (checked on main and in the v4.3.1 sdist), all passing a string column's .values directly as set_index keys:
- line ~728 (
label_triplets_to_dfregion):custom_labels.set_index(custom_labels["label_store"].values, inplace=True) - line ~1325 (
set_custom_labels/ DataFramecustom_labelspath):self.custom_labels.set_index(self.custom_labels["label_store"].values, inplace=True) - line ~1347 (
get_contained_labelsregion):label_map.set_index(label_map["symbol"].values, inplace=True)
With pandas' new string dtype (pandas 3.0, or 2.x with pd.set_option("future.infer_string", True)), Series.values is an ArrowStringArrayNumpySemantics, which DataFrame.set_index rejects:
TypeError: The parameter "keys" may be a column key, one-dimensional array, or a list containing only valid column keys and one-dimensional arrays.
These are runtime paths (annotation objects with custom labels), so import wfdb now succeeds, but the custom-label functionality still breaks once pandas 3 is the default.
Reproduce
import pandas as pd
pd.set_option("future.infer_string", True)
import wfdb
from wfdb.io.annotation import Annotation
# any path that reaches set_custom_labels / label_triplets_to_df with a
# DataFrame of custom labels -> TypeError above
(Versions: pandas 2.2.3 with the option / pandas 3.0; wfdb 4.3.1 and current main.)
Suggested fix
Pass the column label instead of the array — identical semantics on every pandas version (the keys are the column's values either way):
custom_labels.set_index("label_store", inplace=True)
self.custom_labels.set_index("label_store", inplace=True)
label_map.set_index("symbol", inplace=True)
Happy to open a PR with these three one-line changes if useful.
(Context: downstream ECG libraries, e.g. DeepPSP/torch_ecg, still pin pandas < 3 partly on this; a fix would help unblock the pandas-3 migration.)
- 主要语言
- Jupyter Notebook
- 星标
- 853
- 派生
- 324
- 平均合并
- 17 小时 39 分钟
- 30 天内合并 PR
- 10
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
MIT-LCP/wfdb-python 的其他 Issue
-
难度 1/5 1-3 小时 新手友好度 83/100
MIT-LCP/wfdb-python#594 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 72/100
MIT-LCP/wfdb-python#590 ·
维护者通常 1 天内回复
-
`find_local_peaks` ignores the sample at `i + radius`, so points on a rising slope are returned as peaks可能已有人在做 @rmz-oz 于 27 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
MIT-LCP/wfdb-python#572 ·
维护者通常 1 天内回复
-
bug
难度 3/5 1-2 天 新手友好度 72/100
MIT-LCP/wfdb-python#595 ·
维护者通常 1 天内回复
-
bug
难度 3/5 1-2 天 新手友好度 67/100
MIT-LCP/wfdb-python#593 ·
维护者通常 1 天内回复
查看 MIT-LCP/wfdb-python 的全部 Issue
相似的 Issue
-
fix(worker): keep normal prepare waiting states failure-free可能已有人在做 @LichKing-2234 今天认领。 未关闭agent:codex priority:P1
难度 2/5 1-3 小时 新手友好度 72/100
AgoraIO-Extensions/agent-infra#3745 ·
维护者通常 1 天内回复
-
The five-line work window can drop its oldest line: the per-line byte share ignores the JSON framing可能已有人在做 @Eapp1e 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
makecindy/cindy#7973 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
objectionary/hone-maven-plugin#1351 ·
维护者通常 9 天内回复
-
PC
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
dependencies
难度 2/5 1-3 小时 新手友好度 68/100
dlt-contrib/dlt-filesystem#51 ·
维护者通常 1 天内回复