Skip to content

Differential frame attributes can't be serialized to YAML #6447

Closed

Description

@eteq

This was first reported in #6446, although #6446 is actually two related issues - this one and a slightly different one (which I am declaring #6446 to actually be about).

This issue is that differential objects can't get written out to ECSV. To see this in operation:

import io
from astropy.coordinates import SkyCoord
from astropy.table import Table
sc = SkyCoord([1], [2], unit='deg', galcen_v_sun=None)
t = Table([sc])
t.write(io.StringIO(), format='ascii.ecsv', overwrite=True)

This raises a RepresenterError: cannot represent an object: ( 11.1, 232.24, 7.25) km / s

(if the galcen_v_sun=None business isn't obvious, it's that it sets that attribute to the default value:)


>>> sc1 = SkyCoord([1], [2], unit='deg')
>>> sc1.galcen_v_sun
>>> sc2 = SkyCoord([1], [2], unit='deg', galcen_v_sun=None)
>>> sc2.galcen_v_sun
<CartesianDifferential (d_x, d_y, d_z) in km / s
    ( 11.1,  232.24,  7.25)>

So the core problem seems to be that CartesianDifferential isn't something that ECSV can handle. @taldcroft, is this because these features were being implemented in parallel and therefore it's an oversight? CartesianDifferential is very similar to CartesianRepresentation, so I'd think it would be pretty straightforward to include?

cc @larrybradley @adrn

Activity

  1. mhvk commented on Aug 16, 2017

    @mhvk
    Contributor

    It is not specific to differentials - obsgeoloc can also not be reproduced - the problem is that the list of "safe" objects to represent as yaml got incomplete (in io.misc.yaml). Since dumping for most astropy classes is done via info, it might be easiest if representations acquired their own info class. @taldcroft - would you think this is indeed best?

  2. taldcroft commented on Aug 16, 2017

    @taldcroft
    Member

    @eteq - the underlying problem is not in ECSV but in the YAML coverage for this new kind of astropy core object. See:
    https://github.com/astropy/astropy/blob/master/astropy/io/misc/yaml.py

    If one implements _cartesian_differential_representer and _cartesian_differential_constructor functions then YAML and ECSV should just work. One might look at EarthLocation and EarthLocationInfo for inspiration, i.e. https://github.com/astropy/astropy/blob/8516dad/astropy/coordinates/earth.py#L87

    The Info framework has infrastructure for constructing and representing that makes this implementation pretty simple. I could probably do this for 3.0 but not in the next month. @mhvk also knows quite well how all this works.

  3. changed the title [-]Differential frame attributes can't be written in ECSV tables[/-] [+]Differential frame attributes can't be serialized to YAML[/+] on Aug 16, 2017
  4. taldcroft commented on Aug 16, 2017

    @taldcroft
    Member

    I changed the issue title to represent the root problem.

  5. taldcroft commented on Aug 16, 2017

    @taldcroft
    Member

    @mhvk - I see you wrote a comment while I was writing mine..

  6. taldcroft commented on Aug 16, 2017

    @taldcroft
    Member

    @mhvk - yes, I independently suggested adding Info classes. Would it make sense for Representation objects to be Table mixin columns?

  7. mhvk commented on Aug 16, 2017

    @mhvk
    Contributor

    Yes, it shows we both thought about ecsv quite a bit recently -- and yes, since we suggest to use representation objects for general vectors, I think it makes sense that they would be able to be used as mixin columns.

  8. taldcroft commented on Dec 8, 2017

    @taldcroft
    Member

    I just had a quick look at coordinates representation.py and it should be reasonably straightforward to support YAML serialization of these in the existing framework. But not being familiar with this code there might be gotchas.

  9. eteq commented on Dec 8, 2017

    @eteq
    MemberAuthor

    It came up in the planning telecon today, so just to be clear: this issue still exists in master. When I go back and look in the traceback, the thing that it says it doesn't know how to represent is indeed the <CartesianDifferential (d_x, d_y, d_z) in km / s ( 11.1, 232.24, 7.25)>, so it does indeed seem that there needs to be Info for the differential objects.

    cc @taldcroft @mhvk

  10. mhvk commented on Apr 27, 2020

    @mhvk
    Contributor

    This will be fixed by #10210

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions