-
Notifications
You must be signed in to change notification settings - Fork 298
Closed
Milestone
Description
📰 Custom Issue
Part of the investigation in #5499 found that warning duplication was being caused during loading by these lines of code:
iris/lib/iris/fileformats/_nc_load_rules/helpers.py
Lines 417 to 431 in b6e39d7
| with warnings.catch_warnings(record=True) as warning_records: | |
| cube.cell_methods = parse_cell_methods(nc_att_cell_methods) | |
| # Filter to get the warning we are interested in. | |
| warning_records = [ | |
| record | |
| for record in warning_records | |
| if issubclass(record.category, UnknownCellMethodWarning) | |
| ] | |
| if len(warning_records) > 0: | |
| # Output an enhanced warning message. | |
| warn_record = warning_records[0] | |
| name = "{}".format(cf_var.cf_name) | |
| msg = warn_record.message.args[0] | |
| msg = msg.replace("variable", "variable {!r}".format(name)) | |
| warnings.warn(message=msg, category=UnknownCellMethodWarning) |
This code should be refactored to not use catch_warnings and it should be demonstrated that this reduces warning duplication.