numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend) non-precise type pyobject
Thanks for writing this module. 🚀
We recently installed darts/prophet for another use (NOT for haversine) and that created a side-effect affecting this module which was working before. The related code is at https://github.com/mapado/haversine/blob/main/haversine/haversine.py#L172-L178
We don't want to use haversine with numba. Is there a way to disable this?
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
non-precise type pyobject
During: typing of argument at /opt/breww-venv/lib/python3.13/site-packages/haversine/haversine.py (116)
File "../opt/breww-venv/lib/python3.13/site-packages/haversine/haversine.py", line 116:
def _haversine_kernel(lat1, lng1, lat2, lng2):
^
During: Pass nopython_type_inference
This error may have been caused by the following argument(s):
- argument 0: Cannot determine Numba type of <class 'decimal.Decimal'>
- argument 1: Cannot determine Numba type of <class 'decimal.Decimal'>
- argument 2: Cannot determine Numba type of <class 'decimal.Decimal'>
- argument 3: Cannot determine Numba type of <class 'decimal.Decimal'>
numpy should be faster if installed. Your issue seems to be a typing issue though. Is it a runtime issue or just a type-checking one ?
I would prefer not adding a new API option to disable that functionality.
Do you have a minimal reproductible case that may help debugging ?
Thanks
numpy should be faster if installed.
The error is resulting from numba and not from numpy (we have been happily using numpy)
Your issue seems to be a typing issue though. Is it a runtime issue or just a type-checking one ?
It is a runtime issue.
I would prefer not adding a new API option to disable that functionality.
Probably a bug in the implementation.
Do you have a minimal reproductible case that may help debugging ?
Please see https://github.com/roniemartinez/haversine-bug (just uninstall numba to see that it is working properly).
haversine() works properly when numba is uninstalled. But given that in real-world, we have numba as a "Transitive dependency" of darts, we have no control over it.
The easy solution might be to just "convert" to the coordinates to float, but you're taking a performance hit compared to baseline. So I don't know what the preferred approach to fix this might be.
def haversine(point1, point2, unit=Unit.KILOMETERS, normalize=False, check=True):
# unpack latitude/longitude
lat1, lng1 = point1
lat2, lng2 = point2
# Convert to float before Numba compilation
lat1, lng1, lat2, lng2 = map(float, (lat1, lng1, lat2, lng2))
# normalize points or ensure they are proper lat/lon, i.e., in [-90, 90] and [-180, 180]
if normalize:
lat1, lng1 = _normalize(lat1, lng1)
lat2, lng2 = _normalize(lat2, lng2)
elif check:
_ensure_lat_lon(lat1, lng1)
_ensure_lat_lon(lat2, lng2)
return get_avg_earth_radius(unit) * _haversine_kernel(lat1, lng1, lat2, lng2)
The easy solution might be to just "convert" to the coordinates to float
This is what we are currently doing. I am not familiar with numba so nothing I can do at the moment.