Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid a deprecation warning from numpy 1.25 in crs._safe_pj_transform #2194

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/cartopy/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,16 @@ 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)
with warnings.catch_warnings():
# pyproj implicitly converts size-1 arrays to scalars, which is
# deprecated in numpy 1.25, but *also* handles the future error
# see https://github.com/numpy/numpy/pull/10615
# and https://github.com/SciTools/cartopy/pull/2194
warnings.filterwarnings(
"ignore",
message="Conversion of an array with ndim > 0"
)
return transformer.transform(x, y, z, errcheck=trap)


class Globe:
Expand Down
11 changes: 11 additions & 0 deletions lib/cartopy/tests/test_crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
from pathlib import Path
import pickle
import warnings

import numpy as np
from numpy.testing import assert_almost_equal
Expand Down Expand Up @@ -351,3 +352,13 @@ def test_projection__from_string():

def test_crs__from_pyproj_crs():
assert ccrs.CRS(pyproj.CRS("EPSG:4326")) == "EPSG:4326"


def test_transform_point_no_warning():
# Make sure we aren't warning on single-point numpy arrays
# 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)