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
SkyCoord class is Iterable, yet raises exception when trying to iterate scalars. #16172
Comments
Welcome to Astropy 👋 and thank you for your first issue! A project member will respond to you as soon as possible; in the meantime, please double-check the guidelines for submitting issues and make sure you've provided the requested details. GitHub issues in the Astropy repository are used to track bug reports and feature requests; If your issue poses a question about how to use Astropy, please instead raise your question in the Astropy Discourse user forum and close this issue. If you feel that this issue has not been responded to in a timely manner, please send a message directly to the development mailing list. If the issue is urgent or sensitive in nature (e.g., a security vulnerability) please send an e-mail directly to the private e-mail feedback@astropy.org. |
This is an unfortunate consequence of python's ideas of what makes something iterable not being a good match to arrays, where one really wants to distinguish shape Anyway, regardless of what one thinks about the logic, astropy will have to continue to follow numpy in this regard, so I'll mark this issue as p.s. Internally, we use |
Hi humans 👋 - this issue was labeled as Close? approximately 8 hours ago. If you think this issue should not be closed, a maintainer should remove the Close? label - otherwise, I will close this issue in 7 days. If you believe I commented on this issue incorrectly, please report this here |
Kinda related, see numpy/numpy#19833 for a precedent. |
This is an exact duplicate of #13172 |
Well, at least we independently give the same feedback and advice! |
I'm going to close this issue as per my previous message, but if you feel that this issue should stay open, then feel free to re-open and remove the Close? label. If this is the first time I am commenting on this issue, or if you believe I closed this issue incorrectly, please report this here |
Description
As of version 5.2.2,
isinstance(SkyCoord(10, 10, unit=u.degree), Iterable)
evaluates toTrue
and member functions__iter__
and__len__
are present,hasattr(c, '__len__')
evaluates toTrue
. Yet calls to__iter__
or__len__
result in an exception when only a single pair of coordinates is wrapped.Expected behavior
Either make sure that
__iter__
and__len__
are not present whenSkyCoord
is just a single pair of coordinates, or implement the iterator over that single value. Throwing an exception from__len__
or__iter__
is not how other Python libraries work. Since testing if an object is an instance of Iterable translates to something likehasattr(c, '__iter__')
, implementing the single-element iterator is easier, or the scalarSkyCoord
should be monkey-patched somehow by explicitly removing the functions from the object. The issue probably affects all classes that inherit fromShapedLikeNDArray
.How to Reproduce
Versions
EDIT: xref #5481
The text was updated successfully, but these errors were encountered: