# Buggy code
def hgs_to_hgc(hgscoord, hgcframe):
    """
    Transform from Heliographic Stonyhurst to Heliograpic Carrington.
    """
    if hgcframe.obstime is None or np.any(hgcframe.obstime != hgscoord.obstime):
        raise ValueError(
            "Can not transform from Heliographic Stonyhurst to "
            "Heliographic Carrington, unless both frames have matching obstime."
        )

    c_lon = hgscoord.spherical.lon + _carrington_offset(hgscoord.obstime).to(u.deg)
    representation = SphericalRepresentation(c_lon, hgscoord.lat, hgscoord.radius)
    hgcframe = hgcframe.__class__(obstime=hgscoord.obstime)

    return hgcframe.realize_frame(representation)


# Traceback (AttributeError)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-46-77d08794e7f4> in <module>()
----> 1 foo.transform_to(sunpy.coordinates.Helioprojective(observer=obs))

~/anaconda/envs/synthesizar/lib/python3.6/site-packages/astropy/coordinates/sky_coordinate.py in transform_to(self, frame, merge_attributes)
480         # Do the transformation, returning a coordinate frame of the desired
481         # final type (not generic).
--> 482         new_coord = trans(self.frame, generic_frame)
483
484         # Finally make the new SkyCoord object from the `new_coord` and

~/anaconda/envs/synthesizar/lib/python3.6/site-packages/astropy/coordinates/transformations.py in __call__(self, fromcoord, toframe)
1312
1313             curr_toframe = t.tosys(**frattrs)
-> 1314             curr_coord = t(curr_coord, curr_toframe)
1315
1316         # this is safe even in the case where self.transforms is empty, because

~/anaconda/envs/synthesizar/lib/python3.6/site-packages/astropy/coordinates/transformations.py in __call__(self, fromcoord, toframe)
747
748     def __call__(self, fromcoord, toframe):
--> 749         res = self.func(fromcoord, toframe)
750         if not isinstance(res, self.tosys):
751             raise TypeError('the transformation function yielded {0} but '

~/anaconda/envs/synthesizar/lib/python3.6/site-packages/sunpy/coordinates/transformations.py in hgs_to_hcc(heliogcoord, heliocframe)
186     # TODO: Revert this.
187     from astropy.tests.helper import quantity_allclose
--> 188     hglon = heliogcoord.lon
189     hglat = heliogcoord.lat
190     r = heliogcoord.radius

~/anaconda/envs/synthesizar/lib/python3.6/site-packages/astropy/coordinates/baseframe.py in __getattr__(self, attr)
1249             return val
1250
-> 1251         return self.__getattribute__(attr)  # Raise AttributeError.
1252
1253     def __setattr__(self, attr, value):

AttributeError: 'HeliographicStonyhurst' object has no attribute 'lon'

# Fixed code
def hgs_to_hgc(hgscoord, hgcframe):
    """
    Transform from Heliographic Stonyhurst to Heliograpic Carrington.
    """
    if hgcframe.obstime is None or np.any(hgcframe.obstime != hgscoord.obstime):
        raise ValueError(
            "Can not transform from Heliographic Stonyhurst to "
            "Heliographic Carrington, unless both frames have matching obstime."
        )

    c_lon = hgscoord.spherical.lon + _carrington_offset(hgscoord.obstime).to(u.deg)
    representation = SphericalRepresentation(
        c_lon, hgscoord.spherical.lat, hgscoord.spherical.distance
    )
    hgcframe = hgcframe.__class__(obstime=hgscoord.obstime)

    return hgcframe.realize_frame(representation)