Nullable pandas dtypes crash in categorical handling: "Cannot interpret 'BooleanDtype' as a data type"

Open
#281 0 comments 0 reactions 0 assignees View on GitHub

@RaphaelFakhri is already working on this.

Since Nov 5, 2026.

  • #282 by @RaphaelFakhri — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
numpy, pandas, python
Domain
data

Research direction

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.

Written by the indexing model from the issue text.

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).

Dominant language
Python
Stars
990
Forks
113
Avg merge
2d 8h
Merged PRs (30d)
3

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pydata/patsy

All issues in pydata/patsy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.