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

Replace logging.warn with warnings.warn #379

Closed
malmans2 opened this issue May 13, 2024 · 2 comments · Fixed by #382
Closed

Replace logging.warn with warnings.warn #379

malmans2 opened this issue May 13, 2024 · 2 comments · Fixed by #382
Assignees
Labels
enhancement New feature or request

Comments

@malmans2
Copy link
Contributor

Is your feature request related to a problem? Please describe.

It would be easier for us to handle warnings if they are issued using the standard library warnings rather than logging.

For example, earthkit warns users that changes to xr.open_dataset kwargs are not recommended, which produces a lot of warnings for us.

I think the change would be in line with the official logging HOWTO:

warnings.warn() in library code if the issue is avoidable and the client application should be modified to eliminate the warning

A logger’s warning() method if there is nothing the client application can do about the situation, but the event should still be noted

Describe the solution you'd like

No response

Describe alternatives you've considered

No response

Additional context

No response

Organisation

B-Open / CADS-EQC

@malmans2 malmans2 added the enhancement New feature or request label May 13, 2024
@sandorkertesz
Copy link
Collaborator

Please can you post an example warning output you get when "changes to xr.open_dataset kwargs are not recommended"?

@sandorkertesz sandorkertesz self-assigned this May 14, 2024
@malmans2
Copy link
Contributor Author

Here it is:

import earthkit.data

collection_id = "reanalysis-era5-single-levels"
request = {
    "variable": "2t",
    "product_type": "reanalysis",
    "date": "2012-12-01",
    "time": "12:00",
}
ds = earthkit.data.from_source("cds", collection_id, **request)
kwargs = {"chunks": {}, "squeeze": True}
ds.to_xarray(xarray_open_dataset_kwargs=kwargs)
In  , overriding the default value (chunks=None) with chunks={} is not recommended.
In  , overriding the default value (squeeze=False) with squeeze=True is not recommended.

if k in default and v != default[k]:
LOG.warning(
(
f"In {logging_owner} {logging_main_key}, overriding the default value "
f"({k}={default[k]}) with {k}={v} is not recommended."
)
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants