Rename masked column fails for subsequent slicing#3023
Conversation
|
Fix attached. The root problem seems to be that by design For reference see also: |
|
@astrofrog or @mhvk can you have a quick look? I think this not too controversial and has reasonable tests. |
|
(There was a failing test, but it appeared to just be a random Travis stoppage, re-running now). |
There was a problem hiding this comment.
@taldcroft - since the problem appears to be that __array_finalize__ is not called, why not just do that? I.e.,
if out.__class__ is self.__class__:
out.__array_finalize__(self)
There was a problem hiding this comment.
p.s. Am slightly confused why the if statement is necessary.
There was a problem hiding this comment.
About using __array_finalize__ directly, I didn't do this because it seemed like the out object was mostly "finalized" already, and that there probably was good a reason the MaskedArray implementation was not calling it. So I started from a bit of fearful ignorance.
Now looking at what ends up getting run via __array_finalize__ there is a bunch of stuff that I'm not sure needs to be done or should be done again on out. But still not having complete understanding, I did just try it out and it failed a couple of tests in test_table_aggregate (which is honestly a bit odd).
There was a problem hiding this comment.
About the if statement, you don't want to set these attributes if the item was an integer so that the return is now a scalar type object instead of a new MaskedColumn.
There was a problem hiding this comment.
OK, I think I understand why __array_finalize__ would do too much: I think it would call MaskedArray.__array_finalize__, which is the one that will have been done already. So, what you have is indeed better.
And, yes, of course the if statement makes sense...
|
@taldcroft - see my comment. Note that this would likely be resolved by numpy/numpy#4586. So, hopefully this workaround will no longer be necessary some day... |
|
I noticed pandas 0.15 dropped numpy 1.6, but I suppose for astropy it'll be a while before we drop 1.9... 😄 |
Rename masked column fails for subsequent slicing
|
@taldcroft - merged, since it looked all OK now that I understand why |
Rename masked column fails for subsequent slicing
This is weird, but when you create a masked column and look at the data attribute, you will see things like
mc.data._name,mc.data._parent_table, etc. For reasons I don't understand, this leads to the following bug:Note this is in the current stable release, and the same feature is not seen for Column. This is for Mac / Python 2.7 / numpy 1.8.