Nullable pandas dtypes crash in categorical handling: "Cannot interpret 'BooleanDtype' as a data type"
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 35/100
Piste de recherche
Start by reading CategoricalSniffer.sniff() and categorical_to_int() in the Patsy source, then inspect the existing tests for categorical handling. Reproduce the failures with pandas nullable and pyarrow dtypes, including Boolean and integer columns. Done means categorical handling works for the shown dtypes; the separate pd.NA missing-value gap is also identified in the issue.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
A DataFrame column with a pandas nullable or pyarrow dtype raises TypeError when patsy treats it as categorical, even when the column has no missing values. DataFrame.convert_dtypes() and read_csv(dtype_backend=...) produce these dtypes.
Reproduce
import pandas as pd
import patsy
df = pd.DataFrame({"b": [True, False, True], "i": [1, 2, 1]}).convert_dtypes()
patsy.dmatrix("b", df) # TypeError: Cannot interpret 'BooleanDtype' as a data type
patsy.dmatrix("C(i)", df) # TypeError: Cannot interpret 'Int64Dtype()' as a data type
df = df.convert_dtypes(dtype_backend="pyarrow")
patsy.dmatrix("b", df) # TypeError: Cannot interpret 'bool[pyarrow]' as a data type
Tested with patsy main (38a1ac5), numpy 2.5.4 and pandas 3.1.0. Numeric use of the same columns (dmatrix("i", df)) works.
Cause
CategoricalSniffer.sniff() and categorical_to_int() call safe_issubdtype(data.dtype, np.bool_) on the pandas Series. safe_issubdtype passes the pandas extension dtype to np.issubdtype, and numpy can't interpret it. Nullable and pyarrow dtypes expose the equivalent numpy dtype as numpy_dtype.
Columns that contain pd.NA are a separate gap: patsy doesn't treat pd.NA as missing in any dtype (string, Int64, boolean).
- Langage dominant
- Python
- Étoiles
- 990
- Forks
- 113
- Merge moyen
- 2 j 8 h
- PR mergées (30 j)
- 3
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de pydata/patsy
-
VarLookupDict should implement __iter__, causes CPython crash when using statsmodels in marimo notebookPeut-être pris @kouyouqi123 l’a pris il y a 173 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
-
Add link to license in readmePeut-être pris @zheng-guannan577 l’a pris il y a 9 jours. Ouverte
Difficulté 1/5 Moins d'une heure Accessibilité débutants 72/100
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 68/100
-
cc() truncates periodic coordinates for integer input with fractional boundsPeut-être pris @ktz03 l’a pris il y a 39 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 35/100
-
`build._eval_factor` error condition attempts to access attribute `dtype` on `DataFrame` object, but no such attribute existsPeut-être pris @kouyouqi123 l’a pris il y a 173 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 55/100
Toutes les issues de pydata/patsy
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
abetlen/llama-cpp-python#2424 ·
Les mainteneurs répondent en général sous 1 jour
-
Bug IronPython Python 3
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
pyrevitlabs/pyRevit#4184 ·
Les mainteneurs répondent en général sous 1 jour
-
CLAW (Agents & Orchestration)Ouverte
Difficulté 1/5 Moins d'une heure Accessibilité débutants 74/100
jqueryscript/awesome-claude-code#1009 ·
-
tests
Difficulté 2/5 1-3 heures Accessibilité débutants 66/100
Les mainteneurs répondent en général sous 3 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour