ecmwf / earthkit-data

A format-agnostic Python interface for geospatial data
Apache License 2.0
47 stars 9 forks source link

Replace logging.warn with warnings.warn #379

Closed malmans2 closed 1 month ago

malmans2 commented 1 month ago

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

sandorkertesz commented 1 month ago

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

malmans2 commented 1 month ago

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.

https://github.com/ecmwf/earthkit-data/blob/e873e96c55099aff49800739d4c217a76faa35c6/src/earthkit/data/utils/kwargs.py#L55-L61