Skip to content

Commit c815a6d

Browse files
authored
fix: pandas pyarrow string validation (#1636)
Signed-off-by: Ajith Aravind <[email protected]>
1 parent 18aacca commit c815a6d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

pandera/engines/pandas_engine.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1660,7 +1660,9 @@ class ArrowInt8(ArrowInt16):
16601660
type = pd.ArrowDtype(pyarrow.int8())
16611661
bit_width: int = 8
16621662

1663-
@Engine.register_dtype(equivalents=[pyarrow.string])
1663+
@Engine.register_dtype(
1664+
equivalents=[pyarrow.string, pd.ArrowDtype(pyarrow.string())]
1665+
)
16641666
@immutable
16651667
class ArrowString(DataType, dtypes.String):
16661668
"""Semantic representation of a :class:`pyarrow.string`."""

tests/core/test_dtypes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,12 @@ def test_invalid_pandas_extension_dtype():
311311

312312
def test_check_equivalent(dtype: Any, pd_dtype: Any):
313313
"""Test that a pandas-compatible dtype can be validated by check()."""
314+
if (
315+
pandas_engine.PYARROW_INSTALLED
316+
and pandas_engine.PANDAS_2_0_0_PLUS
317+
and dtype == "string[pyarrow]"
318+
):
319+
pytest.skip("`string[pyarrow]` gets parsed to type `string` by pandas")
314320
actual_dtype = pandas_engine.Engine.dtype(pd_dtype)
315321
expected_dtype = pandas_engine.Engine.dtype(dtype)
316322
assert actual_dtype.check(expected_dtype)

0 commit comments

Comments
 (0)