Repository: scverse/scanpy

Issue:
Scatter plots broken on master
To recreate:

```python
import scanpy as sc
print(sc.__version__)  # 1.4+222.gdd052ed
pbmcs = sc.datasets.pbmc3k()
sc.pp.pca(pbmcs)
sc.pl.pca(pbmcs, color="MALAT1")
```

<details>
<summary>Traceback:</summary>

```python
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-a8a0d93afa77> in <module>
      3 pbmcs = sc.datasets.pbmc3k()
      4 sc.pp.pca(pbmcs)
----> 5 sc.pl.pca(pbmcs, color="MALAT1")

~/github/scanpy/scanpy/plotting/_tools/scatterplots.py in pca(adata, **kwargs)
    413     If `show==False` a `matplotlib.Axis` or a list of it.
    414     """
--> 415     return plot_scatter(adata, 'pca', **kwargs)
    416 
    417 

~/github/scanpy/scanpy/plotting/_tools/scatterplots.py in plot_scatter(adata, basis, color, gene_symbols, use_raw, sort_order, edges, edges_width, edges_color, arrows, arrows_kwds, groups, components, layer, projection, color_map, palette, size, frameon, legend_fontsize, legend_fontweight, legend_loc, ncols, hspace, wspace, title, show, save, ax, return_fig, **kwargs)
    149             adata, value_to_plot, layer=layer,
    150             groups=groups, palette=palette,
--> 151             use_raw=use_raw, gene_symbols=gene_symbols,
    152         )
    153 

~/github/scanpy/scanpy/plotting/_tools/scatterplots.py in _get_color_values(adata, value_to_plot, groups, palette, use_raw, gene_symbols, layer)
    726         elif use_raw and value_to_plot in adata.var_names:
    727             color_vector = adata.raw[:, value_to_plot].X
--> 728         elif value_to_plot in adata.raw.var_names:
    729             color_vector = adata[:, value_to_plot].X
    730 

AttributeError: 'NoneType' object has no attribute 'var_names'
```

</details>

Looks like the `raw` attribute is being checked when it's not there. @fidelram, looks like you might have been working on this recently?


Discussion:

Resolving patch:
diff --git a/scanpy/plotting/_tools/scatterplots.py b/scanpy/plotting/_tools/scatterplots.py
--- a/scanpy/plotting/_tools/scatterplots.py
+++ b/scanpy/plotting/_tools/scatterplots.py
@@ -71,16 +71,13 @@ def plot_scatter(
 
     if use_raw is None:
         # check if adata.raw is set
-        if adata.raw is None:
-            use_raw = False
-        else:
-            use_raw = True
+        use_raw = adata.raw is not None
 
     if wspace is None:
         #  try to set a wspace that is not too large or too small given the
         #  current figure size
         wspace = 0.75 / rcParams['figure.figsize'][0] + 0.02
-    if adata.raw is None and use_raw is True:
+    if adata.raw is None and use_raw:
         raise ValueError(
             "`use_raw` is set to True but AnnData object does not have raw. "
             "Please check."
@@ -723,11 +720,10 @@ def _get_color_values(adata, value_to_plot, groups=None, palette=None, use_raw=F
                 raise KeyError('Selected layer: {} is not in the layers list. The list of '
                                'valid layers is: {}'.format(layer, adata.layers.keys()))
             color_vector = adata[:, value_to_plot].layers[layer]
-        elif use_raw and value_to_plot in adata.var_names:
+        elif use_raw and value_to_plot in adata.raw.var_names:
             color_vector = adata.raw[:, value_to_plot].X
-        elif value_to_plot in adata.raw.var_names:
+        elif value_to_plot in adata.var_names:
             color_vector = adata[:, value_to_plot].X
-
         else:
             raise ValueError("The passed `color` {} is not a valid observation annotation "
                              "or variable name. Valid observation annotation keys are: {}"


Test patch: