-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Support Table mixin columns #3011
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 started going on a prototype implementation based on the previous one that was pulled from #2790: |
|
Following on #3049, I thought for optimal duck typing it would make sense to have a default way to insert new items. But I realize I actually couldn't think of a good method, so all the more reason to have the insert method (where, as in either implementation suggested for Quantity in #3049, we ensure we are compatible with what |
|
Apart from the obvious of not realizing I'll add |
|
I like where this is going (though for consistency with But I'm not sure we should require the insert method -- if I have some random thing with multiple items, it would be a bit sad not to be able to use it in a Table just because it cannot be lengthened (which is not the most common action). |
|
Actually, as a fall-back option, one could try whether the class initialises with a list of its own items, i.e., This works for current |
|
@mhvk - only |
|
@mhvk - the concern with your generic backup method is that there may be other attributes that are required to get back to the same object. E.g. for |
|
Agreed with the idea to support functionailty as possible; we'll just have to have a clear description of what's needed -- I think the absolute minimum is |
|
BTW, on your idea of a generic insert, I see that if the That is to say anything that would initialize the corresponding class correctly assuming all the other attributes (e.g. scale, format) are set appropriately. Perhaps that's too ambitious or ambiguous. But in any case I think that requiring an |
|
About |
|
On duck typing, if mixin column object has at least one element what about doing a little deeper testing by trying the following: Even if we don't do this test, I think these are valid interface requirements for a mixin column to fully support the Table API. |
|
Yes, seem good requirements for a mixin column! And the helper function for |
|
@mhvk @astrofrog - I have been slowly tweaking the mixin column support in the background and it is finally ready to appear as a rebased WIP pull request on master. In spite of my recent email to the contrary, I found that it wasn't so hard to support high-level operations for mixins. The only real limitation is that they can't have masked elements. So for now |
astropy/table/table.py
Outdated
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.
For now, I would add
elif isinstance(col, (Time, SkyCoord)):
is_mixin = True
With that, we do not have to touch Quantity, Time, and SkyCoord at all, which I think is better as we will still experiment with what is the best way to indicate a column can be used as a mixin. At the same time, by keeping the else: clause we can have easy experiments with other types of objects by jut setting object._astropy_mixin_column = True.
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.
OK, but Time still needs to be touched for the _table_format attribute. Unfortunately there is a conflict with the existing Time.format vs. the column format. With three years hindsight, I wish I had chosen representation instead of format in Time.
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.
p.s. Of course, this would need local imports of Time and SkyCoord -- I think that is fine since by this time is_mixin will generally have been set already. So, maybe:
else:
is_mixin = getattr(col, '_astropy_mixin_column', False)
if not is_mixin:
from ..time import Time
from ..coordinates import SkyCoord
is_mixin = isinstance(col, (Time, SkyCoord))
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.
Would it work to look in the MRO of col for a class __name__ that matches 'Time' or 'SkyCoord'? Is that robust?
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.
Just for the record: fine with postponing this to future updates.
@eteq - good point. Looking more closely I realized the real restriction is that key columns should be an ndarray subclass. So |
|
@eteq - about the representation of mixin columns like There is a bit of a slippery slope here, because once you can write out all the RA Dec (and distance) values, then you realize that the equinox and obstime might be a good idea, and for that matter the location.. which is to say a coordinate can have a lot of nested metadata that is critical to round-tripping. The ECSV format is the only hope here, and even that requires some dedicated serialization machinery for |
|
@eteq - thanks for the review, I think I've addressed all your concerns. |
|
@taldcroft - thanks! is this good to merge or are there any other changes you want to make? (if so, feel free to do so) |
|
I think this is ready and there are no other changes I want to make right now. |
|
In my view, the issue with This is for a separate issue though. But having the current repr for |
|
@taldcroft - what do you think of #3315? |
|
All right, let's do this! |
|
Thanks for all your work on this @taldcroft! |
|
Yay!!! |
|
Woohoo! |
|
I haven't been really following the development of this feature so I might be confused. But at some point it might be nice to have a way for classes to register a function or something to return their column attributes, rather than having to define an |
|
🎆 |
|
@embray - I'm still hoping that classes can also just register with a |
|
Ah, the Though I was also thinking that it might one day be desirable to store other objects as columns without having to make a special class or wrapper for it first. But we can cross that bridge if/when the need arises. |
This is essentially the same as #1833, #1835, #1839 but will be done in the framework of #2790 as a follow-on once that is merged.
The starting point here will be fed00dc, which removed the proof-of-concept changes showing that mixin columns would be straightforward in the new column-based Table structure. In this issue (and eventual PR) we can define the right way to support mixin columns like Quantity, Time, and SkyCoord. The original proof-of-concept used a some simple class / instance variables, but @mhvk has proposed using an abstract base class.
Closes #1833
Closes #1835
Closes #1839