From 164cb51dc5bc4debc6a95a54f213f6dc20994b99 Mon Sep 17 00:00:00 2001 From: snowman2 Date: Thu, 7 Jan 2021 18:50:45 -0600 Subject: [PATCH] BUG: Allow transformations with empty arrays --- docs/history.rst | 1 + pyproj/_transformer.pyx | 4 ++-- test/test_transformer.py | 19 ++++++++++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/docs/history.rst b/docs/history.rst index a2173c280..bc17c6e80 100644 --- a/docs/history.rst +++ b/docs/history.rst @@ -4,6 +4,7 @@ Change Log 3.0.1 ----- * Use `proj_context_errno_string` in PROJ 8+ due to deprecation (issue #760) +* BUG: Allow transformations with empty arrays (issue #766) 3.0.0 ----- diff --git a/pyproj/_transformer.pyx b/pyproj/_transformer.pyx index 339fadb49..6a80bb794 100644 --- a/pyproj/_transformer.pyx +++ b/pyproj/_transformer.pyx @@ -481,8 +481,8 @@ cdef class _Transformer(Base): buflent = xbuff.len tt = NULL - if not xbuff.len or not (xbuff.len == ybuff.len == buflenz == buflent): - raise ProjError('x, y, z, and time must be same size') + if not (xbuff.len == ybuff.len == buflenz == buflent): + raise ProjError('x, y, z, and time must be same size if included.') cdef Py_ssize_t iii cdef int errno = 0 diff --git a/test/test_transformer.py b/test/test_transformer.py index 06504533c..eb1b943ec 100644 --- a/test/test_transformer.py +++ b/test/test_transformer.py @@ -7,7 +7,7 @@ import numpy as np import pytest -from numpy.testing import assert_almost_equal +from numpy.testing import assert_almost_equal, assert_array_equal import pyproj from pyproj import Proj, Transformer, itransform, transform @@ -402,6 +402,23 @@ def test_always_xy__itransform(): ) +@pytest.mark.parametrize("empty_array", [(), [], np.array([])]) +def test_transform_empty_array_xy(empty_array): + transformer = Transformer.from_crs(2193, 4326) + assert_array_equal( + transformer.transform(empty_array, empty_array), (empty_array, empty_array) + ) + + +@pytest.mark.parametrize("empty_array", [(), [], np.array([])]) +def test_transform_empty_array_xyzt(empty_array): + transformer = Transformer.from_pipeline("+init=ITRF2008:ITRF2000") + assert_array_equal( + transformer.transform(empty_array, empty_array, empty_array, empty_array), + (empty_array, empty_array, empty_array, empty_array), + ) + + def test_transform_direction__string(): forward_transformer = Transformer.from_crs(4326, 3857) inverse_transformer = Transformer.from_crs(3857, 4326)