Skip to content

API: allow lengths of non-scalar frames without data - #16833

Merged
mhvk merged 2 commits into
astropy:mainfrom
mhvk:basecoordinate-always-have-len
Aug 22, 2024
Merged

mhvk merged 2 commits into
astropy:mainfrom
mhvk:basecoordinate-always-have-len

Conversation

@mhvk

@mhvk mhvk commented Aug 14, 2024

Copy link
Copy Markdown
Contributor

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 Table without 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 a TypeError is 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__ and isscalar -- i.e., instead relying on definitions from the ShapedLikeNDArray superclass.

  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

@mhvk mhvk added coordinates API change PRs and issues that change an existing API, possibly requiring a deprecation period labels Aug 14, 2024
@mhvk mhvk added this to the v7.0.0 milestone Aug 14, 2024
@github-actions

Copy link
Copy Markdown
Contributor

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.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

@mhvk

mhvk commented Aug 15, 2024

Copy link
Copy Markdown
Contributor Author

Just an extra note: I'll happily add text fixing the new behaviour once there is agreement this change is fine!

@eerovaher

Copy link
Copy Markdown
Member

As far as I can tell the two methods that are being removed here served some purpose before #15121, but don't seem to be needed anymore. It would be a good idea to check if this pull request is relevant for #15415.

@mhvk

mhvk commented Aug 15, 2024

Copy link
Copy Markdown
Contributor Author

As far as I can tell the two methods that are being removed here served some purpose before #15121, but don't seem to be needed anymore. It would be a good idea to check if this pull request is relevant for #15415.

Yes, indeed, pre #15121 there was even more of an attempt to have the shape just be that of the data, and attributes just had to broadcast with it, while in #15121 proper broadcasting of the data was introduced. It might have been logical to change __len__ and isscalar at that time...

#15415 is not directly relevant - that is really more of an implementation detail for Attribute that only depends on shape.

@eerovaher

Copy link
Copy Markdown
Member

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.

@mhvk

mhvk commented Aug 15, 2024

Copy link
Copy Markdown
Contributor Author

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!!

@mhvk

mhvk commented Aug 22, 2024

Copy link
Copy Markdown
Contributor Author

@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.

@mhvk

mhvk commented Aug 22, 2024

Copy link
Copy Markdown
Contributor Author

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 len() -- the tests passed already.

@adrn

adrn commented Aug 22, 2024

Copy link
Copy Markdown
Member

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...!

@StuartLittlefair

Copy link
Copy Markdown
Contributor

Like @adrn i approve the change.

@mhvk

mhvk commented Aug 22, 2024

Copy link
Copy Markdown
Contributor Author

OK, great, thanks both! Since @eerovaher already said he was OK, I'll merge so that I can rebase my .info PR on it and frames can become part of tables...

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 SkyCoord is returned... Anyway, for another time...

@mhvk
mhvk merged commit 98e78a5 into astropy:main Aug 22, 2024
@mhvk
mhvk deleted the basecoordinate-always-have-len branch August 22, 2024 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API change PRs and issues that change an existing API, possibly requiring a deprecation period coordinates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants