Skip to content

Commit

Permalink
- updated code base with flake8 and black
Browse files Browse the repository at this point in the history
- updated `_assert_pairing_dict_equal()` docstring
  • Loading branch information
fernando-aristizabal committed Dec 14, 2023
1 parent 18fe910 commit 6b4f919
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
16 changes: 10 additions & 6 deletions tests/cases_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
from tests.conftest import _load_xarray
from gval.utils.schemas import Crosstab_df
from gval.comparison.pairing_functions import (
szudzik_pair_signed, cantor_pair_signed, PairingDict
szudzik_pair_signed,
cantor_pair_signed,
PairingDict,
)


Expand Down Expand Up @@ -127,11 +129,13 @@ def case_szudzik_pair_signed(c, b, a):

expected_dict_data = [
(
PairingDict({
(np.finfo(float).max, 1): 1,
(2, np.finfo(float).max): 2,
(np.finfo(float).max, 5): 3,
})
PairingDict(
{
(np.finfo(float).max, 1): 1,
(2, np.finfo(float).max): 2,
(np.finfo(float).max, 5): 3,
}
)
)
]

Expand Down
14 changes: 5 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import os

import numpy as np
import xarray as xr
import rioxarray as rxr
import geopandas as gpd
Expand Down Expand Up @@ -95,18 +94,16 @@ def _load_xarray(


def _assert_pairing_dict_equal(
computed_dict: Union[dict, PairingDict], expected_dict: Union[dict, PairingDict]
computed_dict: Union[dict, PairingDict], expected_dict: Union[dict, PairingDict]
) -> None:
"""
Testing function used to test if two pairing dictionaries are equal.
This is necessary because np.nans can be of float or np.float64 kind which makes operator (==) comparisons false.
Parameters
----------
computed_dict : dict
computed_dict : dict or PairingDict
Pairing dict computed to test.
expected_dict : dict
expected_dict : dict or PairingDict
Expected pairing dict to compare to.
Returns
Expand All @@ -125,9 +122,8 @@ def _assert_pairing_dict_equal(
diff = DeepDiff(expected_dict, computed_dict)

if diff:
raise AssertionError(
f"Dictionaries are not equal. {diff}"
)
raise AssertionError(f"Dictionaries are not equal. {diff}")


def _attributes_to_string(
obj: Union[xr.DataArray, xr.Dataset]
Expand Down
1 change: 1 addition & 0 deletions tests/test_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def test_attribute_tracking(
pd.testing.assert_frame_equal(results[0], expected_df)
_assert_pairing_dict_equal(results[1].attrs, expected_attr)


@parametrize_with_cases(
"candidate_map, benchmark_map, candidate_include, candidate_exclude, benchmark_include, benchmark_exclude, exception",
glob="attribute_tracking_fail",
Expand Down

0 comments on commit 6b4f919

Please sign in to comment.