diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0672c84..025418a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 @@ -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` diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c0ca09e..615fdd9 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,10 @@ +UNRELEASED +---------- + +*UNRELEASED* + +* `#225 `__: Add support for Pandas 3.0 to `dataframe_regression`. + 2.9.1 ----- diff --git a/src/pytest_regressions/dataframe_regression.py b/src/pytest_regressions/dataframe_regression.py index 034846c..eaa6153 100644 --- a/src/pytest_regressions/dataframe_regression.py +++ b/src/pytest_regressions/dataframe_regression.py @@ -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( @@ -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, @@ -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: @@ -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." ) @@ -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"], ( diff --git a/tox.ini b/tox.ini index 2cc2c5a..08d0819 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py310,py311,py312,py313,py314,pytest6 +envlist = py310,py311,py312,py313,py314,pytest6,pd2,pd3 [testenv] download = true @@ -7,6 +7,8 @@ extras = dev commands = pytest {posargs:tests} deps = pytest6: pytest ~= 6.2 + pd2: pandas < 3.0.0 + pd3: pandas >= 3.0.0 [pytest]