# Buggy code
def hgc_to_hgs(hgccoord, hgsframe):
    """
    Convert from Heliograpic Carrington to Heliographic Stonyhurst.
    """
    if hgsframe.obstime is None or np.any(hgsframe.obstime != hgccoord.obstime):
        raise ValueError(
            "Can not transform from Heliographic Carrington to "
            "Heliographic Stonyhurst, unless both frames have matching obstime."
        )
    obstime = hgsframe.obstime
    s_lon = hgccoord.spherical.lon - _carrington_offset(obstime).to(u.deg)
    representation = SphericalRepresentation(s_lon, hgccoord.lat, hgccoord.radius)

    return hgsframe.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 hgc_to_hgs(hgccoord, hgsframe):
    """
    Convert from Heliograpic Carrington to Heliographic Stonyhurst.
    """
    if hgsframe.obstime is None or np.any(hgsframe.obstime != hgccoord.obstime):
        raise ValueError(
            "Can not transform from Heliographic Carrington to "
            "Heliographic Stonyhurst, unless both frames have matching obstime."
        )
    obstime = hgsframe.obstime
    s_lon = hgccoord.spherical.lon - _carrington_offset(obstime).to(u.deg)
    representation = SphericalRepresentation(
        s_lon, hgccoord.spherical.lat, hgccoord.spherical.distance
    )

    return hgsframe.realize_frame(representation)