question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

QuantityAttribute cannot have a unit and default=None

See original GitHub issue
import 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:closed
  • Created 5 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
maxnoecommented, Dec 19, 2018

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.

It’s in https://github.com/cta-observatory/ctapipe

We are currently reworking the coordinates here: https://github.com/cta-observatory/ctapipe/pull/896

0reactions
eteqcommented, Dec 19, 2018

We have Attributes where if it is not set, we assume them to be the same in both frames.

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.

The other question would be: why does registering a transformation even create an instance of a frame attribute?

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 the MyFrame constructor rather than the QuantityAttribute constructor).

But registering the transformation then create a Quantity from the default because the get_frame_attr_names. I’m not entirely sure why (@adrn, do you?) but I think it was because SkyCoord 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).

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found