Nullable pandas dtypes crash in categorical handling: "Cannot interpret 'BooleanDtype' as a data type"
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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).
- Lenguaje dominante
- Python
- Estrellas
- 990
- Forks
- 113
- Merge medio
- 2 d 8 h
- PR fusionados (30 d)
- 3
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de pydata/patsy
-
VarLookupDict should implement __iter__, causes CPython crash when using statsmodels in marimo notebookPosiblemente ocupada @kouyouqi123 la tomó hace 173 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
Add link to license in readmePosiblemente ocupada @zheng-guannan577 la tomó hace 9 días. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 68/100
-
cc() truncates periodic coordinates for integer input with fractional boundsPosiblemente ocupada @ktz03 la tomó hace 39 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 35/100
-
`build._eval_factor` error condition attempts to access attribute `dtype` on `DataFrame` object, but no such attribute existsPosiblemente ocupada @kouyouqi123 la tomó hace 173 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 55/100
Todos los issues de pydata/patsy
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
abetlen/llama-cpp-python#2424 ·
Los mantenedores suelen responder en 1 día
-
Bug IronPython Python 3
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
pyrevitlabs/pyRevit#4184 ·
Los mantenedores suelen responder en 1 día
-
CLAW (Agents & Orchestration)Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 74/100
jqueryscript/awesome-claude-code#1009 ·
-
tests
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Los mantenedores suelen responder en 3 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día