yt.units.unit_object.Unit.invert

Unit.invert(g)

See the invert function in sympy.polys