Skip to content

Commit

Permalink
Add proper support for tolerances in testing methods. (#8649)
Browse files Browse the repository at this point in the history
Resolves #8646 so that testing equality between different types of frames can be based on approximate rather than exact equality. Note that this is a blocker for packages that need to move away from relying on `cudf.tests.utils` for testing functions, since that module is no longer exposed by `cudf`.

Authors:
  - Vyas Ramasubramani (https://github.com/vyasr)

Approvers:
  - https://github.com/brandon-b-miller
  - GALI PREM SAGAR (https://github.com/galipremsagar)

URL: #8649
  • Loading branch information
vyasr authored Jul 9, 2021
1 parent cef51bd commit 214d74a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion python/cudf/cudf/testing/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

from typing import Union

import cupy as cp
import numpy as np
import pandas as pd

import cudf
from cudf.api.types import is_numeric_dtype
from cudf.core._compat import PANDAS_GE_110
from cudf.utils.dtypes import is_categorical_dtype

Expand Down Expand Up @@ -203,7 +205,17 @@ def assert_column_equal(

columns_equal = False
try:
columns_equal = left.equals(right)
columns_equal = (
(
cp.all(left.isnull().values == right.isnull().values)
and cp.allclose(
left[left.isnull().unary_operator("not")].values,
right[right.isnull().unary_operator("not")].values,
)
)
if not check_exact and is_numeric_dtype(left)
else left.equals(right)
)
except TypeError as e:
if str(e) != "Categoricals can only compare with the same type":
raise e
Expand Down

0 comments on commit 214d74a

Please sign in to comment.