File tree Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -1526,10 +1526,11 @@ def get_associated_variable_names(
1526
1526
allvars = itertools .chain (* coords .values ())
1527
1527
missing = set (allvars ) - set (self ._maybe_to_dataset ().variables )
1528
1528
if missing :
1529
- warnings .warn (
1530
- f"Variables { missing !r} not found in object but are referred to in the CF attributes." ,
1531
- UserWarning ,
1532
- )
1529
+ if OPTIONS ["warn_on_missing_variables" ]:
1530
+ warnings .warn (
1531
+ f"Variables { missing !r} not found in object but are referred to in the CF attributes." ,
1532
+ UserWarning ,
1533
+ )
1533
1534
for k , v in coords .items ():
1534
1535
for m in missing :
1535
1536
if m in v :
Original file line number Diff line number Diff line change 9
9
10
10
OPTIONS : MutableMapping [str , Any ] = {
11
11
"custom_criteria" : [],
12
+ "warn_on_missing_variables" : True ,
12
13
}
13
14
14
15
@@ -20,6 +21,9 @@ class set_options:
20
21
custom_criteria : dict
21
22
Translate from axis, coord, or custom name to
22
23
variable name optionally using ``custom_criteria``. Default: [].
24
+ warn_on_missing_variables : bool
25
+ Whether to raise a warning when variables referred to in attributes
26
+ are not present in the object.
23
27
24
28
Examples
25
29
--------
Original file line number Diff line number Diff line change @@ -299,6 +299,11 @@ def test_getitem_ancillary_variables():
299
299
with pytest .warns (UserWarning ):
300
300
anc [["q" ]].cf ["q" ]
301
301
302
+ with pytest .warns (None ) as record :
303
+ with cf_xarray .set_options (warn_on_missing_variables = False ):
304
+ anc [["q" ]].cf ["q" ]
305
+ assert len (record ) == 0
306
+
302
307
for k in ["ULONG" , "ULAT" ]:
303
308
assert k not in popds .cf ["TEMP" ].coords
304
309
You can’t perform that action at this time.
0 commit comments