Skip to content

Commit

Permalink
Avoid a deprecation warning from numpy 1.25 in crs._safe_pj_transform
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros committed Jun 21, 2023
1 parent 2abf4fd commit 0fb0ee8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/cartopy/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,22 @@ def _safe_pj_transform(src_crs, tgt_crs, x, y, z=None, trap=True):
if z is None:
z = np.zeros_like(x)

return transformer.transform(x, y, z, errcheck=trap)
def _sanitize_scalars(a):
# future compatibility with numpy:
# pyproj implicitly converts size-1 arrays to scalars, which is
# deprecated in numpy 1.25
# see https://github.com/numpy/numpy/pull/10615
if isinstance(a, np.ndarray) and a.size == 1:
return a.item()
else:
return a

return transformer.transform(
_sanitize_scalars(x),
_sanitize_scalars(y),
_sanitize_scalars(z),
errcheck=trap,
)


class Globe:
Expand Down
17 changes: 17 additions & 0 deletions lib/cartopy/tests/crs/test_transform_point.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright Cartopy Contributors
#
# This file is part of Cartopy and is released under the LGPL license.
# See COPYING and COPYING.LESSER in the root of the repository for full
# licensing details.
import warnings

import cartopy.crs as ccrs


def test_transform_point():
# see https://github.com/SciTools/cartopy/pull/2194
p = ccrs.PlateCarree()
p2 = ccrs.Mercator()
with warnings.catch_warnings():
warnings.simplefilter("error")
p2.transform_point(1, 2, p)

0 comments on commit 0fb0ee8

Please sign in to comment.