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

Raster.data is not consistently a masked_array #231

Closed
erikmannerfelt opened this issue Jul 9, 2021 · 2 comments
Closed

Raster.data is not consistently a masked_array #231

erikmannerfelt opened this issue Jul 9, 2021 · 2 comments
Labels
bug Something isn't working invalid This doesn't seem right

Comments

@erikmannerfelt
Copy link
Contributor

Describe the bug
There is no check in the data setter that the data is a masked array, so arguably weird situations can happen as a consequence.

To Reproduce

>>> import geoutils as gu
>>> import numpy as np
>>> import rasterio as rio
>>> data = np.ones((5, 5), dtype="int32")
>>> transform = rio.transform.from_origin(0, 5, 1, 1)
>>> img = gu.Raster.from_array(data, transform=transform, crs=4326)
>>> # Now, the data has been converted to a masked_array
>>> img.data.mask
False
>>> img.data = data.reshape(img.data.shape)
>>> # If the data is assigned to again, it's not necessarily a masked_array
>>> img.data.mask
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'numpy.ndarray' object has no attribute 'mask'

Expected behavior
The data setter should make sure that the data type is consistent. Right now, any class that inherits from np.ndarray is allowed!

@erikmannerfelt erikmannerfelt added bug Something isn't working invalid This doesn't seem right labels Jul 9, 2021
@adehecq
Copy link
Member

adehecq commented Jul 27, 2021

Good point! I will try to look at it before my holidays.

@adehecq
Copy link
Member

adehecq commented Sep 1, 2022

Seems to be fixed as of PR #289 or #265.

@adehecq adehecq closed this as completed Sep 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants