Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single valued flag_values causes an Exception #922

Closed
pp-mo opened this issue Apr 22, 2022 · 4 comments
Closed

Single valued flag_values causes an Exception #922

pp-mo opened this issue Apr 22, 2022 · 4 comments

Comments

@pp-mo
Copy link

pp-mo commented Apr 22, 2022

Version of compliance checker running:
5.0.2.dev90+gcad1a7c
https://github.com/ioos/compliance-checker/tree/cad1a7c9900459fd33a403e58d79868a54d907b7

Describe the checker this affects:
CF

Attach a minimal CDL or NetCDF file which is able to reproduce the issue

netcdf singleflag {
variables:
  int x ;
    x:flag_values = -1 ;
    x:flag_meanings = "any" ;

}

To Reproduce:

$ ncgen -k3 singleflag.cdl.txt -o singleflag.nc
$ compliance-checker -vvv -t=cf singleflag.nc
Running Compliance Checker on the datasets from: ['singleflag.nc']
   . . .
* §2.6.2 global attribute history should exist and be a non-empty string
* §2.6.1 Conventions field is not present
WARNING: The following exceptions occurred during the cf checker (possibly indicate compliance checker issues):
cf.check_flags: 'numpy.int32' object is not iterable
  File "/net/home/h05/itpp/git/ioos_compliance-checker/compliance_checker/cf/cf_1_6.py", line 1072, in check_flags
    valid_values = self._check_flag_values(ds, name)
  File "/net/home/h05/itpp/git/ioos_compliance-checker/compliance_checker/cf/cf_1_6.py", line 1125, in _check_flag_values
    flag_set = set(flag_values)

$ 

Describe the issue below:
The error occurs trying to iterate over 'flag_values', but the code requires also the presence of a 'flag_meanings' to hit the error.

The CF validity of the example is, I think, questionable : Is a single flag value/meaning acceptable or not?
(update : on this, see #914 (comment) and #914 (comment) )
Having said that, I did have a real file from another person which contained this.
Arguably, the checker code needs to be more robust.

@pp-mo
Copy link
Author

pp-mo commented Apr 22, 2022

Possibly related :

@pp-mo
Copy link
Author

pp-mo commented Apr 22, 2022

I can probably propose a fix, but someone else may be better placed.
Would anyone else agree that this is worth fixing ?

@benjwadams
Copy link
Contributor

Yes, this is worth fixing. NetCDF's data model treats attributes as an array of a certain type. NetCDF4-Python will take a single element attribute and cast it to scalar.

benjwadams added a commit to benjwadams/compliance-checker that referenced this issue Apr 29, 2022
Fixes single-valued/scalar flag_values test cases, including an
elementwise comparison against flag_masks.  Fixes ioos#922.
@pp-mo
Copy link
Author

pp-mo commented May 1, 2022

#924 fixes

@pp-mo pp-mo closed this as completed May 1, 2022
ocefpaf pushed a commit to ocefpaf/compliance-checker that referenced this issue Apr 14, 2023
Fixes single-valued/scalar flag_values test cases, including an
elementwise comparison against flag_masks.  Fixes ioos#922.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants