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

Wrap read_interpolated_variable's data size determination in a try block #82

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ursg
Copy link
Contributor

@ursg ursg commented Feb 13, 2019

This catches the special case in which a derived variable evaluates to
NaN (such as TPerpOverPar), gets masked away, creates an array with zero
effective size, and then all hell breaks loose.

This catches the special case in which a derived variable evaluates to
NaN (such as TPerpOverPar), gets masked away, creates an array with zero
effective size, and then all hell breaks loose.
@markusbattarbee
Copy link
Contributor

This works for the read interpolated variable indeed. Perhaps a better fix would be to have read_variable return a NaN instead, if the return object was about to be a fully masked array?

@JonasSuni
Copy link
Contributor

The problem in question is due to a masked element of a masked array having the data type np.ma.core.MaskedConstant, which is a constant, but for some reason inherits np.ma.core.MaskedArray, np.ndarray and Iterable, meaning that it passes the test for isinstance(test_val, Iterable), but cannot be iterated and its size is an empty tuple.

My suggestion is to change

if isinstance(test_val, Iterable):
    value_length=len(test_val)

to

if isinstance(test_val, np.ma.core.MaskedConstant):
    value_length=1
elif isinstance(test_val, Iterable):
    value_length=len(test_val)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants