# Buggy code
def compute_neighbors(
    self,
    n_neighbors: int = 30,
    knn: bool = True,
    n_pcs: Optional[int] = None,
    use_rep: Optional[str] = None,
    method: _Method = "umap",
    random_state: Optional[Union[int, RandomState]] = 0,
    write_knn_indices: bool = False,
    metric: _Metric = "euclidean",
    metric_kwds: Mapping[str, Any] = MappingProxyType({}),
) -> None:
    """\
        Compute distances and connectivities of neighbors.

        Parameters
        ----------
        n_neighbors
             Use this number of nearest neighbors.
        knn
             Restrict result to `n_neighbors` nearest neighbors.
        {n_pcs}
        {use_rep}

        Returns
        -------
        Writes sparse graph attributes `.distances` and `.connectivities`.
        Also writes `.knn_indices` and `.knn_distances` if
        `write_knn_indices==True`.
        """
    from sklearn.metrics import pairwise_distances

    start_neighbors = logg.debug("computing neighbors")
    if n_neighbors > self._adata.shape[0]:  # very small datasets
        n_neighbors = 1 + int(0.5 * self._adata.shape[0])
        logg.warning(f"n_obs too small: adjusting to `n_neighbors = {n_neighbors}`")
    if method == "umap" and not knn:
        raise ValueError("`method = 'umap' only with `knn = True`.")
    if method == "rapids" and metric != "euclidean":
        raise ValueError("`method` 'rapids' only supports the 'euclidean' `metric`.")
    if method not in {"umap", "gauss", "rapids"}:
        raise ValueError("`method` needs to be 'umap', 'gauss', or 'rapids'.")
    if self._adata.shape[0] >= 10000 and not knn:
        logg.warning("Using high n_obs without `knn=True` takes a lot of memory...")
    self.n_neighbors = n_neighbors
    self.knn = knn
    X = _choose_representation(self._adata, use_rep=use_rep, n_pcs=n_pcs)
    # neighbor search
    use_dense_distances = (metric == "euclidean" and X.shape[0] < 8192) or knn == False
    if use_dense_distances:
        _distances = pairwise_distances(X, metric=metric, **metric_kwds)
        knn_indices, knn_distances = _get_indices_distances_from_dense_matrix(
            _distances, n_neighbors
        )
        if knn:
            self._distances = _get_sparse_matrix_from_indices_distances_numpy(
                knn_indices, knn_distances, X.shape[0], n_neighbors
            )
        else:
            self._distances = _distances
    elif method == "rapids":
        knn_indices, knn_distances = compute_neighbors_rapids(X, n_neighbors)
    else:
        # non-euclidean case and approx nearest neighbors
        if X.shape[0] < 4096:
            X = pairwise_distances(X, metric=metric, **metric_kwds)
            metric = "precomputed"
        knn_indices, knn_distances, forest = compute_neighbors_umap(
            X, n_neighbors, random_state, metric=metric, metric_kwds=metric_kwds
        )
        # very cautious here
        try:
            if forest:
                self._rp_forest = _make_forest_dict(forest)
        except:
            pass
    # write indices as attributes
    if write_knn_indices:
        self.knn_indices = knn_indices
        self.knn_distances = knn_distances
    start_connect = logg.debug("computed neighbors", time=start_neighbors)
    if not use_dense_distances or method in {"umap", "rapids"}:
        # we need self._distances also for method == 'gauss' if we didn't
        # use dense distances
        self._distances, self._connectivities = _compute_connectivities_umap(
            knn_indices,
            knn_distances,
            self._adata.shape[0],
            self.n_neighbors,
        )
    # overwrite the umap connectivities if method is 'gauss'
    # self._distances is unaffected by this
    if method == "gauss":
        self._compute_connectivities_diffmap()
    logg.debug("computed connectivities", time=start_connect)
    self._number_connected_components = 1
    if issparse(self._connectivities):
        from scipy.sparse.csgraph import connected_components

        self._connected_components = connected_components(self._connectivities)
        self._number_connected_components = self._connected_components[0]


# Traceback (sphinx.errors.SphinxWarning)
/home/docs/checkouts/readthedocs.org/user_builds/icb-scanpy/envs/latest/lib/python3.6/site-packages/anndata/_core/anndata.py:21: FutureWarning: pandas.core.index is deprecated and will be removed in a future version.  The public classes are available in the top-level namespace.
from pandas.core.index import RangeIndex
/home/docs/checkouts/readthedocs.org/user_builds/icb-scanpy/envs/latest/lib/python3.6/site-packages/setuptools_scm/git.py:68: UserWarning: "/home/docs/checkouts/readthedocs.org/user_builds/icb-scanpy/checkouts/latest" is shallow and may cause errors
warnings.warn('"{}" is shallow and may cause errors'.format(wd.path))

Traceback (most recent call last):
File "/home/docs/checkouts/readthedocs.org/user_builds/icb-scanpy/envs/latest/lib/python3.6/site-packages/sphinx/cmd/build.py", line 276, in build_main
app.build(args.force_all, filenames)
File "/home/docs/checkouts/readthedocs.org/user_builds/icb-scanpy/envs/latest/lib/python3.6/site-packages/sphinx/application.py", line 349, in build
self.builder.build_update()
File "/home/docs/checkouts/readthedocs.org/user_builds/icb-scanpy/envs/latest/lib/python3.6/site-packages/sphinx/builders/__init__.py", line 299, in build_update
len(to_build))
File "/home/docs/checkouts/readthedocs.org/user_builds/icb-scanpy/envs/latest/lib/python3.6/site-packages/sphinx/builders/__init__.py", line 361, in build
self.write(docnames, list(updated_docnames), method)
File "/home/docs/checkouts/readthedocs.org/user_builds/icb-scanpy/envs/latest/lib/python3.6/site-packages/sphinx/builders/__init__.py", line 535, in write
self._write_serial(sorted(docnames))
File "/home/docs/checkouts/readthedocs.org/user_builds/icb-scanpy/envs/latest/lib/python3.6/site-packages/sphinx/builders/__init__.py", line 545, in _write_serial
self.write_doc(docname, doctree)
File "/home/docs/.pyenv/versions/3.6.8/lib/python3.6/contextlib.py", line 88, in __exit__
next(self.gen)
File "/home/docs/checkouts/readthedocs.org/user_builds/icb-scanpy/envs/latest/lib/python3.6/site-packages/sphinx/util/logging.py", line 219, in pending_warnings
memhandler.flushTo(logger)
File "/home/docs/checkouts/readthedocs.org/user_builds/icb-scanpy/envs/latest/lib/python3.6/site-packages/sphinx/util/logging.py", line 184, in flushTo
logger.handle(record)
File "/home/docs/.pyenv/versions/3.6.8/lib/python3.6/logging/__init__.py", line 1454, in handle
self.callHandlers(record)
File "/home/docs/.pyenv/versions/3.6.8/lib/python3.6/logging/__init__.py", line 1516, in callHandlers
hdlr.handle(record)
File "/home/docs/.pyenv/versions/3.6.8/lib/python3.6/logging/__init__.py", line 861, in handle
rv = self.filter(record)
File "/home/docs/.pyenv/versions/3.6.8/lib/python3.6/logging/__init__.py", line 720, in filter
result = f.filter(record)
File "/home/docs/checkouts/readthedocs.org/user_builds/icb-scanpy/envs/latest/lib/python3.6/site-packages/sphinx/util/logging.py", line 404, in filter
raise SphinxWarning(location + ":" + message)
sphinx.errors.SphinxWarning: /home/docs/checkouts/readthedocs.org/user_builds/icb-scanpy/checkouts/latest/scanpy/preprocessing/_simple.py:docstring of scanpy.pp.downsample_counts:17:py:class reference target not found: numpy.random.RandomState

Warning, treated as error:
/home/docs/checkouts/readthedocs.org/user_builds/icb-scanpy/checkouts/latest/scanpy/preprocessing/_simple.py:docstring of scanpy.pp.downsample_counts:17:py:class reference target not found: numpy.random.RandomState

# Fixed code
def compute_neighbors(
    self,
    n_neighbors: int = 30,
    knn: bool = True,
    n_pcs: Optional[int] = None,
    use_rep: Optional[str] = None,
    method: _Method = "umap",
    random_state: AnyRandom = 0,
    write_knn_indices: bool = False,
    metric: _Metric = "euclidean",
    metric_kwds: Mapping[str, Any] = MappingProxyType({}),
) -> None:
    """\
        Compute distances and connectivities of neighbors.

        Parameters
        ----------
        n_neighbors
             Use this number of nearest neighbors.
        knn
             Restrict result to `n_neighbors` nearest neighbors.
        {n_pcs}
        {use_rep}

        Returns
        -------
        Writes sparse graph attributes `.distances` and `.connectivities`.
        Also writes `.knn_indices` and `.knn_distances` if
        `write_knn_indices==True`.
        """
    from sklearn.metrics import pairwise_distances

    start_neighbors = logg.debug("computing neighbors")
    if n_neighbors > self._adata.shape[0]:  # very small datasets
        n_neighbors = 1 + int(0.5 * self._adata.shape[0])
        logg.warning(f"n_obs too small: adjusting to `n_neighbors = {n_neighbors}`")
    if method == "umap" and not knn:
        raise ValueError("`method = 'umap' only with `knn = True`.")
    if method == "rapids" and metric != "euclidean":
        raise ValueError("`method` 'rapids' only supports the 'euclidean' `metric`.")
    if method not in {"umap", "gauss", "rapids"}:
        raise ValueError("`method` needs to be 'umap', 'gauss', or 'rapids'.")
    if self._adata.shape[0] >= 10000 and not knn:
        logg.warning("Using high n_obs without `knn=True` takes a lot of memory...")
    self.n_neighbors = n_neighbors
    self.knn = knn
    X = _choose_representation(self._adata, use_rep=use_rep, n_pcs=n_pcs)
    # neighbor search
    use_dense_distances = (metric == "euclidean" and X.shape[0] < 8192) or knn == False
    if use_dense_distances:
        _distances = pairwise_distances(X, metric=metric, **metric_kwds)
        knn_indices, knn_distances = _get_indices_distances_from_dense_matrix(
            _distances, n_neighbors
        )
        if knn:
            self._distances = _get_sparse_matrix_from_indices_distances_numpy(
                knn_indices, knn_distances, X.shape[0], n_neighbors
            )
        else:
            self._distances = _distances
    elif method == "rapids":
        knn_indices, knn_distances = compute_neighbors_rapids(X, n_neighbors)
    else:
        # non-euclidean case and approx nearest neighbors
        if X.shape[0] < 4096:
            X = pairwise_distances(X, metric=metric, **metric_kwds)
            metric = "precomputed"
        knn_indices, knn_distances, forest = compute_neighbors_umap(
            X, n_neighbors, random_state, metric=metric, metric_kwds=metric_kwds
        )
        # very cautious here
        try:
            if forest:
                self._rp_forest = _make_forest_dict(forest)
        except:
            pass
    # write indices as attributes
    if write_knn_indices:
        self.knn_indices = knn_indices
        self.knn_distances = knn_distances
    start_connect = logg.debug("computed neighbors", time=start_neighbors)
    if not use_dense_distances or method in {"umap", "rapids"}:
        # we need self._distances also for method == 'gauss' if we didn't
        # use dense distances
        self._distances, self._connectivities = _compute_connectivities_umap(
            knn_indices,
            knn_distances,
            self._adata.shape[0],
            self.n_neighbors,
        )
    # overwrite the umap connectivities if method is 'gauss'
    # self._distances is unaffected by this
    if method == "gauss":
        self._compute_connectivities_diffmap()
    logg.debug("computed connectivities", time=start_connect)
    self._number_connected_components = 1
    if issparse(self._connectivities):
        from scipy.sparse.csgraph import connected_components

        self._connected_components = connected_components(self._connectivities)
        self._number_connected_components = self._connected_components[0]