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

BUG: Allow transformations with empty arrays #768

Merged
merged 1 commit into from
Jan 8, 2021
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
1 change: 1 addition & 0 deletions docs/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down
4 changes: 2 additions & 2 deletions pyproj/_transformer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion test/test_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down