-
Notifications
You must be signed in to change notification settings - Fork 284
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
Populate cube.fill_value thru cube.data setter. #2524
Populate cube.fill_value thru cube.data setter. #2524
Conversation
Ping @dkillick and @lbdreyer ... |
If you create a new masked array with a specific fill value, make it lazy, then make it a cube's data |
This looks good to me 👍 So unless there are any objections I'm going to merge this in! |
cube = Cube(np.array(0)) | ||
self.assertIsNone(cube.fill_value) | ||
cube.data = ma.masked_array(1, fill_value=fill_value) | ||
self.assertEqual(cube.fill_value, fill_value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't check the data type of the fill value is correct but presumably the testing of that will be in the cube.fill_value setter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My assumption is that unit testing elsewhere covers that, and it does 😉
@lbdreyer Awesome, thanks! |
I'm having second thoughts on this PR...
>>> data = np.array([1, 2, 3])
>>> masked_data = ma.MaskedArray([1, 2, 3], mask=[True, False, False])
>>>
>>> cube = Cube(masked_data)
>>> print cube.fill_value
None
>>>
>>> cube = Cube(data)
>>> print cube.fill_value
None
>>> cube.data = masked_data
>>> print cube.fill_value
999999
>>> cube = iris.load_cube('iris-test-data/test_data/abfAVHRRBUVI01.1985apra.abf')
>>> print type(cube.data)
<class 'numpy.ma.core.MaskedArray'>
>>> print cube.fill_value
None
>>> cube.data = cube.data.copy(order='C')
>>> print cube.fill_value
63 This is because, regardless of what type of integer the masked array's dtype is, the fill_value of an integer masked array will always be 999999 (:warning:) >>> np.array([999999], dtype=np.uint8)
array([63], dtype=uint8) |
@lbdreyer Nice detective work! Let's discuss a way forward off-line and commit to a follow-on PR 👍 |
This PR is a follow-on action from #2492 and detailed in #2516 and allows the
cube.fill_value
to be set from thefill_value
of concrete masked data being passed tocube.data
setter.All of the CML changes are due to either tests directly setting
cube.data
with a masked array, or tests that use testing stock cubes that setcube.data
directly with a masked array ... thus populating thecube.fill_value
and thus bleeding thru to the CML. This is the behaviour that we want to see.If data passed to the
cube.data
setter is not masked data, then thecube.fill_value
will be clear, as before.This PR also neatly completes the circle with
fill_value
and masked arrays wrt the cube, in that thecube.data
getter will set thefill_value
of any masked array returned to the user with thecube.fill_value
, and now this PR allows thefill_value
of a masked array to set thecube.fill_value
through thecube.data
setter.