pandas 3.0: three remaining set_index(<str column>.values) calls still raise TypeError (custom-labels paths)
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 82/100
Rechercherichtung
Lies die drei Aufrufstellen von set_index in wfdb/io/annotation.py im Umfeld von label_triplets_to_df, set_custom_labels und get_contained_labels. Reproduziere den Fehler mit pandas 2.2.3 unter Verwendung von pd.set_option("future.infer_string", True) und teste die Pfade für benutzerdefinierte Labels. Die Aufgabe ist abgeschlossen, wenn alle drei Pfade ohne den gemeldeten TypeError unter der String-Semantik von pandas funktionieren.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.)
- Vorherrschende Sprache
- Jupyter Notebook
- Sterne
- 853
- Forks
- 324
- Ø Merge
- 17 Std. 39 Min.
- Gemergte PRs (30 T.)
- 10
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus MIT-LCP/wfdb-python
-
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 83/100
MIT-LCP/wfdb-python#594 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 72/100
MIT-LCP/wfdb-python#590 ·
Maintainer antworten meist innerhalb von 1 Tag
-
`find_local_peaks` ignores the sample at `i + radius`, so points on a rising slope are returned as peaksEvtl. vergeben @rmz-oz hat das vor 28 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
MIT-LCP/wfdb-python#572 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 72/100
MIT-LCP/wfdb-python#595 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 67/100
MIT-LCP/wfdb-python#593 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in MIT-LCP/wfdb-python
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
cloudevents/sdk-go#1346 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
cyrusimap/cyrus-imapd#6640 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
GD decoder discards the finfo media type in mediaTypeByBinary() since 4.4.0Evtl. vergeben @lazerg hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 77/100
Intervention/image#1556 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 60/100
Maintainer antworten meist innerhalb von 1 Tag