internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: ioos/compliance-checker

Issue:
No reasoning message from CF check_calendar
E.g. for [this file](http://thredds.aodn.org.au/thredds/catalog/IMOS/eMII/checker_test/ABOS/SOFSrt/catalog.html?dataset=eMII/checker_test/ABOS/SOFSrt/IMOS_ABOS-ASFS_FMT_20130917T005900Z_SOFS_FV02.nc), we get the result:

```
time                                   :3:     2/ 4 :  
    TIME                               :3:     2/ 4 :  
        has_calendar                   :1:     0/ 1 :  
        valid_calendar                 :1:     0/ 1 :  
```



Discussion:

Resolving patch:
diff --git a/compliance_checker/cf/cf.py b/compliance_checker/cf/cf.py
--- a/compliance_checker/cf/cf.py
+++ b/compliance_checker/cf/cf.py
@@ -1273,17 +1273,27 @@ def check_calendar(self, ds):
         for k,v in ds.dataset.variables.iteritems():
             if not is_time_variable(k,v):
                 continue
+            reasoning = None
             has_calendar = hasattr(v, 'calendar')
+            if not has_calendar:
+                reasoning = ['Variable %s should have a calendar attribute' % k]
             result = Result(BaseCheck.LOW,  \
                             has_calendar,   \
-                            ('time', k, 'has_calendar'))
-            ret_val.append(result)
-            valid_calendar = has_calendar and v.calendar in valid_calendars
-            result = Result(BaseCheck.LOW,  \
-                            valid_calendar, \
-                            ('time', k, 'valid_calendar'))
+                            ('time', k, 'has_calendar'),  \
+                            reasoning)
             ret_val.append(result)
 
+            if has_calendar:
+                reasoning = None
+                valid_calendar = v.calendar in valid_calendars
+                if not valid_calendar:
+                    reasoning = ["'%s' is not a valid calendar" % v.calendar]
+                    result = Result(BaseCheck.LOW,  \
+                                    valid_calendar, \
+                                    ('time', k, 'valid_calendar'),  \
+                                    reasoning)
+                ret_val.append(result)
+
         return ret_val
         
 


Test patch:
diff --git a/compliance_checker/tests/test_cf.py b/compliance_checker/tests/test_cf.py
--- a/compliance_checker/tests/test_cf.py
+++ b/compliance_checker/tests/test_cf.py
@@ -551,7 +551,6 @@ def test_check_calendar(self):
         results = self.cf.check_calendar(dataset)
         rd = {r.name[1:] : r.value for r in results }
         self.assertFalse(rd[('bad_time_1', 'has_calendar')])
-        self.assertFalse(rd[('bad_time_1', 'valid_calendar')])
         self.assertTrue(rd[('bad_time_2', 'has_calendar')])
         self.assertFalse(rd[('bad_time_2', 'valid_calendar')])
Repository: ioos/compliance-checker

Issue:
CF Conventions check allows pre 1.6 strings
Added in #68 is a list of new convention strings allowed from CF-1.0 to CF-1.6.  As noted by @DanielJMaher in the comments of that PR, this checker is only designed for CF-1.6.  Allowing other checks gives a false impression that other CF standards will be rigorously checked (they won't be).

I'm fine with the other changes of that PR but this list needs to be reverted back to a single entity, CF-1.6.



Discussion:

Resolving patch:
diff --git a/compliance_checker/cf/cf.py b/compliance_checker/cf/cf.py
--- a/compliance_checker/cf/cf.py
+++ b/compliance_checker/cf/cf.py
@@ -471,8 +471,8 @@ def check_conventions_are_cf_16(self, ds):
         """
         2.6.1 the NUG defined global attribute Conventions to the string value "CF-1.6"
         """
-        valid_conventions = ['CF-1.0', 'CF-1.1', 'CF-1.2', 'CF-1.3',
-                             'CF-1.4', 'CF-1.5', 'CF-1.6']
+
+        valid_conventions = ['CF-1.6']
         if hasattr(ds, 'Conventions'):
             conventions = re.split(',|\s+', getattr(ds, 'Conventions', ''))
             if any((c.strip() in valid_conventions for c in conventions)):
@@ -480,7 +480,7 @@ def check_conventions_are_cf_16(self, ds):
                 reasoning = []
             else:
                 valid = False
-                reasoning = ['Conventions field is not "CF-1.x (x in 0-6)"']
+                reasoning = ['Conventions field is not "CF-1.6"']
         else:
             valid = False
             reasoning = ['Conventions field is not present']


Test patch:
Repository: ioos/compliance-checker

Issue:
Question about data type for flag_masks
Question about the data type allowed for a flag_masks variable.

See CF.py code 

``` python
        type_ok = v.dtype in [np.character,
                                      np.dtype('b'),
                                      np.dtype('i4'),
                                      np.int32]
```

https://github.com/ioos/compliance-checker/blob/master/compliance_checker/cf/cf.py#L811

is there a reason why int8 and int32 are allowed and int16 is not. I previously had a file
with a flag_masks variable of "short' type not passing the CF checker

Thanks

@mhidas FYI



Discussion:
it should allow all integer types, I believe.

@benjwadams could you take a look at this?


Resolving patch:
diff --git a/compliance_checker/cf/cf.py b/compliance_checker/cf/cf.py
--- a/compliance_checker/cf/cf.py
+++ b/compliance_checker/cf/cf.py
@@ -854,11 +854,9 @@ def check_flags(self, ds):
                 ok_count = 0
 
                 same_type = flag_masks.dtype == v.dtype
-                type_ok = v.dtype in [np.character,
-                                      np.dtype('b'),
-                                      np.dtype('i4'),
-                                      np.int32]
-
+                type_ok = (np.issubdtype(v.dtype, int) or
+                           np.issubdtype(v.dtype, 'S') or
+                           np.issubdtype(v.dtype, 'b'))
                 if same_type:
                     ok_count += 1
                 else:


Test patch:
Repository: ioos/compliance-checker

Issue:
ACDD - Dimensionless variables are not required to have units attribute



Discussion:
@benjwadams I am going to assign this to me and work it.  


Resolving patch:
diff --git a/compliance_checker/acdd.py b/compliance_checker/acdd.py
--- a/compliance_checker/acdd.py
+++ b/compliance_checker/acdd.py
@@ -146,7 +146,7 @@ def check_var_standard_name(self, ds):
             results.append(Result(BaseCheck.HIGH, check, (variable, "var_std_name"), msgs))
 
         return results
-
+    
     @score_group('varattr')
     def check_var_units(self, ds):
         results = []
@@ -161,10 +161,16 @@ def check_var_units(self, ds):
             if std_name is not None:
                 if 'status_flag' in std_name:
                     continue
-            check = hasattr(ds.variables[variable], 'units')
-            if not check:
+            # Check units and dims for variable
+            unit_check = hasattr(ds.variables[variable], 'units')
+            no_dim_check = (getattr(ds.variables[variable], 'dimensions') == tuple())
+            # Check if we have no dimensions.  If no dims, skip test
+            if no_dim_check:
+                continue
+            # Check if we have no units
+            if not unit_check:
                 msgs.append("Var %s missing attr units" % variable)
-            results.append(Result(BaseCheck.HIGH, check, (variable, "var_units"), msgs))
+            results.append(Result(BaseCheck.HIGH, unit_check, (variable, "var_units"), msgs))
 
         return results
 


Test patch:
Repository: ioos/compliance-checker

Issue:
JSON output missing argument
Attempting to run compliance-checker on Python 2 or 3 with JSON output fails due to a missing function argument.

```
compliance-checker --test ioos -f json -c strict compliance_checker/tests/data/conv_bad.nc                                                                    
Traceback (most recent call last):
  File "/home/badams_local/.virtualenvs/cchecker_py3/bin/compliance-checker", line 9, in <module>
    load_entry_point('compliance-checker', 'console_scripts', 'compliance-checker')()
  File "/home/badams_local/devel/compliance-checker/cchecker.py", line 41, in main
    args.format)
  File "/home/badams_local/devel/compliance-checker/compliance_checker/runner.py", line 50, in run_checker
    groups = cls.json_output(cs, score_groups, output_filename, ds_loc, limit)
  File "/home/badams_local/devel/compliance-checker/compliance_checker/runner.py", line 116, in json_output
    cs.json_output(checker, groups, f, ds_loc)
TypeError: json_output() missing 1 required positional argument: 'limit'
```



Discussion:

Resolving patch:
diff --git a/compliance_checker/suite.py b/compliance_checker/suite.py
--- a/compliance_checker/suite.py
+++ b/compliance_checker/suite.py
@@ -225,7 +225,7 @@ def json_output(self, check_name, groups, file_object, source_name, limit):
         aggregates = self.build_structure(check_name, groups, source_name, limit)
         aggregates = self.serialize(aggregates)
         json_string = json.dumps(aggregates, ensure_ascii=False)
-        file_object.write(str(json_string))
+        file_object.write(json_string)
         return
 
     def serialize(self, o):


Test patch:
diff --git a/compliance_checker/tests/test_cli.py b/compliance_checker/tests/test_cli.py
--- a/compliance_checker/tests/test_cli.py
+++ b/compliance_checker/tests/test_cli.py
@@ -71,3 +71,23 @@ def test_unicode_cf_html(self):
         )
 
         assert os.stat(path).st_size > 0
+
+    def test_json_output(self):
+        '''
+        Tests that the CF checker can produce JSON output
+        '''
+
+        fd, path = tempfile.mkstemp()
+        os.close(fd)
+        self.addCleanup(os.remove, path)
+
+        return_value, errors = ComplianceChecker.run_checker(
+            ds_loc=STATIC_FILES['conv_bad'],
+            verbose=0,
+            criteria='strict',
+            checker_names=['cf'],
+            output_filename=path,
+            output_format='json'
+        )
+
+        assert os.stat(path).st_size > 0
Repository: ioos/compliance-checker

Issue:
CDL check fails on text files (py3)
The recent CDL additions (#297) have broken the ability to pass a text file on the command line (IE a getcaps/describesensor xml document) on python 3 environments:

```
~/dev/compliance-checker -> python cchecker.py --test ioos ~/Downloads/aoos_sos_getcaps.xml
Running Compliance Checker on the dataset from: /home/daf/Downloads/aoos_sos_getcaps.xml
Traceback (most recent call last):
  File "cchecker.py", line 79, in <module>
    sys.exit(main())
  File "cchecker.py", line 68, in main
    args.format)
  File "/home/daf/dev/compliance-checker/compliance_checker/runner.py", line 44, in run_checker
    ds = cs.load_dataset(ds_loc)
  File "/home/daf/dev/compliance-checker/compliance_checker/suite.py", line 576, in load_dataset
    elif is_cdl_file(ds_str, first_chunk):
  File "/home/daf/dev/compliance-checker/compliance_checker/suite.py", line 567, in is_cdl_file
    if data.startswith('netcdf') or 'dimensions' in data:
TypeError: startswith first arg must be bytes or a tuple of bytes, not str
```



Discussion:
WTB tests PST

Python string encoding funtimes.  I'll handle this and add some tests too.


Resolving patch:
diff --git a/compliance_checker/suite.py b/compliance_checker/suite.py
--- a/compliance_checker/suite.py
+++ b/compliance_checker/suite.py
@@ -482,9 +482,9 @@ def process_doc(self, doc):
         Attempt to parse an xml string conforming to either an SOS or SensorML
         dataset and return the results
         """
-        xml_doc = ET.fromstring(str(doc))
+        xml_doc = ET.fromstring(doc)
         if xml_doc.tag == "{http://www.opengis.net/sos/1.0}Capabilities":
-            ds = SensorObservationService(ds_str, xml=str(doc))
+            ds = SensorObservationService(None, xml=doc)
 
         elif xml_doc.tag == "{http://www.opengis.net/sensorML/1.0.1}SensorML":
             ds = SensorML(xml_doc)
@@ -524,7 +524,7 @@ def load_dataset(self, ds_str):
                 r = requests.get(ds_str)
                 r.raise_for_status()
 
-                doc = r.text
+                doc = r.content
             else:
                 raise Exception("Could not understand response code %s and content-type %s" % (rhead.status_code, rhead.headers.get('content-type', 'none')))
         else:
@@ -564,7 +564,7 @@ def is_cdl_file(filename, data):
                 '''
                 if os.path.splitext(filename)[-1] == '.cdl':
                     return True
-                if data.startswith('netcdf') or 'dimensions' in data:
+                if data.startswith(b'netcdf') or b'dimensions' in data:
                     return True
                 return False
 
@@ -577,7 +577,7 @@ def is_cdl_file(filename, data):
                     ds_str = self.generate_dataset(ds_str)
                 else:
                     f.seek(0)
-                    doc = "".join(f.readlines())
+                    doc = f.read()
 
         if doc is not None:
             ds = self.process_doc(doc)


Test patch:
Repository: ioos/compliance-checker

Issue:
Fail result for `Flags and flag attributes` check with no reasoning
Running the CF checker on [this file](http://thredds.aodn.org.au/thredds/fileServer/IMOS/SRS/SST/ghrsst/L3S-1d/dn/2016/20160919092000-ABOM-L3S_GHRSST-SSTfnd-AVHRR_D-1d_dn.nc) results in 

```
Name                             Priority:     Score:Reasoning
--------------------------------------------------------------------------------
§3.5 Flags and flag attributes         :3:    31/32 :  
```

An apparently failed result, with no reasoning message.



Discussion:
The file has two flag variables, with attributes:

```
        short l2p_flags(time, lat, lon) ;
                l2p_flags:_FillValue = -32768s ;
                l2p_flags:long_name = "L2P flags" ;
                l2p_flags:valid_min = 0s ;
                l2p_flags:valid_max = 32767s ;
                l2p_flags:coordinates = "time lat lon" ;
                l2p_flags:flag_masks = 1s, 2s, 4s, 8s, 16s, 32s, 64s, 128s, 256s, 512s, 1024s, 2048s, 4096s, 8192s, 16384s ;
                l2p_flags:flag_meanings = "microwave land ice lake river reserved aerosol analysis lowwind highwind edge terminator reflector swath delta_dn" ;
        byte quality_level(time, lat, lon) ;
                quality_level:_FillValue = -128b ;
                quality_level:long_name = "quality level of SST pixel" ;
                quality_level:valid_min = 0b ;
                quality_level:valid_max = 5b ;
                quality_level:coordinates = "time lat lon" ;
                quality_level:flag_meanings = "no_data bad_data worst_quality low_quality acceptable_quality best_quality" ;
                quality_level:flag_values = 0b, 1b, 2b, 3b, 4b, 5b ;
```

I don't see anything obviously wrong.

Nor do I, we'll take a look. 


Resolving patch:
diff --git a/compliance_checker/cf/cf.py b/compliance_checker/cf/cf.py
--- a/compliance_checker/cf/cf.py
+++ b/compliance_checker/cf/cf.py
@@ -926,12 +926,15 @@ def check_flags(self, ds):
                 ret_val.append(Result(BaseCheck.HIGH, (ok_count, 2), '§3.5 Flags and flag attributes', msgs=msgs))
 
                 # 7) the flag_masks attribute values must be non-zero
-                zeros = [x for x in flag_masks if x == 0]
+                zeros_absent = 0 not in flag_masks
+
                 msgs = []
-                if len(zeros):
+                if not zeros_absent:
                     msgs = ['flag_masks attribute values contains a zero']
 
-                ret_val.append(Result(BaseCheck.HIGH, len(zeros) != 0, '§3.5 Flags and flag attributes', msgs=msgs))
+                ret_val.append(Result(BaseCheck.HIGH, zeros_absent,
+                                      '§3.5 Flags and flag attributes',
+                                      msgs=msgs))
 
             # 9) when both defined, boolean AND of each entry in flag_values with corresponding entry in flag_masks
             #    should equal the flags_value entry


Test patch:
Repository: ioos/compliance-checker

Issue:
Refactor check_time_coordinate
- Iterate over the coordinate variables, not every variable.


Discussion:

Resolving patch:
diff --git a/compliance_checker/cf/cf.py b/compliance_checker/cf/cf.py
--- a/compliance_checker/cf/cf.py
+++ b/compliance_checker/cf/cf.py
@@ -1773,16 +1773,15 @@ def check_time_coordinate(self, ds):
         '''
 
         ret_val = []
-        for k, v in ds.variables.items():
-            if not util.is_time_variable(k, v):
-                continue
+        for name in cfutil.get_time_variables(ds):
+            variable = ds.variables[name]
             # Has units
-            has_units = hasattr(v, 'units')
+            has_units = hasattr(variable, 'units')
             if not has_units:
                 result = Result(BaseCheck.HIGH,
                                 False,
                                 '§4.4 Time coordinate variable and attributes',
-                                ['%s does not have units' % k])
+                                ['%s does not have units' % name])
                 ret_val.append(result)
                 continue
             # Correct and identifiable units
@@ -1790,10 +1789,10 @@ def check_time_coordinate(self, ds):
                             True,
                             '§4.4 Time coordinate variable and attributes')
             ret_val.append(result)
-            correct_units = util.units_temporal(v.units)
+            correct_units = util.units_temporal(variable.units)
             reasoning = None
             if not correct_units:
-                reasoning = ['%s does not have correct time units' % k]
+                reasoning = ['%s does not have correct time units' % name]
             result = Result(BaseCheck.HIGH,
                             correct_units,
                             '§4.4 Time coordinate variable and attributes',


Test patch:
Repository: ioos/compliance-checker

Issue:
check_dimension_order is raising an exception on string variables
```
The following exceptions occured during the cf checker (possibly indicate compliance checker issues):
cf.check_dimension_order: type object 'str' has no attribute 'char'
  File "/home/travis/miniconda/envs/test-environment/lib/python3.5/site-packages/compliance_checker/cf/cf.py", line 497, in check_dimension_order
    if variable.dtype.char == 'S':
```


Discussion:

Resolving patch:
diff --git a/compliance_checker/cf/cf.py b/compliance_checker/cf/cf.py
--- a/compliance_checker/cf/cf.py
+++ b/compliance_checker/cf/cf.py
@@ -498,9 +498,13 @@ def check_dimension_order(self, ds):
             # This is tested later in the respective checks
             if name in any_bounds or name == any_clim:
                 continue
+
             # Skip strings/labels
-            if variable.dtype.char == 'S':
+            if hasattr(variable.dtype, 'char') and variable.dtype.char == 'S':
                 continue
+            elif variable.dtype == str:
+                continue
+
             if variable.dimensions:
                 dimension_order = self._get_dimension_order(ds, name, coord_axis_map)
                 valid_dimension_order.assert_true(self._dims_in_order(dimension_order),


Test patch:
Repository: ioos/compliance-checker

Issue:
accessing OpenDAP on ESGF data archives
ESGF data archives provide OpenDAP to access climate data. But to access the data you need a certificate and an appropriate `.dodsrc` file. The python netcdf4 library is already able to handle this without modifications. See my notebook example:

https://github.com/cehbrecht/demo-notebooks/blob/master/esgf-opendap.ipynb

When i run the compliance checker on an ESGF OpenDAP url i get the following exception:

``
Could not understand response code 401 and content-type text/html;charset=ISO-8859-1
``

To make this work you probably just need to add the 401 error code to the following line (in method `CheckSuite.load_dataset`):

https://github.com/ioos/compliance-checker/blob/master/compliance_checker/suite.py#L523




Discussion:

Resolving patch:
diff --git a/compliance_checker/suite.py b/compliance_checker/suite.py
--- a/compliance_checker/suite.py
+++ b/compliance_checker/suite.py
@@ -520,7 +520,7 @@ def load_dataset(self, ds_str):
         if pr.netloc:       # looks like a remote url
             rhead = requests.head(ds_str, allow_redirects=True)
             # if we get a 400 here, it's likely a Dataset openable OpenDAP url
-            if rhead.status_code == 400:
+            if rhead.status_code == 400 or rhead.status_code == 401:
                 pass
             elif rhead.status_code == 200 and rhead.headers['content-type'] == 'text/xml':
                 # probably interesting, grab it


Test patch:
Repository: ioos/compliance-checker

Issue:
Mixed two variables in checking of grid mapping
In the function `check_grid_mapping` in `cf.py`(lines 2450 - 2451) the variable `grid_mapping_dict` was used instead of `grid_mapping`.

`grid_mapping_dict` is a dictionary containing all allowed grid mappings. `grid_mapping` is one of these grid mappings currently applicable. At the particular location in the code, the fourth element (with index 3) of the `grid_mapping` list should be used if it exists. Using the forth element of the dictionary `grid_mapping_dict` makes no sense in this context.

_old_ code:
```
if len(grid_mapping_dict) == 4:
    at_least_attr = grid_mapping_dict[3]
```

fixed code:
```
if len(grid_mapping) == 4:
    at_least_attr = grid_mapping[3]
```

I will create a pull request for this.


Discussion:

Resolving patch:
diff --git a/compliance_checker/cf/cf.py b/compliance_checker/cf/cf.py
--- a/compliance_checker/cf/cf.py
+++ b/compliance_checker/cf/cf.py
@@ -2447,8 +2447,8 @@ def check_grid_mapping(self, ds):
                                                "{} is a required attribute for grid mapping {}".format(req, grid_mapping_name))
 
             # Make sure that exactly one of the exclusive attributes exist
-            if len(grid_mapping_dict) == 4:
-                at_least_attr = grid_mapping_dict[3]
+            if len(grid_mapping) == 4:
+                at_least_attr = grid_mapping[3]
                 number_found = 0
                 for attr in at_least_attr:
                     if hasattr(grid_var, attr):


Test patch:
Repository: instadeepai/Mava

Issue:
Include flatland installation in readme
Installation of flatland as an environment is not currently included in the readme. This should be included with a warning that flatland should be installed separately and before other requirements.


Discussion:

Resolving patch:
diff --git a/mava/wrappers/flatland.py b/mava/wrappers/flatland.py
--- a/mava/wrappers/flatland.py
+++ b/mava/wrappers/flatland.py
@@ -173,19 +173,11 @@ def step(self, actions: Dict[str, np.ndarray]) -> dm_env.TimeStep:
             observations = self._create_observations(observations, infos, dones)
 
         if self.env_done():
-            # step_type = self._step_type
             self._step_type = dm_env.StepType.LAST
             self._reset_next_step = True
         else:
-            # step_type = dm_env.StepType.MID
             self._step_type = dm_env.StepType.MID
 
-        # if step_type == dm_env.StepType.LAST:
-        #     self._reset_next_step = True
-        #     rewards = {
-        #         agent: np.dtype("float32").type(0) for agent, _ in rewards.items()
-        #     }
-
         return dm_env.TimeStep(
             observation=observations,
             reward=rewards,


Test patch: