-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
FLRW.luminosity_distance returns unexpected type #15576
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. |
@nstarman , is this behavior intentional? Please advise. Thanks! |
This is an issue. But it actually an issue for units. @mhvk might want to see this as well. >>> import pandas as pd
>>> import astropy.units as u
>>> z = pd.Series([1, 2])
>>> d = u.Quantity([10, 20], u.Mpc)
>>> z * d
0 10.0
1 40.0
dtype: float64 |
I found #11247, so this is a known problem. astropy/astropy/cosmology/_utils.py Lines 72 to 75 in e42dfc0
to check for pandas and convert to numpy? |
But the more optimal solution would be to have |
See my comment in the earlier issue: #11247 (comment) Obviously, one can make changes to specific methods in cosmology if you wish - in a way, the problem here is that in trying to get better performance, one skips making Anyway, my bottom-line suggestion would be to raise an issue with pandas. |
The issue here is not class Quantity:
def __mul__(self, other):
if other.__module__.startswith("pandas"): # no pandas dependency
return self * np.array(other) # now we get a Quantity Pandas is sufficiently common I can see it being worthwhile special-casing, but if we don't want to do that in Quantity, I can handle it in |
I guess we can do that in principle deeper inside, in |
Rather than patching Quantity, which as you stated, is a separate issue and requires upstream fix, is it possible to apply a more hacky but local patch just for that cosmology API? Then in the other larger issue, we can add a reminder to undo the cosmology one when/if we ever get to it. |
Yeah. In |
Description
When calling
FLRM.luminosity_distance
with an instance ofpandas.Series
as the input, the output is anotherpandas.Series
rather than an instance ofastropy.units.Quantity
. This is inconsistent with other similar methods, such ascomoving_distance
orcomoving_volume
.Expected behavior
FLRM.luminosity_distance
should return an instance ofastropy.units.Quantity
.How to Reproduce
astropy
,scipy
andpandas
usingconda
On my system, this outputs
Versions
The text was updated successfully, but these errors were encountered: