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: Ensure numpy masked arrays stay masked after projection #1103

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.
Jump to
Jump to file
Failed to load files.
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 @@ -10,6 +10,7 @@ Latest
- REF: use regex to process PROJ strings in :meth:`.CRS.to_dict` (pull #1086)
- BUG: :class:`.MercatorAConversion` defined only for lat_0 = 0 (issue #1089)
- BUG: Add support for `PROJ_DATA` environment variable (issue #1097)
- BUG: Ensure numpy masked arrays stay masked after projection (issue #1102)

3.3.1
-------
Expand Down
9 changes: 8 additions & 1 deletion pyproj/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,14 @@ def _copytobuffer(xxx: Any, inplace: bool = False) -> Tuple[Any, DataType]:
The copy of the data prepared for the PROJ API & Python Buffer API.
"""
# check for pandas.Series, xarray.DataArray or dask.array.Array
if hasattr(xxx, "__array__") and callable(xxx.__array__):
# also handle numpy masked Arrays; note that pandas.Series also has a
# "mask" attribute, hence checking for simply the "mask" attr in that
# case isn't sufficient
if (
not hasattr(xxx, "hardmask")
and hasattr(xxx, "__array__")
and callable(xxx.__array__)
):
xxx = xxx.__array__()

# handle numpy data
Expand Down
7 changes: 7 additions & 0 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ def test__copytobuffer__numpy_array(in_arr):
)


def test__copytobuffer__numpy_masked_array():
in_arr = numpy.ma.array([1])
out_arr, dtype = _copytobuffer(in_arr)

assert isinstance(out_arr, numpy.ma.MaskedArray)


def test__copytobuffer__fortran_order():
data = numpy.ones((2, 4), dtype=numpy.float64, order="F")
converted_data, dtype = _copytobuffer(data)
Expand Down