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 摘要。