Skip to content

Commit

Permalink
Assume unmerged spec behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
honno committed Jul 22, 2022
1 parent 3240e5a commit 0b188ab
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 30 deletions.
29 changes: 17 additions & 12 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from typing import Union

import pytest
Expand Down Expand Up @@ -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
Expand All @@ -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]",
Expand All @@ -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"))
2 changes: 1 addition & 1 deletion tests/test_column_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
10 changes: 2 additions & 8 deletions tests/test_dataframe_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
12 changes: 3 additions & 9 deletions tests/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand All @@ -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}>)"
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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=[
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 0b188ab

Please sign in to comment.