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

Added check to catch masked constants in read_interpolated_variable #247

Merged
merged 1 commit into from
Jun 19, 2024

Conversation

JonasSuni
Copy link
Contributor

This is a fix for PR #82 :

The problem is that if for any reason the test_variable used in read_interpolated_variable is masked, isinstance(test_variable, Iterable) will return True but value_length=len(test_variable) will throw the error TypeError: len() of unsized object. This is because the masked value is of type np.ma.core.MaskedConstant, which inherits the property of Iterable from somewhere, but it's actually not iterable.

This PR adds an additional check for np.ma.core.MaskedConstant and sets value_length=1 if the value is masked.

@alhom
Copy link
Contributor

alhom commented Jun 12, 2024

This snippet is repeated everywhere. I added helper function to read the vectorsize of a variable from vlsv file to reduce code duplication, but it does not work on datareducers.

MaskedConstant inherits numpy.ndarray, so it has a .size and a .shape, which is what we just went through yesterday with @kostahoraites for a similar fix (in some place, I forget which...).

@alhom alhom merged commit da4034d into fmihpc:master Jun 19, 2024
kostahoraites pushed a commit to kostahoraites/analysator that referenced this pull request Jun 19, 2024
… the dimensionality of vector variable fsgrid data.
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.

2 participants