pangeo-data / xESMF

Universal Regridder for Geospatial Data
http://xesmf.readthedocs.io/
MIT License
183 stars 32 forks source link

Feature Request: Add Typing #301

Open mgorfer opened 9 months ago

mgorfer commented 9 months ago

I would be interested to see correct typing hints when using xESMF.

For my small function, I am getting an error at the return

def regrid_to_lat_lon(
    ds: xr.Dataset,
    target_res_lat: float = 1,
    target_res_lon: float = 1,
) -> xr.Dataset:
    ds_out = xe.util.grid_global(target_res_lat, target_res_lon, cf=True)
    regridder = xe.Regridder(
        ds,
        ds_out,
        "bilinear",
        periodic=True,
    )
    dr_out = regridder(ds, keep_attrs=True)
    return dr_out
Expression of type "NDArray[Any] | Any" cannot be assigned to return type "Dataset"
  Type "NDArray[Any] | Any" cannot be assigned to type "Dataset"
    "NDArray[Any]" is incompatible with "Dataset"Pylance[reportGeneralTypeIssues](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportGeneralTypeIssues)

There are probably not a lot of functions or classes which need typing hints for the average user. I would also be interested to open a Pull Request for this, if the developers want it.

huard commented 9 months ago

@mgorfer,

We'll gladly review and merge a PR for this!

Thanks,

Siddhesh-Agarwal commented 8 months ago

@huard Has this been solved? if not, can I take it?

mgorfer commented 8 months ago

@Siddhesh-Agarwal I did not start this project yet. I would be glad if you could take over.

Siddhesh-Agarwal commented 8 months ago

Hey @huard @mgorfer I think this does the job. Can anyone review the code?