geospace-code / pymap3d

pure-Python (Numpy optional) 3D coordinate conversions for geospace ecef enu eci
https://geospace-code.github.io/pymap3d
BSD 2-Clause "Simplified" License
391 stars 85 forks source link

geodetic2enu type annotations cause false errors in type checking #50

Closed randallpittman closed 2 years ago

randallpittman commented 2 years ago

pymap3d.geodetic2enu has the following type signature:

def geodetic2enu(
    lat: ndarray,
    lon: ndarray,
    h: ndarray,
    lat0: ndarray,
    lon0: ndarray,
    h0: ndarray,
    ell: Ellipsoid = None,
    deg: bool = True,
) -> tuple[ndarray, ndarray, ndarray]:
    ...

I'm pretty sure lat0, lon0, and h0 must always be scalars. If I provide scalar float or int to these args I get type checking errors. Furthermore, lat, lon, and h may be either scalar or n-dimensional. If all these args are scalars, the function returns a tuple of three floats, not three ndarrays.

Admittedly numpy and type checking are a tricky business, so it may be better to only annotate non-numeric stuff. Alternatively, consider looking into numpy.typing and ArrayLike.

I think this probably applies to quite a number of other conversion functions, but I haven't looked into them.

scivision commented 2 years ago

Thanks, fixed in release 2.8.0 I think. Let me know if any more issues.