Repository navigation
API: allow lengths of non-scalar frames without data - #16833
Conversation
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
|
Just an extra note: I'll happily add text fixing the new behaviour once there is agreement this change is fine! |
Yes, indeed, pre #15121 there was even more of an attempt to have the #15415 is not directly relevant - that is really more of an implementation detail for |
|
The change seems reasonable to me, but it would be better if there was a test that would document that the difference between old and new behavior is intentional. |
Yes, I definitely will add tests - just want to be sure people agree the change is OK first!! |
|
@eerovaher - I went ahead and added tests, since you seemed to think the general idea is good, and I have not yet heard from others -- @StuartLittlefair and @adrn - do comment if you think giving frame-less data a length is a bad idea. |
|
p.s. I added the tests as an extra commit, so that one can see that before there were no tests that relied on frame-less data not having |
|
I think this change is fine. But of course this gets me thinking about discussions we have had about making frames inherently data-less, but that is not really relevant for this PR...! |
|
Like @adrn i approve the change. |
|
OK, great, thanks both! Since @eerovaher already said he was OK, I'll merge so that I can rebase my p.s. I do like the idea of data-less frames only, but it will probably need a deprecation crutch where, if data is passed in, a |
In #16831, we ran into the problem that frames without data do not have a length, even though the can have a shape. This means they cannot easily be stored in a
Tablewithout changing how mixin columns work in tables.More generally, it is strange that something that has a shape cannot be iterated over in normal ways (
for i in range(len(frame)): <do something with frame[i]>.So, I here suggest to change the API so that for any frame, with or without data, it is true that
len(frame) == frame.shape[0](or aTypeErroris raised if the frame is scalar).It turns out that no tests actually relied on the existing behaviour! So, perhaps the API break is not very large. Furthermore, the changes just mean removing the definitions of
__len__andisscalar-- i.e., instead relying on definitions from theShapedLikeNDArraysuperclass.