From 0b188ab6ad247a15daa663d67351b725a434ea43 Mon Sep 17 00:00:00 2001 From: Matthew Barber Date: Fri, 22 Jul 2022 10:22:22 +0100 Subject: [PATCH] Assume unmerged spec behaviour https://github.com/data-apis/dataframe-api/pull/74 --- tests/conftest.py | 29 +++++++++++++++++------------ tests/test_column_object.py | 2 +- tests/test_dataframe_object.py | 10 ++-------- tests/wrappers.py | 12 +++--------- 4 files changed, 23 insertions(+), 30 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 2308f63..35ef4b0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,4 @@ +import re from typing import Union import pytest @@ -38,17 +39,15 @@ def pytest_configure(config): ci_failing_ids = [ - # dataframe objects return the interchange dataframe, not a dict, although - # this is the behaviour that should be in the spec soon. - # See https://github.com/data-apis/dataframe-api/pull/74 - "test_dataframe_object.py::test_toplevel_dunder_dataframe[pandas]", - "test_dataframe_object.py::test_toplevel_dunder_dataframe[vaex]", - "test_dataframe_object.py::test_toplevel_dunder_dataframe[modin]", - "test_dataframe_object.py::test_dunder_dataframe[pandas]", - "test_dataframe_object.py::test_dunder_dataframe[modin]", - # vaex's interchange dataframe doesn't have __dataframe__() + # vaex's and cudf's interchange dataframe doesn't have __dataframe__() + # See https://github.com/data-apis/dataframe-api/issues/80 "test_dataframe_object.py::test_dunder_dataframe[vaex]", "test_signatures.py::test_dataframe_method[vaex-__dataframe__]", + "test_dataframe_object.py::test_dunder_dataframe[cudf]", + "test_signatures.py::test_dataframe_method[cudf-__dataframe__]", + # https://github.com/rapidsai/cudf/issues/11320 + "test_signatures.py::test_buffer_method[cudf-__dlpack__]", + "test_signatures.py::test_buffer_method[cudf-__dlpack_device__]", # https://github.com/vaexio/vaex/issues/2083 # https://github.com/vaexio/vaex/issues/2093 # https://github.com/vaexio/vaex/issues/2113 @@ -59,11 +58,13 @@ def pytest_configure(config): "test_column_object.py::test_size[vaex]", # https://github.com/vaexio/vaex/issues/2118 "test_column_object.py::test_dtype[vaex]", - # Raises TypeError as opposed to RuntimeError, although this is the - # behaviour that should be in the spec soon. + # Raises RuntimeError, which is technically correct, but the spec will + # require TypeError soon. # See https://github.com/data-apis/dataframe-api/pull/74 - "test_column_object.py::test_describe_categorical[pandas]", + "test_column_object.py::test_describe_categorical[modin]", + # https://github.com/vaexio/vaex/issues/2113 "test_column_object.py::test_describe_categorical[vaex]", + # https://github.com/rapidsai/cudf/issues/11332 "test_column_object.py::test_describe_categorical[cudf]", # https://github.com/pandas-dev/pandas/issues/47789 "test_column_object.py::test_null_count[pandas]", @@ -79,9 +80,13 @@ def pytest_configure(config): "test_column_object.py::test_get_buffers[cudf]", ] +r_cudf_roundtrip = re.compile(r"test_from_dataframe_roundtrip\[.*cudf.*\]") + def pytest_collection_modifyitems(config, items): if config.getoption("--ci"): for item in items: if any(id_ in item.nodeid for id_ in ci_failing_ids): item.add_marker(pytest.mark.xfail()) + elif r_cudf_roundtrip.search(item.nodeid): + item.add_marker(pytest.mark.skip("TODO")) diff --git a/tests/test_column_object.py b/tests/test_column_object.py index 338a688..6631672 100644 --- a/tests/test_column_object.py +++ b/tests/test_column_object.py @@ -99,7 +99,7 @@ def test_describe_categorical(libinfo: LibraryInfo, data: st.DataObject): if mapping is not None: assert isinstance(mapping, dict) else: - with pytest.raises(RuntimeError): + with pytest.raises(TypeError): col.describe_categorical diff --git a/tests/test_dataframe_object.py b/tests/test_dataframe_object.py index ac96f61..de0aae1 100644 --- a/tests/test_dataframe_object.py +++ b/tests/test_dataframe_object.py @@ -11,20 +11,14 @@ def test_toplevel_dunder_dataframe(libinfo: LibraryInfo, data: st.DataObject): df = data.draw(libinfo.toplevel_dataframes(), label="df") assert hasattr(df, "__dataframe__") - out = df.__dataframe__() - assert isinstance(out, dict) - assert hasattr(out, "dataframe") - assert hasattr(out, "version") + df.__dataframe__() @given(data=st.data()) def test_dunder_dataframe(libinfo: LibraryInfo, data: st.DataObject): df = data.draw(libinfo.interchange_dataframes(), label="df") assert hasattr(df, "__dataframe__") - out = df.__dataframe__() - assert isinstance(out, dict) - assert hasattr(out, "dataframe") - assert hasattr(out, "version") + df.__dataframe__() @given(data=st.data()) diff --git a/tests/wrappers.py b/tests/wrappers.py index 2784506..989d664 100644 --- a/tests/wrappers.py +++ b/tests/wrappers.py @@ -19,15 +19,13 @@ class LibraryInfo(NamedTuple): mock_to_toplevel: Callable[[MockDataFrame], TopLevelDataFrame] from_dataframe: Callable[[TopLevelDataFrame], DataFrame] frame_equal: Callable[[TopLevelDataFrame, DataFrame], bool] - toplevel_to_interchange: Callable[[TopLevelDataFrame], DataFrame] = lambda df: ( - df.__dataframe__()["dataframe"] - ) exclude_dtypes: List[NominalDtype] = [] allow_zero_cols: bool = True allow_zero_rows: bool = True def mock_to_interchange(self, mock_dataframe: MockDataFrame) -> DataFrame: - return self.toplevel_to_interchange(self.mock_to_toplevel(mock_dataframe)) + toplevel_df = self.mock_to_toplevel(mock_dataframe) + return toplevel_df.__dataframe__() @property def mock_dataframes_kwargs(self) -> Dict[str, Any]: @@ -44,7 +42,7 @@ def toplevel_dataframes(self) -> st.SearchStrategy[TopLevelDataFrame]: return self.mock_dataframes().map(self.mock_to_toplevel) def interchange_dataframes(self) -> st.SearchStrategy[TopLevelDataFrame]: - return self.toplevel_dataframes().map(self.toplevel_to_interchange) + return self.toplevel_dataframes().map(lambda df: df.__dataframe__()) def __repr__(self) -> str: return f"LibraryInfo(<{self.name}>)" @@ -82,7 +80,6 @@ def pandas_mock_to_toplevel(mock_df: MockDataFrame) -> pd.DataFrame: mock_to_toplevel=pandas_mock_to_toplevel, from_dataframe=pandas_from_dataframe, frame_equal=lambda df1, df2: df1.equals(df2), - toplevel_to_interchange=lambda df: df.__dataframe__(), exclude_dtypes=[NominalDtype.DATETIME64NS], ) libinfo_params.append(pytest.param(pandas_libinfo, id=pandas_libinfo.name)) @@ -140,7 +137,6 @@ def vaex_frame_equal(df1, df2) -> bool: mock_to_toplevel=vaex_mock_to_toplevel, from_dataframe=vaex_from_dataframe, frame_equal=vaex_frame_equal, - toplevel_to_interchange=lambda df: df.__dataframe__(), exclude_dtypes=[NominalDtype.DATETIME64NS], # https://github.com/vaexio/vaex/issues/2094 allow_zero_cols=False, @@ -220,7 +216,6 @@ def modin_frame_equal(df1: mpd.DataFrame, df2: mpd.DataFrame) -> bool: mock_to_toplevel=modin_mock_to_toplevel, from_dataframe=modin_from_dataframe, frame_equal=modin_frame_equal, - toplevel_to_interchange=lambda df: df.__dataframe__(), # https://github.com/modin-project/modin/issues/4654 # https://github.com/modin-project/modin/issues/4652 exclude_dtypes=[ @@ -297,7 +292,6 @@ def cudf_mock_to_toplevel(mock_df: MockDataFrame) -> cudf.DataFrame: mock_to_toplevel=cudf_mock_to_toplevel, from_dataframe=cudf_from_dataframe, frame_equal=lambda df1, df2: df1.equals(df2), # NaNs considered equal - toplevel_to_interchange=lambda df: df.__dataframe__(), exclude_dtypes=[NominalDtype.DATETIME64NS], ) libinfo_params.append(pytest.param(cupy_libinfo, id=cupy_libinfo.name))