Return an instantiated stat object

        stats should not override this method.

        Parameters
        ----------
        geom : geom
            `geom`

        Returns
        -------
        out : stat
            A stat object

        Raises
        ------
        :class:`PlotnineError` if unable to create a `stat`.

def from_geom(geom):
        """
        Return an instantiated stat object

        stats should not override this method.

        Parameters
        ----------
        geom : geom
            `geom`

        Returns
        -------
        out : stat
            A stat object

        Raises
        ------
        :class:`PlotnineError` if unable to create a `stat`.
        """
        name = geom.params['stat']
        kwargs = geom._kwargs
        # More stable when reloading modules than
        # using issubclass
        if (not isinstance(name, type) and
                hasattr(name, 'compute_layer')):
            return name

        if isinstance(name, stat):
            return name
        elif isinstance(name, type) and issubclass(name, stat):
            klass = name
        elif is_string(name):
            if not name.startswith('stat_'):
                name = 'stat_{}'.format(name)
            klass = Registry[name]
        else:
            raise PlotnineError(
                'Unknown stat of type {}'.format(type(name)))

        valid_kwargs = (
             (klass.aesthetics() |
              klass.DEFAULT_PARAMS.keys()) &
             kwargs.keys())

        params = {k: kwargs[k] for k in valid_kwargs}
        return klass(geom=geom, **params)