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
6 changes: 5 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ jobs:
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
os: [ubuntu-latest, windows-latest]
pandas-version: [pd2, pd3]
exclude:
- python-version: "3.10" # pd3 requires python >= 3.11
pandas-version: pd3

steps:
- uses: actions/checkout@v6
Expand All @@ -57,4 +61,4 @@ jobs:
- name: Test
shell: bash
run: |
tox run -e py --installpkg `find dist/*.tar.gz`
tox run -e ${{ matrix.pandas-version }} --installpkg `find dist/*.tar.gz`
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
UNRELEASED
----------

*UNRELEASED*

* `#225 <https://github.com/ESSS/pytest-regressions/issues/225>`__: Add support for Pandas 3.0 to `dataframe_regression`.

2.9.1
-----

Expand Down
18 changes: 12 additions & 6 deletions src/pytest_regressions/dataframe_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def _check_data_types(
raise ModuleNotFoundError(import_error_message("NumPy"))

__tracebackhide__ = True
obtained_data_type = obtained_column.values.dtype
expected_data_type = expected_column.values.dtype
obtained_data_type = obtained_column.values.dtype.type
expected_data_type = expected_column.values.dtype.type
if obtained_data_type != expected_data_type:
# Check if both data types are comparable as numbers (float, int, short, bytes, etc...)
if np.issubdtype(obtained_data_type, np.number) and np.issubdtype(
Expand Down Expand Up @@ -134,7 +134,7 @@ def _check_fn(self, obtained_filename: Path, expected_filename: Path) -> None:
self._check_data_types(k, obtained_column, expected_column)
self._check_data_shapes(obtained_column, expected_column)

if np.issubdtype(obtained_column.values.dtype, np.inexact):
if np.issubdtype(obtained_column.values.dtype.type, np.inexact):
not_close_mask = ~np.isclose(
obtained_column.values,
expected_column.values,
Expand All @@ -156,7 +156,10 @@ def _check_fn(self, obtained_filename: Path, expected_filename: Path) -> None:
diff_expected_data = expected_column[diff_ids]
if obtained_column.values.dtype == bool:
diffs = np.logical_xor(obtained_column, expected_column)[diff_ids]
elif obtained_column.values.dtype == object:
elif (
obtained_column.values.dtype == object
or obtained_column.values.dtype == "str"
):
diffs = diff_obtained_data.copy()
diffs[:] = "?"
else:
Expand All @@ -173,7 +176,10 @@ def _check_fn(self, obtained_filename: Path, expected_filename: Path) -> None:
error_msg += "To update values, use --force-regen option.\n\n"
for k, comparison_table in comparison_tables_dict.items():
error_msg += f"{k}:\n{comparison_table}\n\n"
if obtained_column.values.dtype == object:
if (
obtained_column.values.dtype == object
or obtained_column.values.dtype == "str"
):
error_msg += (
"WARNING: diffs for this kind of data type cannot be computed."
)
Expand Down Expand Up @@ -255,7 +261,7 @@ def check(
continue

# Arrays of strings are supported.
if (array.dtype == "O") and (type(array.iloc[0]) is str):
if (array.dtype.kind == "O") and (type(array.iloc[0]) is str):
continue
# Rejected: timedelta, objects, zero-terminated bytes, unicode strings and raw data
assert array.dtype.kind not in ["m", "O", "S", "U", "V"], (
Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
[tox]
envlist = py310,py311,py312,py313,py314,pytest6
envlist = py310,py311,py312,py313,py314,pytest6,pd2,pd3

[testenv]
download = true
extras = dev
commands = pytest {posargs:tests}
deps =
pytest6: pytest ~= 6.2
pd2: pandas < 3.0.0
pd3: pandas >= 3.0.0


[pytest]
Expand Down