Skip to content

Commit 8426335

Browse files
Annika comments
1 parent d1d74e1 commit 8426335

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

engine/tolerance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"--minimum-tolerance",
4646
type=float,
4747
default="0.0",
48-
help=cli_help["member_type"],
48+
help=cli_help["minimum_tolerance"],
4949
)
5050
def tolerance(stats_file_name, tolerance_file_name, member_ids, member_type, minimum_tolerance):
5151

@@ -79,7 +79,7 @@ def tolerance(stats_file_name, tolerance_file_name, member_ids, member_type, min
7979
# Take the cumulative maximum to only allow monotonically growing tolerances
8080
force_monotonic(df_max)
8181

82-
# Set a fixed non-zero tolerance value in case these became exactly zero
82+
# Set a fixed tolerance value in case these became exactly zero
8383
df_max = df_max.map(lambda x: minimum_tolerance if x < minimum_tolerance else x)
8484

8585
tolerance_dir = os.path.dirname(tolerance_file_name)

tests/cli/test_tolerance_cli.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
import os
9+
import pytest
910

1011
from tests.helpers import (
1112
assert_empty_df,
@@ -16,13 +17,25 @@
1617
)
1718

1819

19-
def test_tolerance_cli(ref_data, df_ref_tolerance, tmp_dir, new_ref):
20+
@pytest.mark.parametrize("use_minimum_tolerance", [True, False])
21+
def test_tolerance_cli(ref_data, df_ref_tolerance, tmp_dir, new_ref, use_minimum_tolerance):
2022
stats_file_name = os.path.join(ref_data, "stats_{member_id}.csv")
2123
tolerance_file_name = os.path.join(tmp_dir, "tolerance.csv")
22-
run_tolerance_cli(stats_file_name, tolerance_file_name, member_type="dp", minimum_tolerance=1e-14)
23-
df_test = load_pandas(tolerance_file_name, index_col=[0, 1])
24-
err = pandas_error(df_ref_tolerance, df_test)
2524

25+
if use_minimum_tolerance:
26+
run_tolerance_cli(stats_file_name, tolerance_file_name, member_type="dp", minimum_tolerance=1e-14)
27+
df_test = load_pandas(tolerance_file_name, index_col=[0, 1])
28+
err = pandas_error(df_ref_tolerance, df_test)
29+
else:
30+
run_tolerance_cli(stats_file_name, tolerance_file_name, member_type="dp")
31+
32+
# Create modified tolerance df with T tolerances equal to 0.0 to match `minimum_tolerance` default
33+
df_test = load_pandas(tolerance_file_name, index_col=[0, 1])
34+
modified_df_ref_tolerance = df_ref_tolerance
35+
modified_df_ref_tolerance.loc[("NetCDF:*.nc", "T")] = 0.0
36+
37+
err = pandas_error(modified_df_ref_tolerance, df_test)
38+
2639
store_as_potential_new_ref(tolerance_file_name, new_ref)
2740

2841
assert_empty_df(err, "Tolerance datasets are not equal!")

0 commit comments

Comments
 (0)