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
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
step.duration reflects only the last retry attempt (HelperStep.run() overwrites startTime)可能已有人在做 @mirao 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 78/100
codeceptjs/CodeceptJS#5774 · 1 則留言 ·
維護者通常 2 天內回覆
-
bug mac アプリ: コード アプリ: チャット 優先: 中 要トリアージ
難度 2/5 1-3 小時 新手友好度 74/100
yksr-melt/Meltype#1346 · 2 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
aws/context-ontology-accelerator#336 ·
維護者通常 1 天內回覆
-
b:minor bug
難度 2/5 1-3 小時 新手友好度 76/100
software-mansion/argent#1698 ·
維護者通常 1 天內回覆