Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mask_obs parameter modifies obs column when calling scatterplot #3400

Open
3 tasks done
mumichae opened this issue Dec 13, 2024 · 1 comment
Open
3 tasks done

mask_obs parameter modifies obs column when calling scatterplot #3400

mumichae opened this issue Dec 13, 2024 · 1 comment

Comments

@mumichae
Copy link
Contributor

Please make sure these conditions are met

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of scanpy.
  • (optional) I have confirmed this bug exists on the main branch of scanpy.

What happened?

When I plot a function with mask_obs and call a scatterplot with at least 1 color, the function modifies the column in place. This is not what I would expect when I want to plot subsets of my data.

I believe the following code should make a copy of the column:

else:
values = adata.obs_vector(value_to_plot, layer=layer)
if mask_obs is not None:
values[~mask_obs] = np.nan

Minimal code sample

import scanpy as sc

adata = sc.datasets.pbmc3k_processed()
louvain_old = adata.obs['louvain'].copy()

# call plotting function
sc.pl.umap(adata, mask_obs=(adata.obs['louvain'] == 'B cells'), color='louvain')

# column changed after calling plot
print(louvain_old.value_counts())
print(adata.obs['louvain'].value_counts())

Error output

Versions

-----
anndata     0.10.9
scanpy      1.10.4
-----
PIL                 10.3.0
asciitree           NA
asttokens           NA
cloudpickle         3.0.0
colorama            0.4.6
comm                0.2.2
cycler              0.12.1
cython_runtime      NA
cytoolz             0.12.3
dask                2024.7.1
dateutil            2.9.0
debugpy             1.8.1
decorator           5.1.1
exceptiongroup      1.2.0
executing           2.0.1
h5py                3.10.0
igraph              0.11.5
ipykernel           6.29.3
jedi                0.19.1
jinja2              3.1.3
joblib              1.3.2
kiwisolver          1.4.5
legacy_api_wrap     NA
leidenalg           0.10.2
llvmlite            0.43.0
louvain             0.8.2
lz4                 4.3.3
markupsafe          2.1.5
matplotlib          3.8.4
mpl_toolkits        NA
msgpack             1.0.7
natsort             8.4.0
numba               0.60.0
numcodecs           0.12.1
numpy               1.26.4
packaging           24.0
pandas              2.2.1
parso               0.8.3
pickleshare         0.7.5
pkg_resources       NA
platformdirs        4.2.0
prompt_toolkit      3.0.42
psutil              5.9.8
pure_eval           0.2.2
pyarrow             15.0.2
pydev_ipython       NA
pydevconsole        NA
pydevd              2.9.5
pydevd_file_utils   NA
pydevd_plugins      NA
pydevd_tracing      NA
pygments            2.17.2
pyparsing           3.1.2
pytz                2024.1
scipy               1.12.0
session_info        1.0.0
six                 1.16.0
sklearn             1.4.1.post1
sparse              0.15.4
stack_data          0.6.2
tblib               3.0.0
texttable           1.7.0
threadpoolctl       3.4.0
tlz                 0.12.3
toolz               0.12.1
tornado             6.4
traitlets           5.14.2
typing_extensions   NA
wcwidth             0.2.13
yaml                6.0.1
zarr                2.18.3
zipp                NA
zmq                 25.1.2
zoneinfo            NA
-----
IPython             8.22.2
jupyter_client      8.6.1
jupyter_core        5.7.2
-----
Python 3.10.15 | packaged by conda-forge | (main, Sep 30 2024, 17:51:04) [GCC 13.3.0]
Linux-4.18.0-553.16.1.el8_10.x86_64-x86_64-with-glibc2.28
-----
Session information updated at 2024-12-13 12:41
@mumichae mumichae added Bug 🐛 Triage 🩺 This issue needs to be triaged by a maintainer labels Dec 13, 2024
@flying-sheep flying-sheep added Area - Plotting 🌺 and removed Bug 🐛 Triage 🩺 This issue needs to be triaged by a maintainer labels Dec 16, 2024
@flying-sheep
Copy link
Member

should be an easy fix of just copying the vector before modiflying it. You want to try your hand at it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants