Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
UNRELEASED
----------

*UNRELEASED*

* `#208 <https://github.com/ESSS/pytest-regressions/issues/208>`__: Fixed support for ``pandas.StringDtype`` columns in ``dataframe_regression``, including when the first value is NA.

2.11.0
------

Expand Down
4 changes: 4 additions & 0 deletions src/pytest_regressions/dataframe_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ def check(
if isinstance(array.dtype, pd.CategoricalDtype):
continue

# pandas StringDtype columns are supported (#208).
if isinstance(array.dtype, pd.StringDtype):
continue

# Arrays of strings are supported.
if (array.dtype.kind == "O") and (type(array.iloc[0]) is str):
continue
Expand Down
24 changes: 24 additions & 0 deletions tests/test_dataframe_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,27 @@ def test_categorical(dataframe_regression: DataFrameRegressionFixture) -> None:

df = pd.DataFrame.from_dict({"types": types})
dataframe_regression.check(df)


def test_string_dtype(dataframe_regression: DataFrameRegressionFixture) -> None:
"""Support for pandas StringDtype columns (#208)."""
df = pd.DataFrame(
{
"name": pd.Series(["Alice", "Bob", "Charlie"], dtype="string"),
"age": [25, 30, 35],
"city": pd.Series(["New York", "London", "Paris"], dtype="string"),
}
)
dataframe_regression.check(df)


def test_string_dtype_with_na(
dataframe_regression: DataFrameRegressionFixture,
) -> None:
"""StringDtype columns whose first value is NA are still string columns (#208)."""
df = pd.DataFrame(
{
"name": pd.Series([pd.NA, "Bob", "Charlie"], dtype="string"),
}
)
dataframe_regression.check(df)
4 changes: 4 additions & 0 deletions tests/test_dataframe_regression/test_string_dtype.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
,name,age,city
0,Alice,25,New York
1,Bob,30,London
2,Charlie,35,Paris
4 changes: 4 additions & 0 deletions tests/test_dataframe_regression/test_string_dtype_with_na.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
,name
0,
1,Bob
2,Charlie