Description
Code Sample, a copy-pastable example if possible
import time
import numpy as np
from pyproj import Transformer
transformer = Transformer.from_crs(2263, 4326)
# Repeat the calculation a bunch of times
t0 = time.time()
for i in range(2000000):
transformer.transform(np.array([0]), np.array([1]))
# transformer.transform(0, 1)
t1 = time.time()
print(t1 - t0)
Problem description
Numpy 1.25 is now issuing a warning on auto-conversion of 1-element arrays to double. We have recently added a try-except for a fast-path on the transformer that tries the conversion and then catches the exception. However, this now also throws a warning, which we actually don't care about, but if running with python -Werror script.py
it will raise.
We can add the following filter to ignore these warnings within that block, but this adds a significant slowdown of ~5x for the single-point case.
single-point: ~10s
warnings.filterwarnings("ignore", message="Conversion of an array with ndim > 0")
Another option is to catch all exceptions and then do the comparison test and re-raise within the exception block.
single-point: ~2s
except (TypeError, Exception) as e:
if not (isinstance(e, TypeError) or
str(e).startswith("Conversion of an array with ndim > 0")):
raise e
I'm raising this issue to get thoughts and ideas on what would be the best way to handle this (maybe something other than those two ideas above). The patch should go in geod
and transformer
, I haven't looked in detail at other locations. This was originally raised over in Cartopy: SciTools/cartopy#2194 but seems like it should probably be addressed in Pyproj
Expected Output
No warnings using Numpy 1.25
Installation method
pip install -e .