# Buggy code
def add_dendrogram(
    self,
    show: Optional[bool] = True,
    dendrogram_key: Optional[str] = None,
    size: Optional[float] = 0.8,
):
    """
    Show dendrogram based on the hierarchical clustering between the `groupby`
    categories. Categories are reordered to match the dendrogram order.

    The dendrogram information is computed using :func:`scanpy.tl.dendrogram`.
    If `sc.tl.dendrogram` has not been called previously the function is called
    with default parameters.

    The dendrogram is by default shown on the right side of the plot or on top
    if the axes are swapped.

    `var_names` are reordered to produce a more pleasing output if:
        * The data contains `var_groups`
        * the `var_groups` match the categories.
    The previous conditions happen by default when using Plot
    to show the results from `sc.tl.rank_genes_groups` (aka gene markers), by
    calling `sc.tl.rank_genes_groups_(plot_name)`.

    Parameters
    ----------
    show : bool, default True
    dendrogram_key : str, default None
        Needed if `sc.tl.dendrogram` saved the dendrogram using a key different
        than the default name.
    size : size of the dendrogram. Corresponds to width when dendrogram shown on
        the right of the plot, or height when shown on top.

    Returns
    -------
    BasePlot

    Examples
    --------
    >>> adata = sc.datasets.pbmc68k_reduced()
    >>> markers = {{'T-cell': 'CD3D', 'B-cell': 'CD79A', 'myeloid': 'CST3'}}
    >>> sc.pl.BasePlot(adata, markers, groupby='bulk_labels').add_dendrogram().show()

    """

    if not show:
        self.plot_group_extra = None
        return self

    if self.groupby is None or len(self.categories) <= 2:
        # dendrogram can only be computed  between groupby categories
        logg.warning(
            "Dendrogram not added. Dendrogram is added only "
            "when the number of categories to plot > 2"
        )
        return self

    self.group_extra_size = size

    # to correctly plot the dendrogram the categories need to be ordered
    # according to the dendrogram ordering.
    self._reorder_categories_after_dendrogram(dendrogram_key)

    dendro_ticks = np.arange(len(self.categories)) + 0.5

    self.group_extra_size = size
    self.plot_group_extra = {
        "kind": "dendrogram",
        "width": size,
        "dendrogram_key": dendrogram_key,
        "dendrogram_ticks": dendro_ticks,
    }
    return self


# Traceback (sphinx.errors.SphinxWarning)
/home/docs/checkouts/readthedocs.org/user_builds/icb-scanpy/envs/1204/lib/python3.6/site-packages/setuptools_scm/git.py:68: UserWarning: "/home/docs/checkouts/readthedocs.org/user_builds/icb-scanpy/checkouts/1204" is shallow and may cause errors
warnings.warn('"{}" is shallow and may cause errors'.format(wd.path))
/home/docs/checkouts/readthedocs.org/user_builds/icb-scanpy/checkouts/1204/docs/conf.py:112: RemovedInSphinx40Warning: The app.add_stylesheet() is deprecated. Please use app.add_css_file() instead.
app.add_stylesheet('css/custom.css')

Traceback (most recent call last):
File "/home/docs/checkouts/readthedocs.org/user_builds/icb-scanpy/envs/1204/lib/python3.6/site-packages/sphinx/cmd/build.py", line 280, in build_main
app.build(args.force_all, filenames)
File "/home/docs/checkouts/readthedocs.org/user_builds/icb-scanpy/envs/1204/lib/python3.6/site-packages/sphinx/application.py", line 348, in build
self.builder.build_update()
File "/home/docs/checkouts/readthedocs.org/user_builds/icb-scanpy/envs/1204/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/1204/lib/python3.6/site-packages/sphinx/builders/__init__.py", line 311, in build
updated_docnames = set(self.read())
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/1204/lib/python3.6/site-packages/sphinx/util/logging.py", line 213, in pending_warnings
memhandler.flushTo(logger)
File "/home/docs/checkouts/readthedocs.org/user_builds/icb-scanpy/envs/1204/lib/python3.6/site-packages/sphinx/util/logging.py", line 178, 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/1204/lib/python3.6/site-packages/sphinx/util/logging.py", line 415, in filter
raise SphinxWarning(location + ":" + str(message))
sphinx.errors.SphinxWarning: /home/docs/checkouts/readthedocs.org/user_builds/icb-scanpy/checkouts/1204/scanpy/plotting/_dotplot.py:docstring of scanpy.pl.dotplot:122:Inline strong start-string without end-string.

Warning, treated as error:
/home/docs/checkouts/readthedocs.org/user_builds/icb-scanpy/checkouts/1204/scanpy/plotting/_dotplot.py:docstring of scanpy.pl.dotplot:122:Inline strong start-string without end-string.

# Fixed code
def add_dendrogram(
    self,
    show: Optional[bool] = True,
    dendrogram_key: Optional[str] = None,
    size: Optional[float] = 0.8,
):
    """\
        Show dendrogram based on the hierarchical clustering between the `groupby`
        categories. Categories are reordered to match the dendrogram order.

        The dendrogram information is computed using :func:`scanpy.tl.dendrogram`.
        If `sc.tl.dendrogram` has not been called previously the function is called
        with default parameters.

        The dendrogram is by default shown on the right side of the plot or on top
        if the axes are swapped.

        `var_names` are reordered to produce a more pleasing output if:
            * The data contains `var_groups`
            * the `var_groups` match the categories.

        The previous conditions happen by default when using Plot
        to show the results from :func:`~scanpy.tl.rank_genes_groups` (aka gene markers), by
        calling `scanpy.tl.rank_genes_groups_(plot_name)`.


        Parameters
        ----------
        show
            Boolean to turn on (True) or off (False) 'add_dendrogram'
        dendrogram_key
            Needed if `sc.tl.dendrogram` saved the dendrogram using a key different
            than the default name.
        size
            size of the dendrogram. Corresponds to width when dendrogram shown on
            the right of the plot, or height when shown on top.


        Returns
        -------
        BasePlot


        Examples
        --------
        >>> adata = sc.datasets.pbmc68k_reduced()
        >>> markers = {{'T-cell': 'CD3D', 'B-cell': 'CD79A', 'myeloid': 'CST3'}}
        >>> sc.pl.BasePlot(adata, markers, groupby='bulk_labels').add_dendrogram().show()

        """

    if not show:
        self.plot_group_extra = None
        return self

    if self.groupby is None or len(self.categories) <= 2:
        # dendrogram can only be computed  between groupby categories
        logg.warning(
            "Dendrogram not added. Dendrogram is added only "
            "when the number of categories to plot > 2"
        )
        return self

    self.group_extra_size = size

    # to correctly plot the dendrogram the categories need to be ordered
    # according to the dendrogram ordering.
    self._reorder_categories_after_dendrogram(dendrogram_key)

    dendro_ticks = np.arange(len(self.categories)) + 0.5

    self.group_extra_size = size
    self.plot_group_extra = {
        "kind": "dendrogram",
        "width": size,
        "dendrogram_key": dendrogram_key,
        "dendrogram_ticks": dendro_ticks,
    }
    return self