Skip to content

Inconsistent array types from sc.get.aggregate #2892

Closed

Description

@ivirshup

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?

cc: @Intron7

The array types returned for the various aggregations in sc.get.aggregate are different (see example)

This can lead to somewhat confusing behavior downstream, especially while we are using the sparse matrix classes.

I would suggest we default to a dense result and consider adding an argument array_type that determines the type of the arrays added to layers.

Minimal code sample

import scanpy as sc

adata = sc.datasets.pbmc3k_processed().raw.to_adata()

aggregated = sc.get.aggregate(adata, "louvain", ["sum", "count_nonzero"])
type(aggregated.layers["sum"])
# numpy.ndarray

type(aggregated.layers["count_nonzero"])
# scipy.sparse._csr.csr_matrix

Error output

No response

Versions

Details
-----
anndata     0.10.5.post1
scanpy      1.10.0.dev315+gf6d5ac94
-----
IPython             8.20.0
PIL                 10.2.0
asciitree           NA
asttokens           NA
cloudpickle         3.0.0
cycler              0.12.1
cython_runtime      NA
dask                2024.1.1
dateutil            2.8.2
decorator           5.1.1
executing           2.0.1
fasteners           0.19
h5py                3.10.0
igraph              0.11.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.41.1
markupsafe          2.1.4
matplotlib          3.8.2
mpl_toolkits        NA
msgpack             1.0.7
natsort             8.4.0
numba               0.58.1
numcodecs           0.12.1
numpy               1.26.3
packaging           23.2
pandas              2.2.0
parso               0.8.3
pexpect             4.9.0
prompt_toolkit      3.0.43
psutil              5.9.8
ptyprocess          0.7.0
pure_eval           0.2.2
pygments            2.17.2
pyparsing           3.1.1
pytz                2023.4
scipy               1.12.0
session_info        1.0.0
six                 1.16.0
sklearn             1.4.0
sparse              0.15.1
stack_data          0.6.3
tblib               3.0.0
texttable           1.7.0
threadpoolctl       3.2.0
tlz                 0.12.1
toolz               0.12.1
traitlets           5.14.1
wcwidth             0.2.13
yaml                6.0.1
zarr                2.16.1
zipp                NA
-----
Python 3.11.7 | packaged by conda-forge | (main, Dec 23 2023, 14:43:09) [GCC 12.3.0]
Linux-5.15.0-87-generic-x86_64-with-glibc2.35
-----
Session information updated at 2024-03-04 13:41

Activity

  1. added this to the 1.10.0 milestone on Mar 4, 2024
  2. ivirshup commented on Mar 4, 2024

    @ivirshup
    MemberAuthor

    @Intron7 wdyt about having some kind of result_type argument?

  3. Intron7 commented on Mar 5, 2024

    @Intron7
    Member

    @ivirshup we could have this. But what would the default be?

  4. ivirshup commented on Mar 5, 2024

    @ivirshup
    MemberAuthor

    I think dense is probably the right answer in most cases. Sparse is useful for approaches like meta-cells, but I'm actually not sure how much people care about those rn.

  5. Intron7 commented on Mar 5, 2024

    @Intron7
    Member

    I mean we can always add this function later if people want it

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area – API

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions