-
-
Notifications
You must be signed in to change notification settings - Fork 11k
BUG: multifield-view of MaskedArray gets bad fill_value #12408
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
Conversation
3733bd0
to
27414ff
Compare
5dcdd1b
to
204bd5d
Compare
So, removing that |
Very possible, but I'm not seeing it yet. Could you give an example? I see that numpy currently does (old behavior): >>> x = np.ma.ones(3, dtype=[('a','u2'), ('b','u4',(2,))])
>>> x['b'].fill_value
999999
>>> x[['b']].fill_value
(16959, [999999, 999999]) This PR (new behavior): >>> x = np.ma.ones(3, dtype=[('a','u2'), ('b','u4',(2,))])
>>> x['b'].fill_value
999999
>>> x[['b']].fill_value
([999999, 999999],) |
Seems reasonable. |
numpy/ma/core.py
Outdated
@@ -3245,7 +3244,8 @@ def _scalar_heuristic(arr, elem): | |||
# Inherit attributes from self | |||
dout._update_from(self) | |||
# Check the fill_value | |||
if isinstance(indx, basestring): | |||
if isinstance(indx, basestring) or (isinstance(indx, list) and | |||
builtins.all(isinstance(s, basestring) for s in indx)): |
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.
Possible candidate for a helper function, _is_field_index(idx)
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.
I originally did that, but later deleted it since it was only used in one place.
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.
Helper functions are still useful even if they get called only once - if you pick a good enough name, I can tell what it does without looking at the implementation - and if you don't, at least they provide a good place to put a docstring.
@ahaldane: here's an example when the behavior changes:
My prediction is that this patch changes the second case to match the first, which is probably the right thing to do here. |
numpy/ma/core.py
Outdated
elif fields: | ||
fdtype = [(_[0], _[1]) for _ in ndtype.descr] | ||
elif ndtype.names is not None: | ||
fdtype = [(name, ndtype.fields[name][0]) for name in ndtype.names] |
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.
At this point, it's not clear to me why this line isn't just fdtype - ndtype
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.
True.. I just tried it, it passes all tests. So let's do that.
204bd5d
to
1712430
Compare
@@ -2029,6 +2029,16 @@ def test_fillvalue(self): | |||
assert_equal(x.fill_value, 999.) | |||
assert_equal(x._fill_value, np.array(999.)) | |||
|
|||
# gh-10483 test multi-field index 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.
Might be worth having a separate test here
1712430
to
6386fdb
Compare
Fixed up following your suggestions, thanks! |
Thanks Allan. |
Fixes #10483
The problem was the fill_value was not being updated correctly for multifield-views of masked-arrays. Also,
dtype.descr
was used incorrectly. This eliminates the last use of.descr
innp.ma
.