Skip to content

Support itemsize-parameterized numpy dtypes in the pandas engine - #2437

Merged
cosmicbboy merged 1 commit into
unionai-oss:mainfrom
mannemkarthik010:fix-itemsize-parameterized-numpy-dtypes
Aug 19, 2026
Merged

cosmicbboy merged 1 commit into
unionai-oss:mainfrom
mannemkarthik010:fix-itemsize-parameterized-numpy-dtypes

Conversation

@mannemkarthik010

Copy link
Copy Markdown

Fixes #1270

Declaring a column with a sized numpy dtype raised a TypeError naming a dtype the user never wrote:

pa.DataFrameSchema({"a": pa.Column(np.dtype("S16"))})
TypeError: data type 'bytes128' not understood

Engine.dtype normalizes platform-specific aliases by round-tripping the dtype through its name, so that e.g. np.intc becomes np.int32. That works for fixed-width numeric dtypes, whose name is itself a valid dtype string, but not for itemsize-parameterized ones: np.dtype("S16").name is "bytes128" and np.dtype("U16").name is "str512" -- neither parses back.

This falls back to the dtype itself when the name does not round-trip. Its scalar type is already platform-agnostic, so the subsequent .type lookup resolves as it does for the unsized spelling: np.dtype("S16") now resolves the same as bytes, and np.dtype("U16") the same as np.str_.

Worth noting: using np_or_pd_dtype.type directly instead of the round-trip would be simpler, but it silently regresses the normalization this code exists for -- np.dtype("longlong").type is np.longlong, not np.int64. So the round-trip is kept and only guarded.

The issue reports this for bytes; it affects sized unicode (U16) the same way. Void (V8) remains unsupported by the engine, but now surfaces pandera's own "not understood by Engine" error rather than a numpy parse error.

Test plan

Added to tests/pandas/test_pandas_engine.py:

  • test_itemsize_parameterized_numpy_dtype -- S16/S1/U16/U100 resolve like their scalar type
  • test_itemsize_parameterized_numpy_dtype_validates -- a schema declared with np.dtype("S16") validates real data
  • test_platform_alias_numpy_dtype_still_normalized -- intc/uintc/longlong/ulonglong still normalize (guards the regression described above)

5 of these fail on main and all pass with this change. The full test_pandas_engine.py, test_numpy_engine.py, test_engine.py and test_dtypes.py suites pass (887 tests). ruff check, ruff format and codespell are clean.

Declaring a column with a sized numpy dtype raised a confusing TypeError
that named a dtype the user never wrote:

    pa.DataFrameSchema({"a": pa.Column(np.dtype("S16"))})
    TypeError: data type 'bytes128' not understood

Engine.dtype normalizes platform-specific aliases by round-tripping the
dtype through its name, so that e.g. np.intc becomes np.int32. That works
for fixed-width numeric dtypes, whose name is itself a valid dtype string,
but not for itemsize-parameterized ones: np.dtype("S16").name is
"bytes128", np.dtype("U16").name is "str512", and neither parses back.

Fall back to the dtype itself when the name does not round-trip. Its
scalar type is already platform-agnostic, so the subsequent .type lookup
resolves as it does for the unsized spelling: np.dtype("S16") now resolves
the same as bytes, and np.dtype("U16") the same as np.str_.

Note that using np_or_pd_dtype.type directly instead of the round-trip
would be simpler but silently regress the normalization this code exists
for -- np.dtype("longlong").type is np.longlong, not np.int64 -- so the
round-trip is kept and only guarded. Tests cover both directions.

Fixes unionai-oss#1270

Signed-off-by: Karthik Mannem <180236770+mannemkarthik010@users.noreply.github.com>
@mannemkarthik010
mannemkarthik010 force-pushed the fix-itemsize-parameterized-numpy-dtypes branch from 771b37e to 43b8fe5 Compare August 7, 2026 16:49
@codecov

codecov Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.40%. Comparing base (106a663) to head (43b8fe5).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2437   +/-   ##
=======================================
  Coverage   91.39%   91.40%           
=======================================
  Files         193      193           
  Lines       17579    17582    +3     
=======================================
+ Hits        16067    16070    +3     
  Misses       1512     1512           
Flag Coverage Δ
unit-tests-base-Linux-py3.10 16.48% <0.00%> (-0.01%) ⬇️
unit-tests-base-Linux-py3.11 16.48% <0.00%> (-0.01%) ⬇️
unit-tests-base-Linux-py3.12 16.48% <0.00%> (-0.01%) ⬇️
unit-tests-base-Linux-py3.13 16.48% <0.00%> (-0.01%) ⬇️
unit-tests-base-Linux-py3.14 16.35% <0.00%> (-0.01%) ⬇️
unit-tests-base-Windows-py3.10 16.40% <0.00%> (-0.01%) ⬇️
unit-tests-base-Windows-py3.11 16.40% <0.00%> (-0.01%) ⬇️
unit-tests-base-Windows-py3.12 16.40% <0.00%> (-0.01%) ⬇️
unit-tests-base-Windows-py3.13 16.40% <0.00%> (-0.01%) ⬇️
unit-tests-base-Windows-py3.14 16.28% <0.00%> (-0.01%) ⬇️
unit-tests-base-macOS-py3.10 16.41% <0.00%> (-0.01%) ⬇️
unit-tests-base-macOS-py3.11 16.41% <0.00%> (-0.01%) ⬇️
unit-tests-base-macOS-py3.12 16.41% <0.00%> (-0.01%) ⬇️
unit-tests-base-macOS-py3.13 16.41% <0.00%> (-0.01%) ⬇️
unit-tests-base-macOS-py3.14 16.29% <0.00%> (-0.01%) ⬇️
unit-tests-dask-Linux-py3.10-pandas2.3.3-polars 23.65% <50.00%> (+<0.01%) ⬆️
unit-tests-dask-Linux-py3.11-pandas2.3.3-polars 23.65% <50.00%> (+<0.01%) ⬆️
unit-tests-dask-Linux-py3.12-pandas2.3.3-polars 23.65% <50.00%> (+<0.01%) ⬆️
unit-tests-dask-Linux-py3.13-pandas2.3.3-polars 23.65% <50.00%> (+<0.01%) ⬆️
unit-tests-dask-Linux-py3.14-pandas2.3.3-polars 23.56% <50.00%> (+<0.01%) ⬆️
unit-tests-dask-Windows-py3.10-pandas2.3.3-polars 23.56% <50.00%> (+<0.01%) ⬆️
unit-tests-dask-Windows-py3.11-pandas2.3.3-polars 23.56% <50.00%> (+<0.01%) ⬆️
unit-tests-dask-Windows-py3.12-pandas2.3.3-polars 23.56% <50.00%> (+<0.01%) ⬆️
unit-tests-dask-Windows-py3.13-pandas2.3.3-polars 23.56% <50.00%> (+<0.01%) ⬆️
unit-tests-dask-Windows-py3.14-pandas2.3.3-polars 23.48% <50.00%> (+<0.01%) ⬆️
unit-tests-dask-macOS-py3.10-pandas2.3.3-polars 23.59% <50.00%> (-0.01%) ⬇️
unit-tests-fastapi-Linux-py3.11-pandas2.3.3-pydantic2.12.3 24.07% <50.00%> (-0.65%) ⬇️
unit-tests-fastapi-Linux-py3.11-pandas3.0.0-pydantic2.12.3 24.14% <50.00%> (-0.66%) ⬇️
unit-tests-fastapi-Linux-py3.12-pandas2.3.3-pydantic2.12.3 24.07% <50.00%> (+<0.01%) ⬆️
unit-tests-fastapi-Linux-py3.13-pandas2.3.3-pydantic2.12.3 24.07% <50.00%> (-0.64%) ⬇️
unit-tests-fastapi-Linux-py3.14-pandas3.0.0-pydantic2.12.3 24.06% <50.00%> (+<0.01%) ⬆️
unit-tests-fastapi-Windows-py3.10-pandas2.3.3-pydantic2.12.3 23.99% <50.00%> (-0.01%) ⬇️
unit-tests-geopandas-Linux-py3.11-pandas2.3.3-pydantic2.12.3 29.35% <50.00%> (+0.01%) ⬆️
unit-tests-geopandas-Linux-py3.11-pandas3.0.0-pydantic2.12.3 29.35% <50.00%> (-0.72%) ⬇️
unit-tests-geopandas-Windows-py3.11-pandas2.3.3-pydantic2.12.3 29.26% <50.00%> (+<0.01%) ⬆️
unit-tests-hypotheses-Linux-py3.10-pandas2.3.3-pydantic2.12.3 21.94% <50.00%> (-0.01%) ⬇️
unit-tests-hypotheses-Linux-py3.11-pandas3.0.0-pydantic2.12.3 21.98% <50.00%> (+<0.01%) ⬆️
unit-tests-hypotheses-Linux-py3.12-pandas2.3.3-pydantic2.12.3 21.94% <50.00%> (-0.01%) ⬇️
unit-tests-hypotheses-Linux-py3.13-pandas3.0.0-pydantic2.12.3 21.98% <50.00%> (-0.59%) ⬇️
unit-tests-hypotheses-Linux-py3.14-pandas2.3.3-pydantic2.12.3 21.84% <50.00%> (+<0.01%) ⬆️
unit-tests-ibis-Linux-py3.10-pandas2.3.3-polars 28.09% <50.00%> (+<0.01%) ⬆️
unit-tests-ibis-Linux-py3.11-pandas2.3.3-polars 28.09% <50.00%> (+<0.01%) ⬆️
unit-tests-ibis-Linux-py3.12-pandas2.3.3-polars 28.09% <50.00%> (+<0.01%) ⬆️
unit-tests-ibis-Linux-py3.13-pandas2.3.3-polars 28.09% <50.00%> (+<0.01%) ⬆️
unit-tests-ibis-Linux-py3.14-pandas2.3.3-polars 27.90% <50.00%> (+<0.01%) ⬆️
unit-tests-ibis-Windows-py3.10-pandas2.3.3-polars 28.02% <50.00%> (+<0.01%) ⬆️
unit-tests-ibis-Windows-py3.11-pandas2.3.3-polars 28.02% <50.00%> (-0.01%) ⬇️
unit-tests-ibis-Windows-py3.12-pandas2.3.3-polars 28.02% <50.00%> (+<0.01%) ⬆️
unit-tests-ibis-Windows-py3.13-pandas2.3.3-polars 28.02% <50.00%> (+<0.01%) ⬆️
unit-tests-ibis-Windows-py3.14-pandas2.3.3-polars 27.83% <50.00%> (+<0.01%) ⬆️
unit-tests-ibis-macOS-py3.10-pandas2.3.3-polars 28.03% <50.00%> (-0.01%) ⬇️
unit-tests-ibis-macOS-py3.11-pandas2.3.3-polars 28.03% <50.00%> (+<0.01%) ⬆️
unit-tests-io-Linux-py3.10-pandas2.3.3-pydantic2.12.3 37.20% <50.00%> (-0.01%) ⬇️
unit-tests-io-Linux-py3.11-pandas2.3.3-pydantic2.12.3 37.24% <50.00%> (-0.95%) ⬇️
unit-tests-io-Linux-py3.12-pandas2.3.3-pydantic2.12.3 37.24% <50.00%> (-0.95%) ⬇️
unit-tests-io-Linux-py3.13-pandas3.0.0-pydantic2.12.3 37.21% <50.00%> (-0.01%) ⬇️
unit-tests-io-Linux-py3.14-pandas3.0.0-pydantic2.12.3 37.11% <50.00%> (-0.01%) ⬇️
unit-tests-io-Windows-py3.11-pandas3.0.0-pydantic2.12.3 36.87% <50.00%> (-0.94%) ⬇️
unit-tests-modin-ray-Linux-py3.10-pandas2.3.3-polars 29.89% <50.00%> (+<0.01%) ⬆️
unit-tests-modin-ray-Linux-py3.11-pandas2.3.3-polars 29.89% <50.00%> (+<0.01%) ⬆️
unit-tests-modin-ray-Linux-py3.12-pandas2.3.3-polars 29.89% <50.00%> (+<0.01%) ⬆️
unit-tests-narwhals-Linux-py3.10 40.37% <50.00%> (-0.01%) ⬇️
unit-tests-narwhals-Linux-py3.11 40.36% <50.00%> (-0.01%) ⬇️
unit-tests-narwhals-Linux-py3.12 40.36% <50.00%> (-0.01%) ⬇️
unit-tests-narwhals-Linux-py3.13 40.36% <50.00%> (-0.01%) ⬇️
unit-tests-narwhals-Linux-py3.14 40.20% <50.00%> (-0.01%) ⬇️
unit-tests-narwhals-backend-ibis-py3.10 31.60% <50.00%> (+<0.01%) ⬆️
unit-tests-narwhals-backend-ibis-py3.11 31.48% <0.00%> (-0.01%) ⬇️
unit-tests-narwhals-backend-ibis-py3.12 31.48% <0.00%> (-0.01%) ⬇️
unit-tests-narwhals-backend-ibis-py3.13 31.48% <0.00%> (-0.01%) ⬇️
unit-tests-narwhals-backend-ibis-py3.14 31.28% <0.00%> (-0.01%) ⬇️
unit-tests-narwhals-backend-polars-py3.10 36.06% <0.00%> (-0.01%) ⬇️
unit-tests-narwhals-backend-polars-py3.11 36.05% <0.00%> (-0.01%) ⬇️
unit-tests-narwhals-backend-polars-py3.12 36.05% <0.00%> (-0.01%) ⬇️
unit-tests-narwhals-backend-polars-py3.13 36.05% <0.00%> (-0.01%) ⬇️
unit-tests-narwhals-backend-polars-py3.14 35.92% <0.00%> (-0.01%) ⬇️
unit-tests-narwhals-backend-pyspark-py3.10 43.23% <50.00%> (-0.01%) ⬇️
unit-tests-narwhals-backend-pyspark-py3.11 43.26% <50.00%> (-0.01%) ⬇️
unit-tests-pandas-Linux-py3.10-pandas2.3.3-pydantic1.10.11 41.74% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Linux-py3.10-pandas2.3.3-pydantic2.12.3 41.89% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Linux-py3.11-pandas2.3.3-pydantic1.10.11 41.74% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Linux-py3.11-pandas2.3.3-pydantic2.12.3 41.89% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Linux-py3.11-pandas3.0.0-pydantic1.10.11 41.75% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Linux-py3.11-pandas3.0.0-pydantic2.12.3 41.90% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Linux-py3.12-pandas2.3.3-pydantic1.10.11 41.73% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Linux-py3.12-pandas2.3.3-pydantic2.12.3 41.88% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Linux-py3.12-pandas3.0.0-pydantic2.12.3 41.89% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Linux-py3.13-pandas2.3.3-pydantic1.10.11 41.73% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Linux-py3.13-pandas2.3.3-pydantic2.12.3 41.88% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Linux-py3.13-pandas3.0.0-pydantic1.10.11 41.74% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Linux-py3.13-pandas3.0.0-pydantic2.12.3 41.89% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Linux-py3.14-pandas2.3.3-pydantic2.12.3 41.86% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Linux-py3.14-pandas3.0.0-pydantic2.12.3 41.87% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Windows-py3.10-pandas2.3.3-pydantic1.10.11 41.65% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Windows-py3.10-pandas2.3.3-pydantic2.12.3 41.81% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Windows-py3.11-pandas2.3.3-pydantic1.10.11 41.65% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Windows-py3.11-pandas2.3.3-pydantic2.12.3 41.81% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Windows-py3.11-pandas3.0.0-pydantic1.10.11 41.67% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Windows-py3.11-pandas3.0.0-pydantic2.12.3 41.82% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Windows-py3.12-pandas2.3.3-pydantic1.10.11 41.64% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Windows-py3.12-pandas2.3.3-pydantic2.12.3 41.79% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Windows-py3.12-pandas3.0.0-pydantic1.10.11 41.65% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Windows-py3.12-pandas3.0.0-pydantic2.12.3 41.81% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Windows-py3.13-pandas2.3.3-pydantic1.10.11 41.64% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Windows-py3.13-pandas2.3.3-pydantic2.12.3 41.79% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Windows-py3.13-pandas3.0.0-pydantic1.10.11 41.65% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Windows-py3.13-pandas3.0.0-pydantic2.12.3 41.81% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Windows-py3.14-pandas2.3.3-pydantic2.12.3 41.77% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-Windows-py3.14-pandas3.0.0-pydantic2.12.3 41.79% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-macOS-py3.10-pandas2.3.3-pydantic1.10.11 41.68% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-macOS-py3.10-pandas2.3.3-pydantic2.12.3 41.83% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-macOS-py3.11-pandas2.3.3-pydantic1.10.11 41.68% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-macOS-py3.11-pandas2.3.3-pydantic2.12.3 41.83% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-macOS-py3.11-pandas3.0.0-pydantic1.10.11 41.69% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-macOS-py3.11-pandas3.0.0-pydantic2.12.3 41.84% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-macOS-py3.12-pandas2.3.3-pydantic1.10.11 41.67% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-macOS-py3.12-pandas2.3.3-pydantic2.12.3 41.82% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-macOS-py3.12-pandas3.0.0-pydantic1.10.11 41.68% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-macOS-py3.12-pandas3.0.0-pydantic2.12.3 41.83% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-macOS-py3.13-pandas2.3.3-pydantic1.10.11 41.67% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-macOS-py3.13-pandas2.3.3-pydantic2.12.3 41.82% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-macOS-py3.13-pandas3.0.0-pydantic1.10.11 41.68% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-macOS-py3.13-pandas3.0.0-pydantic2.12.3 41.83% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-macOS-py3.14-pandas2.3.3-pydantic2.12.3 41.80% <100.00%> (+0.01%) ⬆️
unit-tests-pandas-macOS-py3.14-pandas3.0.0-pydantic2.12.3 41.81% <100.00%> (+0.01%) ⬆️
unit-tests-polars-Linux-py3.10-pandas2.3.3-polars1.33.1 30.25% <0.00%> (-0.01%) ⬇️
unit-tests-polars-Linux-py3.11-pandas2.3.3-polars1.33.1 30.24% <0.00%> (-0.01%) ⬇️
unit-tests-polars-Linux-py3.12-pandas2.3.3-polars1.33.1 30.24% <0.00%> (-0.01%) ⬇️
unit-tests-polars-Linux-py3.13-pandas2.3.3-polars1.33.1 30.24% <0.00%> (-0.01%) ⬇️
unit-tests-polars-Linux-py3.14-pandas2.3.3-polars1.33.1 30.12% <0.00%> (-0.01%) ⬇️
unit-tests-polars-Windows-py3.10-pandas2.3.3-polars1.33.1 30.18% <0.00%> (-0.01%) ⬇️
unit-tests-polars-Windows-py3.11-pandas2.3.3-polars1.33.1 30.17% <0.00%> (-0.01%) ⬇️
unit-tests-polars-Windows-py3.12-pandas2.3.3-polars1.33.1 30.17% <0.00%> (-0.01%) ⬇️
unit-tests-polars-Windows-py3.13-pandas2.3.3-polars1.33.1 30.17% <0.00%> (-0.01%) ⬇️
unit-tests-polars-Windows-py3.14-pandas2.3.3-polars1.33.1 30.04% <0.00%> (-0.01%) ⬇️
unit-tests-pyspark-Linux-py3.10-pandas2.3.3-polars 38.00% <50.00%> (-0.01%) ⬇️
unit-tests-pyspark-Linux-py3.11-pandas2.3.3-polars 38.00% <50.00%> (-0.01%) ⬇️
unit-tests-strategies-Linux-py3.11-pandas2.3.3-pydantic2.12.3 33.36% <50.00%> (ø)
unit-tests-strategies-Linux-py3.12-pandas3.0.0-pydantic2.12.3 33.35% <50.00%> (-0.88%) ⬇️
unit-tests-strategies-Linux-py3.13-pandas3.0.0-pydantic2.12.3 33.35% <50.00%> (-0.84%) ⬇️
unit-tests-xarray-Linux-py3.10-pandas2.3.3-polars 30.96% <0.00%> (-0.01%) ⬇️
unit-tests-xarray-Linux-py3.11-pandas2.3.3-polars 30.96% <0.00%> (-0.01%) ⬇️
unit-tests-xarray-Linux-py3.12-pandas2.3.3-polars 30.96% <0.00%> (-0.01%) ⬇️
unit-tests-xarray-Linux-py3.13-pandas2.3.3-polars 30.96% <0.00%> (-0.01%) ⬇️
unit-tests-xarray-Linux-py3.14-pandas2.3.3-polars 30.89% <0.00%> (-0.01%) ⬇️
unit-tests-xarray-Windows-py3.10-pandas2.3.3-polars 30.89% <0.00%> (-0.01%) ⬇️
unit-tests-xarray-Windows-py3.11-pandas2.3.3-polars 30.89% <0.00%> (-0.01%) ⬇️
unit-tests-xarray-Windows-py3.12-pandas2.3.3-polars 30.89% <0.00%> (-0.01%) ⬇️
unit-tests-xarray-Windows-py3.13-pandas2.3.3-polars 30.89% <0.00%> (-0.01%) ⬇️
unit-tests-xarray-Windows-py3.14-pandas2.3.3-polars 30.82% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cosmicbboy
cosmicbboy merged commit 37c43df into unionai-oss:main Aug 19, 2026
324 checks passed
barlowa124 pushed a commit to barlowa124/pandera that referenced this pull request Dec 4, 2026
…onai-oss#2437)

Declaring a column with a sized numpy dtype raised a confusing TypeError
that named a dtype the user never wrote:

    pa.DataFrameSchema({"a": pa.Column(np.dtype("S16"))})
    TypeError: data type 'bytes128' not understood

Engine.dtype normalizes platform-specific aliases by round-tripping the
dtype through its name, so that e.g. np.intc becomes np.int32. That works
for fixed-width numeric dtypes, whose name is itself a valid dtype string,
but not for itemsize-parameterized ones: np.dtype("S16").name is
"bytes128", np.dtype("U16").name is "str512", and neither parses back.

Fall back to the dtype itself when the name does not round-trip. Its
scalar type is already platform-agnostic, so the subsequent .type lookup
resolves as it does for the unsized spelling: np.dtype("S16") now resolves
the same as bytes, and np.dtype("U16") the same as np.str_.

Note that using np_or_pd_dtype.type directly instead of the round-trip
would be simpler but silently regress the normalization this code exists
for -- np.dtype("longlong").type is np.longlong, not np.int64 -- so the
round-trip is kept and only guarded. Tests cover both directions.

Fixes unionai-oss#1270

Signed-off-by: Karthik Mannem <180236770+mannemkarthik010@users.noreply.github.com>
barlowa124 pushed a commit to barlowa124/pandera that referenced this pull request Dec 4, 2026
…onai-oss#2437)

Declaring a column with a sized numpy dtype raised a confusing TypeError
that named a dtype the user never wrote:

    pa.DataFrameSchema({"a": pa.Column(np.dtype("S16"))})
    TypeError: data type 'bytes128' not understood

Engine.dtype normalizes platform-specific aliases by round-tripping the
dtype through its name, so that e.g. np.intc becomes np.int32. That works
for fixed-width numeric dtypes, whose name is itself a valid dtype string,
but not for itemsize-parameterized ones: np.dtype("S16").name is
"bytes128", np.dtype("U16").name is "str512", and neither parses back.

Fall back to the dtype itself when the name does not round-trip. Its
scalar type is already platform-agnostic, so the subsequent .type lookup
resolves as it does for the unsized spelling: np.dtype("S16") now resolves
the same as bytes, and np.dtype("U16") the same as np.str_.

Note that using np_or_pd_dtype.type directly instead of the round-trip
would be simpler but silently regress the normalization this code exists
for -- np.dtype("longlong").type is np.longlong, not np.int64 -- so the
round-trip is kept and only guarded. Tests cover both directions.

Fixes unionai-oss#1270

Signed-off-by: Karthik Mannem <180236770+mannemkarthik010@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for numpy data type objects or dtypes not working

2 participants