Skip to content

Commit

Permalink
refactor(tests): remove UnorderedComparator class
Browse files Browse the repository at this point in the history
Merging into `BackendTest` and replacing with class variable
  • Loading branch information
gforsyth authored and cpcloud committed Nov 29, 2023
1 parent f95f1d8 commit ab0a8f6
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 35 deletions.
22 changes: 22 additions & 0 deletions docs/contribute/BackendTest.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#+title: Backend Test

| Variable | Default | Type | Description | Required |
|-------------------------------------+------------------------------+---------------------------+-------------------------------------------------------------------------+----------|
| ~check_dtype~ | True | Bool | check that dtypes match when comparing Pandas ~series~ | True |
| ~check_names~ | True | Bool | check that column name matches when comparing Pandas ~series~ | True |
| ~supports_arrays~ | True | Bool | backend supports arrays | |
| ~supports_arrays_outside_of_select~ | True | Bool | backend supports arrays outside of select statements | |
| ~supports_window_operations~ | True | Bool | backend supports windowing | |
| ~supports_divide_by_zero~ | False | Bool | backend supports division by zero | |
| ~returned_timestamp_unit~ | "us" | Unit abbreviation | precision of timestamp unit returned | |
| ~supported_to_timestamp_units~ | {"s", "ms", "us"} | Set of unit abbreviations | supported units of precision for timestamps | |
| ~supports_floating_modulus~ | True | Bool | backend supports floating numbers in modulus operations | |
| ~native_bool~ | True | Bool | backend has native boolean types | |
| ~supports_structs~ | True | Bool | backend supports structs | |
| ~supports_json~ | True | Bool | backend supports JSON | |
| ~supports_map~ | False | Bool | backend supports maps basically nothing does except trino and snowflake | |
| ~reduction_tolerance~ | 1e-7 | Float | | |
| ~default_identifier_case_fn~ | staticmethod(toolz.identity) | Function | | |
| ~stateful~ | True | Bool | | |
| ~service_name~ | None | | | |
| ~supports_tpch~ | False | Bool | | |
8 changes: 3 additions & 5 deletions ibis/backends/bigquery/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ibis.backends.bigquery import EXTERNAL_DATA_SCOPES, Backend
from ibis.backends.bigquery.datatypes import BigQuerySchema
from ibis.backends.conftest import TEST_TABLES
from ibis.backends.tests.base import BackendTest, RoundAwayFromZero, UnorderedComparator
from ibis.backends.tests.base import BackendTest, RoundAwayFromZero
from ibis.backends.tests.data import json_types, non_null_array_types, struct_types, win

DATASET_ID = "ibis_gbq_testing"
Expand All @@ -25,18 +25,16 @@
PROJECT_ID_ENV_VAR = "GOOGLE_BIGQUERY_PROJECT_ID"


class TestConf(UnorderedComparator, BackendTest, RoundAwayFromZero):
class TestConf(BackendTest, RoundAwayFromZero):
"""Backend-specific class with information for testing."""

# These were moved from TestConf for use in common test suite.
# TODO: Indicate RoundAwayFromZero and UnorderedComparator.
# https://github.com/ibis-project/ibis-bigquery/issues/30
supports_divide_by_zero = True
supports_floating_modulus = False
returned_timestamp_unit = "us"
supports_structs = True
supports_json = True
check_names = False
force_sort_before_comparison = True
deps = ("google.cloud.bigquery",)

@staticmethod
Expand Down
9 changes: 3 additions & 6 deletions ibis/backends/clickhouse/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
import ibis
import ibis.expr.types as ir
from ibis import util
from ibis.backends.tests.base import (
RoundHalfToEven,
ServiceBackendTest,
UnorderedComparator,
)
from ibis.backends.tests.base import RoundHalfToEven, ServiceBackendTest

if TYPE_CHECKING:
from collections.abc import Iterable
Expand All @@ -26,13 +22,14 @@
IBIS_TEST_CLICKHOUSE_DB = os.environ.get("IBIS_TEST_DATA_DB", "ibis_testing")


class TestConf(UnorderedComparator, ServiceBackendTest, RoundHalfToEven):
class TestConf(ServiceBackendTest, RoundHalfToEven):
check_dtype = False
supports_window_operations = False
returned_timestamp_unit = "s"
supported_to_timestamp_units = {"s"}
supports_floating_modulus = False
supports_json = False
force_sort_before_comparison = True
data_volume = "/var/lib/clickhouse/user_files/ibis"
service_name = "clickhouse"
deps = ("clickhouse_connect",)
Expand Down
5 changes: 3 additions & 2 deletions ibis/backends/flink/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

import ibis
from ibis.backends.conftest import TEST_TABLES
from ibis.backends.tests.base import BackendTest, RoundAwayFromZero, UnorderedComparator
from ibis.backends.tests.base import BackendTest, RoundAwayFromZero


class TestConf(UnorderedComparator, BackendTest, RoundAwayFromZero):
class TestConf(BackendTest, RoundAwayFromZero):
supports_structs = False
force_sort_before_comparison = True
deps = "pandas", "pyflink"

@staticmethod
Expand Down
5 changes: 3 additions & 2 deletions ibis/backends/impala/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@
from ibis import options, util
from ibis.backends.conftest import TEST_TABLES
from ibis.backends.impala.compiler import ImpalaCompiler, ImpalaExprTranslator
from ibis.backends.tests.base import BackendTest, RoundAwayFromZero, UnorderedComparator
from ibis.backends.tests.base import BackendTest, RoundAwayFromZero
from ibis.backends.tests.data import win
from ibis.tests.expr.mocks import MockBackend


class TestConf(UnorderedComparator, BackendTest, RoundAwayFromZero):
class TestConf(BackendTest, RoundAwayFromZero):
supports_arrays = True
supports_arrays_outside_of_select = False
check_dtype = False
supports_divide_by_zero = True
returned_timestamp_unit = "s"
supports_structs = False
supports_json = False
force_sort_before_comparison = True
deps = "fsspec", "requests", "impala"

def _load_data(self, **_: Any) -> None:
Expand Down
28 changes: 8 additions & 20 deletions ibis/backends/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,6 @@ def round(series: pd.Series, decimals: int = 0) -> pd.Series:
return result if decimals else result.astype(np.int64)


# TODO: Merge into BackendTest, #2564
class UnorderedComparator:
@classmethod
def assert_series_equal(
cls, left: pd.Series, right: pd.Series, *args: Any, **kwargs: Any
) -> None:
left = left.sort_values().reset_index(drop=True)
right = right.sort_values().reset_index(drop=True)
return super().assert_series_equal(left, right, *args, **kwargs)

@classmethod
def assert_frame_equal(
cls, left: pd.DataFrame, right: pd.DataFrame, *args: Any, **kwargs: Any
) -> None:
columns = list(set(left.columns) & set(right.columns))
left = left.sort_values(by=columns)
right = right.sort_values(by=columns)
return super().assert_frame_equal(left, right, *args, **kwargs)


class BackendTest(abc.ABC):
check_dtype = True
check_names = True
Expand All @@ -86,6 +66,7 @@ class BackendTest(abc.ABC):
stateful = True
service_name = None
supports_tpch = False
force_sort_before_comparison = False

@property
@abc.abstractmethod
Expand Down Expand Up @@ -185,6 +166,9 @@ def postload(self, **_): # noqa: B027
def assert_series_equal(
cls, left: pd.Series, right: pd.Series, *args: Any, **kwargs: Any
) -> None:
if cls.force_sort_before_comparison:
left = left.sort_values().reset_index(drop=True)
right = right.sort_values().reset_index(drop=True)
kwargs.setdefault("check_dtype", cls.check_dtype)
kwargs.setdefault("check_names", cls.check_names)
tm.assert_series_equal(left, right, *args, **kwargs)
Expand All @@ -193,6 +177,10 @@ def assert_series_equal(
def assert_frame_equal(
cls, left: pd.DataFrame, right: pd.DataFrame, *args: Any, **kwargs: Any
) -> None:
if cls.force_sort_before_comparison:
columns = list(set(left.columns) & set(right.columns))
left = left.sort_values(by=columns)
right = right.sort_values(by=columns)
left = left.reset_index(drop=True)
right = right.reset_index(drop=True)
kwargs.setdefault("check_dtype", cls.check_dtype)
Expand Down

0 comments on commit ab0a8f6

Please sign in to comment.