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
Projecting numpy masked arrays returns plain numpy arrays #1102
Comments
The fix is likely to check for the mask attribute here: Line 112 in d2d098c
|
A PR with the fix is welcome. |
I'm not that familiar with the codebase, but I'll give it a go! |
Thanks 👍. I recommend adding a test with a masked array in this file: https://github.com/pyproj4/pyproj/blob/main/test/test_utils.py |
After a bit more hunting I found that looking for the For instance, with pyproj 2.6.1 it's possible to show that from pyproj.utils import _copytobuffer
import numpy
in_arr = numpy.ma.array([1])
out_arr = _copytobuffer(in_arr)
isinstance(out_arr[0], numpy.ma.MaskedArray) # => True In pyproj 3.x the To cut a long story short: I'll add a test along these lines :-) |
Interesting extra piece of information: a |
As noted in pyproj4#1102, projecting numpy masked arrays returned numpy masked arrays in the 2.x series of pyproj. This behaviour changed in commit 4ab3ff7, where a "plain" numpy ndarray was returned. The change implemented here ensures that projecting numpy masked arrays returns masked arrays as was previously the case.
As noted in pyproj4#1102, projecting numpy masked arrays returned numpy masked arrays in the 2.x series of pyproj. This behaviour changed in commit 4ab3ff7, where a "plain" numpy ndarray was returned. The change implemented here ensures that projecting numpy masked arrays returns masked arrays as was previously the case.
As noted in pyproj4#1102, projecting numpy masked arrays returned numpy masked arrays in the 2.x series of pyproj. This behaviour changed in commit 4ab3ff7 as part of the 3.x series, where a "plain" numpy ndarray was returned. The change implemented here ensures that projecting numpy masked arrays returns masked arrays as was previously the case.
As noted in pyproj4#1102, projecting numpy masked arrays returned numpy masked arrays in the 2.x series of pyproj. This behaviour changed in commit 4ab3ff7 as part of the 3.x series, where a "plain" numpy ndarray was returned. The change implemented here ensures that projecting numpy masked arrays returns masked arrays as was previously the case.
While upgrading an older system from pyproj 2.6.1 to the 3.x series I found that when projecting arrays of coordinates (as a numpy masked array) that in pyproj 2.6.1 masked arrays of the projected coordinates were returned, however as of the 3.x series the arrays are no longer masked (i.e. "plain" numpy arrays). I'm not sure if this an intentional change or if this is a regression of some kind. I couldn't find a GH issue relating to this problem, so I thought I'd let you know about it. I bisected the issue and found that commit where the problem first appears is 4ab3ff7.
If you require any more information (beyond that mentioned below), please just let me know and I'll be more than happy to provide it.
Code Sample
Here's a sample piece of code which illustrates the problem (referred to as
test_projected_masked_arrays.py
further below):Setting up a virtual environment and installing base packages (assuming a Debian-bullseye system with Python 3.9):
Problem description
My expectation is that the masked array behaviour from the 2.x pyproj series would continue (this could be an incorrect expectation; I'm not sure!). Specifically, i expect that projecting masked arrays would return masked arrays.
Expected Output
I would expect that after executing
where
lon
andlat
are numpy masked arrays, thatx
andy
would have themask
attribute. I.e. that bothhasattr(x, "mask")
andhasattr(y, "mask")
returnTrue
.Environment Information
python -m pyproj -v
python -c "import pyproj; print(pyproj.proj_version_str)"
)python -c "import pyproj; print(pyproj.datadir.get_data_dir())"
)python -c "import sys; print(sys.version.replace('\n', ' '))"
)python -c "import platform; print(platform.platform())"
)Installation method
Via
pip
in a virtual environment.The text was updated successfully, but these errors were encountered: