QuantityAttribute cannot have a unit and default=None
See original GitHub issueimport astropy.units as u
from astropy.coordinates import (
BaseCoordinateFrame,
QuantityAttribute,
frame_transform_graph,
FunctionTransform,
AltAz,
)
class MyFrame(BaseCoordinateFrame):
a = QuantityAttribute(unit=u.m)
@frame_transform_graph.transform(FunctionTransform, MyFrame, AltAz)
def trans(my_frame_coord, altaz_frame):
pass
This results in
Traceback (most recent call last):
File "test_astropy.py", line 15, in <module>
@frame_transform_graph.transform(FunctionTransform, MyFrame, AltAz)
File "/home/maxnoe/.local/anaconda3/lib/python3.7/site-packages/astropy/coordinates/transformations.py", line 659, in deco
register_graph=self, **kwargs)
File "/home/maxnoe/.local/anaconda3/lib/python3.7/site-packages/astropy/coordinates/transformations.py", line 813, in __init__
register_graph=register_graph)
File "/home/maxnoe/.local/anaconda3/lib/python3.7/site-packages/astropy/coordinates/transformations.py", line 709, in __init__
for from_nm in fromsys.get_frame_attr_names():
File "/home/maxnoe/.local/anaconda3/lib/python3.7/site-packages/astropy/coordinates/baseframe.py", line 690, in get_frame_attr_names
for name in cls.frame_attributes)
File "/home/maxnoe/.local/anaconda3/lib/python3.7/site-packages/astropy/coordinates/baseframe.py", line 690, in <genexpr>
for name in cls.frame_attributes)
File "/home/maxnoe/.local/anaconda3/lib/python3.7/site-packages/astropy/coordinates/attributes.py", line 105, in __get__
out, converted = self.convert_input(out)
File "/home/maxnoe/.local/anaconda3/lib/python3.7/site-packages/astropy/coordinates/attributes.py", line 306, in convert_input
raise TypeError('Tried to set a QuantityAttribute with '
TypeError: Tried to set a QuantityAttribute with something that does not have a unit.
Which is highly surprising behaviour to me.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Source code for astropy.coordinates.attributes
Quantity ` or None, optional Default value for the attribute if the user does not supply one. If a Quantity, it must be...
Read more >Developer reference — pint 0.10.1 documentation
quantities (dict) – mapping between variable name and units; registry – (Default value = None). Returns: a list of dimensionless quantities expressed as...
Read more >Dictionary attributes - Product Documentation | ServiceNow
Name Value Target Element
allow_null true/false field_name field
allow_public true/false table_name field
allow_references true/false field_name field
Read more >Working with items and attributes - Amazon DynamoDB
The default value for ReturnValues is NONE , meaning that DynamoDB does not return any information about attributes that were modified.
Read more >HTML attribute: min - HTML: HyperText Markup Language
If the input has no default minimum and a value is specified for min that can't be converted to a valid number (or...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It’s in https://github.com/cta-observatory/ctapipe
We are currently reworking the coordinates here: https://github.com/cta-observatory/ctapipe/pull/896
I think I can see this potentially working (and might solve some of @Cadair’s problems?), but is there any chance you can link me to wherever you have this need, @MaxNoe? (i.e., is there a github repo?) I want to understand the details just a bit better.
In your example above, the
a = QuantityAttribute(unit=u.m)
line actually executes the constructor.QuantityAttribute
is actually a descriptor - i.e., it’s the same sort of thing as a property. So creating the attribute is not the same as “populating it with data” (which happens in theMyFrame
constructor rather than theQuantityAttribute
constructor).But registering the transformation then create a
Quantity
from the default because theget_frame_attr_names
. I’m not entirely sure why (@adrn, do you?) but I think it was becauseSkyCoord
uses the defaults some how? It doesn’t seem necessary, though, so I’ll see about fixing that in the PR to address the bug.Regardless, I think the path forward is a quick PR immediately that addresses the “the current default doesn’t work” problem. That’s clearly a bug so should go in 3.1.x. Making
None
work the way described above is more of a feature and therefore may have to await 3.2 (but we can discuss it then independently of the above problem).