Repository: scipy/scipy
File: scipy/stats/_distribution_infrastructure.py (Python)

Code before:
        return general_standard_moments.get(order, None)

    def _moment_from_pxf(self, order, center, **params):
        def integrand(x, order, center, **params):
            pxf = self._pxf_dispatch(x, **params)
            return pxf*(x-center)**order
        return self._quadrature(integrand, args=(order, center), params=params)

    def _moment_integrate_icdf(self, order, center, **params):
        def integrand(x, order, center, **params):
            x = self._icdf_dispatch(x, **params)
            return (x-center)**order
        return self._quadrature(integrand, limits=(0., 1.),
                                args=(order, center), params=params)

    def _moment_transform_center(self, order, moment_as, a, b):
        a, b, *moment_as = np.broadcast_arrays(a, b, *moment_as)
        n = order
        i = np.arange(n+1).reshape([-1]+[1]*a.ndim)  # orthogonal to other axes
        i = self._preserve_type(i)
        n_choose_i = special.binom(n, i)
        with np.errstate(invalid='ignore'):  # can happen with infinite moment
            moment_b = np.sum(n_choose_i*moment_as*(a-b)**(n-i), axis=0)
        return moment_b

    def _logmoment(self, order=1, *, logcenter=None, standardized=False):
        # make this private until it is worked into moment
        if logcenter is None or standardized is True:
            logmean = self._logmoment_quad(self._one, -np.inf, **self._parameters)
        else:
            logmean = None

        logcenter = logmean if logcenter is None else logcenter
        res = self._logmoment_quad(order, logcenter, **self._parameters)
        if standardized:
            logvar = self._logmoment_quad(2, logmean, **self._parameters)
            res = res - logvar * (order/2)
        return res

    def _logmoment_quad(self, order, logcenter, **params):
        def logintegrand(x, order, logcenter, **params):
            logpdf = self._logpxf_dispatch(x, **params)
            return logpdf + order * _logexpxmexpy(np.log(x + 0j), logcenter)
            ## if logx == logcenter, `_logexpxmexpy` returns (-inf + 0j)
            ## multiplying by order produces (-inf + nan j) - bad
            ## We're skipping logmoment tests, so we might don't need to fix
            ## now, but if we ever do use run them, this might help:
            # logx = np.log(x+0j)
            # out = np.asarray(logpdf + order*_logexpxmexpy(logx, logcenter))
            # i = (logx == logcenter)
            # out[i] = logpdf[i]

Review comment (suggestion):
These were not exposed publicly, and i don't think we need to unless there is a request. Remove unused code.

Code after:

        if 'cache' in methods:
            lmoment = self._lmoment_cache.get(order, None)

        if lmoment is None and 'formula' in methods:
            lmoment = self._lmoment_formula(order, **params)

        if lmoment is None and 'general' in methods:
            lmoment = self._lmoment_general(order, **params)

        if lmoment is None and 'quadrature_icdf' in methods and (
                self._overrides('_icdf_formula') or self._overrides('_iccdf_formula')):
            lmoment = self._lmoment_integrate_icdf(order, **params)

        if lmoment is None and 'order_statistics' in methods:
            lmoment = self._lmoment_from_order_statistics(order, **params)

        if lmoment is None and 'quadrature_icdf' in methods:
            lmoment = self._lmoment_integrate_icdf(order, **params)

        if lmoment is not None and self.cache_policy != _NO_CACHE:
            self._lmoment_cache[order] = lmoment

        return lmoment

    def _lmoment_formula(self, order, **params):
        return None

    def _lmoment_general(self, order, **params):
        return self.mean() if order == 1 else None

    def _lmoment_from_order_statistics(self, order, **params):
        k = np.arange(order)
        k = xpx.atleast_nd(k, ndim=self._ndim + 1).T
        E = order_statistic(self, r=order-k, n=order).mean()
        bc = special.binom(order-1, k)
        return np.sum((-1)**k * bc * E, axis=0) / order

    def _lmoment_integrate_icdf(self, order, **params):
        def integrand(p, **params):
            x = self._icdf_dispatch(p, **params)
            P = special.eval_sh_legendre(order - 1, p)
            return x * P
        return self._quadrature(integrand, limits=(0., 1.), params=params)

    ### Convenience

    def plot(self, x='x', y=None, *, t=None, ax=None):
        r"""Plot a function of the distribution.

        Convenience function for quick visualization of the distribution