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

オープン
#281 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

@RaphaelFakhri がすでに取り組んでいます。

2026年11月5日 から。

  • #282 @RaphaelFakhri による — オープン

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
numpy, pandas, python
領域
data

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Python
スター
990
フォーク
113
平均マージ
2日 8時間
マージ済み PR(30日)
3

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pydata/patsy のほかの issue

pydata/patsy の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。