From f88059c7f69a6bd90ca6b959f09b68d453d15e52 Mon Sep 17 00:00:00 2001 From: Greg Lucas Date: Wed, 9 Oct 2024 10:14:33 -0600 Subject: [PATCH 1/3] MNT: Avoid borrowed Python reference error In the Geod init there is an unsafe usage of inline if/else to cast the values. This is only used for the repr, so just live with the extra ".0" in the display rather than casting integers. --- pyproj/_geod.pyx | 5 +---- test/test_proj.py | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/pyproj/_geod.pyx b/pyproj/_geod.pyx index 702551709..364607ae7 100644 --- a/pyproj/_geod.pyx +++ b/pyproj/_geod.pyx @@ -90,10 +90,7 @@ cdef class Geod: geod_init(&self._geod_geodesic, a, f) self.a = a self.f = f - # convert 'a' only for initstring - a_str = int(a) if a.is_integer() else a - f_str = int(f) if f.is_integer() else f - self.initstring = f"+a={a_str} +f={f_str}" + self.initstring = f"+{a=} +{f=}" self.sphere = sphere self.b = b self.es = es diff --git a/test/test_proj.py b/test/test_proj.py index a933b9557..68e9827c8 100644 --- a/test/test_proj.py +++ b/test/test_proj.py @@ -232,7 +232,7 @@ def test_repr(self): def test_sphere(self): # ellipse is Venus 2000 (IAU2000:29900), which is a sphere g = Geod("+a=6051800 +b=6051800") - self.assertEqual(repr(g), "Geod('+a=6051800 +f=0')") + self.assertEqual(repr(g), "Geod('+a=6051800.0 +f=0.0')") # test __repr__ for Geod object def test_ellps_name_round_trip(self): From 5f19c4e46be6a0bd58b48dfa09353966a5dbc757 Mon Sep 17 00:00:00 2001 From: Greg Lucas Date: Wed, 9 Oct 2024 10:16:40 -0600 Subject: [PATCH 2/3] MNT: Fix unsafe C derivates and str/bytes casting issues with Cython 3.1+ - Avoid Unsafe C derivative of temporary Python reference These are in the Geod repr and c_authority casting to a temp variable - Explicitly cstrencode when bytes are expected instead of strings --- pyproj/_crs.pyx | 4 ++-- pyproj/_transformer.pyx | 3 ++- pyproj/database.pyx | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pyproj/_crs.pyx b/pyproj/_crs.pyx index f8cfc63f7..4e3f28c23 100644 --- a/pyproj/_crs.pyx +++ b/pyproj/_crs.pyx @@ -2352,13 +2352,13 @@ cdef class _CRS(Base): self._coordinate_operation = None self._type_name = None - def __init__(self, const char *proj_string): + def __init__(self, str proj_string): self.context = pyproj_context_create() self._context_manager = get_context_manager() # initialize projection self.projobj = proj_create( self.context, - proj_string, + cstrencode(proj_string), ) if self.projobj == NULL: raise CRSError(f"Invalid projection: {proj_string}") diff --git a/pyproj/_transformer.pyx b/pyproj/_transformer.pyx index 149e4d701..9464acf4f 100644 --- a/pyproj/_transformer.pyx +++ b/pyproj/_transformer.pyx @@ -151,7 +151,8 @@ cdef class _TransformerGroup: double north_lat_degree if authority is not None: - c_authority = authority + tmp = cstrencode(authority) + c_authority = tmp try: operation_factory_context = proj_create_operation_factory_context( diff --git a/pyproj/database.pyx b/pyproj/database.pyx index befffe701..a4481de2f 100644 --- a/pyproj/database.pyx +++ b/pyproj/database.pyx @@ -460,7 +460,7 @@ def get_database_metadata(str key not None): cdef const char* metadata = NULL metadata = proj_context_get_database_metadata( pyproj_context_create(), - cstrdecode(key), + cstrencode(key), ) if metadata == NULL: return None From ad516d1aed552404a1e8cbe9ae3e85a317d970ba Mon Sep 17 00:00:00 2001 From: Greg Lucas Date: Wed, 9 Oct 2024 16:32:28 -0600 Subject: [PATCH 3/3] CI: Add Cython latest installation to a workflow --- .github/workflows/test_proj_latest.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_proj_latest.yaml b/.github/workflows/test_proj_latest.yaml index d9467b8ef..2f04c2f9d 100644 --- a/.github/workflows/test_proj_latest.yaml +++ b/.github/workflows/test_proj_latest.yaml @@ -1,4 +1,4 @@ -name: Test PROJ Latest +name: Test PROJ and Cython Latest on: push: @@ -41,7 +41,7 @@ jobs: shell: bash run: | python -V - python -m pip install cython + python -m pip install --upgrade --pre --only-binary :all: -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple cython python -m pip install -e . python -m pip install -r requirements-test.txt pyproj -v