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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove problematic use of catch_warnings #5536

Closed
Tracked by #5464
stephenworsley opened this issue Oct 5, 2023 · 1 comment 路 Fixed by #5685
Closed
Tracked by #5464

Remove problematic use of catch_warnings #5536

stephenworsley opened this issue Oct 5, 2023 · 1 comment 路 Fixed by #5685
Assignees
Milestone

Comments

@stephenworsley
Copy link
Contributor

馃摪 Custom Issue

Part of the investigation in #5499 found that warning duplication was being caused during loading by these lines of code:

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.

@stephenworsley
Copy link
Contributor Author

Note: the success of this task will influence the decision made regarding the warning workarounds proposed in #5499. If enough of the warning duplication is solved by this ticket we may deem such workarounds to be no longer necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 馃弫 Done
Development

Successfully merging a pull request may close this issue.

3 participants