nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: ioos/compliance-checker
Pull request #572 (2018-03-19 15:36:48)

CF featureType case insensitive
@benjwadams @mhidas 
Fixes https://github.com/ioos/compliance-checker/issues/461


Patch:
diff --git a/compliance_checker/cf/cf.py b/compliance_checker/cf/cf.py
index 915fde8..0011b53 100644
--- a/compliance_checker/cf/cf.py
+++ b/compliance_checker/cf/cf.py
@@ -3172,15 +3172,16 @@ class CFBaseCheck(BaseCheck):
         :param netCDF4.Dataset ds: An open netCDF dataset
         :rtype: compliance_checker.base.Result
         """
-        feature_list = ['point', 'timeSeries', 'trajectory', 'profile', 'timeSeriesProfile', 'trajectoryProfile']
+        # Due to case insensitive requirement, we list the possible featuretypes
+        # in lower case and check using the .lower() method
+        feature_list = ['point', 'timeseries', 'trajectory', 'profile', 'timeseriesprofile', 'trajectoryprofile']
 
         feature_type = getattr(ds, 'featureType', None)
 
         valid_feature_type = TestCtx(BaseCheck.HIGH, '§9.1 Dataset contains a valid featureType')
-        valid_feature_type.assert_true(feature_type is None or feature_type in feature_list,
+        valid_feature_type.assert_true(feature_type is None or feature_type.lower() in feature_list,
                                        "{} is not a valid CF featureType. It must be one of {}"
                                        "".format(feature_type, ', '.join(feature_list)))
-
         return valid_feature_type.to_result()
 
     def check_cf_role(self, ds):


Test patch:
diff --git a/compliance_checker/tests/test_cf.py b/compliance_checker/tests/test_cf.py
index 36730c1..ec48912 100644
--- a/compliance_checker/tests/test_cf.py
+++ b/compliance_checker/tests/test_cf.py
@@ -929,6 +929,28 @@ class TestCF(BaseTestCase):
         result = self.cf.check_all_features_are_same_type(dataset)
         assert result
 
+    def test_featureType_is_case_insensitive(self):
+        '''
+        Tests that the featureType attribute is case insensitive
+        '''
+        nc = self.new_nc_file()
+        nc.featureType = 'timeseriesprofile'
+        result = self.cf.check_feature_type(nc)
+        self.assertTrue(result.value == (1, 1))
+
+        nc.featureType = 'timeSeriesProfile'
+        result = self.cf.check_feature_type(nc)
+        self.assertTrue(result.value == (1, 1))
+
+        nc.featureType = 'traJectorYpRofile'
+        result = self.cf.check_feature_type(nc)
+        self.assertTrue(result.value == (1, 1))
+
+        # This one should fail
+        nc.featureType = 'timeseriesprofilebad'
+        result = self.cf.check_feature_type(nc)
+        self.assertTrue(result.value == (0, 1))
+
     def test_check_units(self):
         '''
         Ensure that container variables are not checked for units but geophysical variables are