Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

pandas 3.0: three remaining set_index(<str column>.values) calls still raise TypeError (custom-labels paths)

未关闭 适合新手
#574 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@wenh06 已经在做这个了。

开始于 2026年10月23日。

  • #575 来自 @wenh06 —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
pandas, python
领域
backend

调研方向

阅读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_df region):
    custom_labels.set_index(custom_labels["label_store"].values, inplace=True)
    
  • line ~1325 (set_custom_labels / DataFrame custom_labels path):
    self.custom_labels.set_index(self.custom_labels["label_store"].values, inplace=True)
    
  • line ~1347 (get_contained_labels region):
    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,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

MIT-LCP/wfdb-python 的其他 Issue

查看 MIT-LCP/wfdb-python 的全部 Issue

相似的 Issue

更多 Backend & API Design Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。