Skip to content

Commit

Permalink
fix failing tests (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
crusaderky authored Jan 23, 2024
1 parent 35033eb commit f925708
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions recursive_diff/tests/test_recursive_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import pandas as pd
import pytest
import xarray
from packaging.version import Version

from recursive_diff import cast, recursive_diff
from recursive_diff.tests import requires_dask

PANDAS_GE_200 = Version(pd.__version__).release >= (2, 0)


class Rectangle:
"""Sample class to test custom comparisons"""
Expand Down Expand Up @@ -70,8 +73,8 @@ def __repr__(self):


def check(lhs, rhs, *expect, rel_tol=1e-09, abs_tol=0.0, brief_dims=()):
expect = set(expect)
actual = set(
expect = sorted(e for e in expect if e)
actual = sorted(
recursive_diff(
lhs, rhs, rel_tol=rel_tol, abs_tol=abs_tol, brief_dims=brief_dims
)
Expand Down Expand Up @@ -433,7 +436,7 @@ def test_pandas_index():
"3.0 is in LHS only",
"3.000001 is in RHS only",
"4.0 is in LHS only",
"object type differs: Int64Index != Float64Index",
"" if PANDAS_GE_200 else "object type differs: Int64Index != Float64Index",
rel_tol=10,
abs_tol=10,
)
Expand Down Expand Up @@ -472,11 +475,12 @@ def test_pandas_rangeindex():
)

# RangeIndex vs regular index
int_index = "Index" if PANDAS_GE_200 else "Int64Index"
check(
pd.RangeIndex(4),
pd.Index([0, 1, 2]),
"3 is in LHS only",
"object type differs: RangeIndex != Int64Index",
f"object type differs: RangeIndex != {int_index}",
)


Expand All @@ -498,12 +502,13 @@ def test_pandas_multiindex():
)

# MultiIndex vs. regular index
int_index = "Index" if PANDAS_GE_200 else "Int64Index"
check(
lhs,
pd.Index([0, 1, 2]),
"Cannot compare objects: MultiIndex([('bar', 'one'), "
"..., Int64Index([0, 1, 2], dtype='int64')",
"object type differs: MultiIndex != Int64Index",
f"..., {int_index}([0, 1, 2], dtype='int64')",
f"object type differs: MultiIndex != {int_index}",
)


Expand Down

0 comments on commit f925708

Please sign in to comment.