-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
BUG: Fix broken pickle in MaskedArray when dtype is object (Return list instead of string when dtype is object) #8122
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
I'm pretty sure the days when @teoliphant had time to review code are over ;) |
I randomly pinged him as I saw him in the Authors list. :p |
Any one of @juliantaylor @rgommers or @seberg can take a look at this maybe? :) |
Is it possible to implement this with |
I thought about that but apparently the ndarray does not implement a |
assert_equal(a_pickled._mask, a._mask) | ||
assert_equal(a_pickled._data, a._data) | ||
if dtype is not object: | ||
assert_equal(a_pickled.fill_value, dtype(999)) |
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.
is there a reason not to test this for object?
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.
Thanks for the catch... I missed an else here :( Fixed it in the recent commit...
@raghavrv I wouldn't usually ping anyone. Most projects have someone - or a rabble - to do triage on new issues/PRs. |
@shoyer wrote:
Would that maintain backwards compatibility like the proposed patch? At least this patch appears to be a good fix, even if a more robust solution is possible at a later point. |
The first five elements of
So I think that's what we want to use. It is a little weird to pull it out of |
Just to note (not sure if it has much to do), but currently it seems masked arrays do not preserve subclasses during pickling. If you use the data's reduce, I am not sure if there might be an effect. |
# self._data.tolist(), | ||
getmaskarray(self).tobytes(cf), | ||
data_state = super(MaskedArray, self).__reduce__()[2] | ||
print(data_state) |
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.
print!
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.
Oops sorry!!
getmaskarray(self).tobytes(cf), | ||
data_state = super(MaskedArray, self).__reduce__()[2] | ||
print(data_state) | ||
state = (data_state[0], # version |
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.
Can you just do data_state + (getmaskarray(self).tobytes(cf), self._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.
Done!
b47127b
to
1fa49f8
Compare
self._fill_value, | ||
) | ||
return state | ||
data_state = super(MaskedArray, self).__reduce__()[2] |
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.
@shoyer, does this really make more sense given that we're making assumptions about super.__reduce__
's return value, and discarding all elements but one?
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'm pretty comfortable with this, given that (1) the spec of __reduce__
is mostly prescribed by Python and this MaskedArray is defined in NumPy itself, which means that if any ever changes how ndarray.__reduce__
works our unit tests will catch the issue for MaskedArray.
This looks good to me. @charris any concerns? If not, let's merge (and mark this one for a potential backport, if we do another bug fix release). |
@shoyer I'll leave it up to you. The change seems small and nothing breaks, so probably good. I don't plan on any more bug fix releases, I'd actually like to get the first rc of 1.12.0 out this month. |
Note that |
Do you want it to be |
@raghavrv Not to worry, looks like MaskedArray is a new style class
Note that the string begins with |
Ah. Sweet then! Thanks for the information! |
OK, in it goes. Thanks @raghavrv! |
Good work, @raghavrv. On 7 October 2016 at 08:31, Stephan Hoyer notifications@github.com wrote:
|
Fixes #1940 and #8113
Is this fix correct? Should this be extended to
mrecords
too?@pierregm @teoliphant