nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: ioos/compliance-checker
Pull request #1204 (2025-06-03 14:06:12)

Make NaN a valid FillValue
We have data where `nan` is used as the FillValue and is marked as an error by the compliance checker.

Karinon: Just for my understanding regarding the failing integration test: Does it fail because neracoos is down?
ocefpaf: pre-commit.ci autofix 
benjwadams: Don't worry about the integration tests, links occasionally are unavailable or rotten and your PR had nothing to do with it.

It looks from the discussion that CF backed away from disallowing NaN as a _FillValue or missing_value, and there's nothing in the conventions document forbidding use of NaN.  So it think it's most sensible and least surprising to allow its use for the aforementioned attributes.

Patch:
diff --git a/compliance_checker/cf/cf_1_6.py b/compliance_checker/cf/cf_1_6.py
index 693e3db..885ff44 100644
--- a/compliance_checker/cf/cf_1_6.py
+++ b/compliance_checker/cf/cf_1_6.py
@@ -420,7 +420,13 @@ class CF1_6Check(CFNCCheck):
 
             if hasattr(variable, "_FillValue") and hasattr(variable, "missing_value"):
                 total = total + 1
-                if variable._FillValue != variable.missing_value:
+                if not (
+                    variable._FillValue == variable.missing_value
+                    or (
+                        np.isnan(variable._FillValue)
+                        and np.isnan(variable.missing_value)
+                    )
+                ):
                     fails.append(
                         f"For the variable {variable.name} the missing_value must be equal to the _FillValue",
                     )


Test patch:
diff --git a/compliance_checker/tests/test_cf.py b/compliance_checker/tests/test_cf.py
index 06b3462..39ab418 100644
--- a/compliance_checker/tests/test_cf.py
+++ b/compliance_checker/tests/test_cf.py
@@ -369,6 +369,12 @@ class TestCF1_6(BaseTestCase):
         dataset.variables["b"][1] = 2
         dataset.variables["b"].setncattr("missing_value", [9999.9])
 
+        # Case of _FillValue and missing_value are equal but set to NaN
+        dataset.createVariable("c", "d", ("time",), fill_value=float("nan"))
+        dataset.variables["c"][0] = 1
+        dataset.variables["c"][1] = 2
+        dataset.variables["c"].setncattr("missing_value", [float("nan")])
+
         result = self.cf.check_fill_value_equal_missing_value(dataset)
 
         # check if the test fails when when variable "a" is checked.