pyproj4 / pyproj

Python interface to PROJ (cartographic projections and coordinate transformations library)
https://pyproj4.github.io/pyproj
MIT License
1.04k stars 210 forks source link

Conversion of array to scalar when transforming 1 element arrays leads to DeprecationWarning #1415

Closed fmaussion closed 1 month ago

fmaussion commented 1 month ago

Code Sample, a copy-pastable example if possible

import pyproj
trf = pyproj.Transformer.from_proj('EPSG:4326', 'EPSG:4326')
trf.transform(np.array([[1]]), np.array([[1]]))

Problem description

This code returns the correct output (arrays of dims [[]]) but throws a deprecation warning:

    trf.transform(np.array([[1]]), np.array([[1]]))
  File "/Users/uu23343/.mambaforge/envs/salem_env_202407/lib/python3.12/site-packages/pyproj/transformer.py", line 820, in transform
    return self._transformer._transform_point(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pyproj/_transformer.pyx", line 762, in pyproj._transformer._Transformer._transform_point
DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)

Expected Output

This should not send a deprecation I think? I don't want to turn this array into a scalar (and I'm not sure why pyproj does - perhaps for optimization?)

Environment Information

pyproj info:
    pyproj: 3.6.1
      PROJ: 9.4.0
  data dir: /Users/uu23343/.mambaforge/envs/salem_env_202407/share/proj
user_data_dir: /Users/uu23343/Library/Application Support/proj
PROJ DATA (recommended version): 1.18
PROJ Database: 1.3
EPSG Database: v11.006 [2024-03-13]
ESRI Database: ArcGIS Pro 3.3 [2024-05-07]
IGNF Database: 3.1.0 [2019-05-24]

System:
    python: 3.12.4 | packaged by conda-forge | (main, Jun 17 2024, 10:11:10) [Clang 16.0.6 ]
executable: /Users/uu23343/.mambaforge/envs/salem_env_202407/bin/python
   machine: macOS-14.5-x86_64-i386-64bit

Python deps:
   certifi: 2024.7.4
    Cython: None
setuptools: 70.1.1
       pip: 24.0
snowman2 commented 1 month ago

See #1307

fmaussion commented 1 month ago

OK sorry I missed this. #1307 gives no context as to why numpy is raising this warning just for one version, but I did add a deprecation warning in our test suite for now...

snowman2 commented 1 month ago

See #1309