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

Subsetting w/ empty list when X is dense throws error #1149

Closed
3 tasks done
ivirshup opened this issue Sep 27, 2023 · 0 comments · Fixed by #1243
Closed
3 tasks done

Subsetting w/ empty list when X is dense throws error #1149

ivirshup opened this issue Sep 27, 2023 · 0 comments · Fixed by #1243

Comments

@ivirshup
Copy link
Member

ivirshup commented Sep 27, 2023

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 anndata.
  • (optional) I have confirmed this bug exists on the master branch of anndata.

Report

Code:

import numpy as np, anndata as ad

ad.AnnData(np.ones((3, 3)))[:, []].X

Traceback:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[4], line 1
----> 1 ad.AnnData(np.ones((3, 3)))[:, []].X

File ~/github/anndata/anndata/_core/anndata.py:656, in AnnData.X(self)
    653     X = None
    654 elif self.is_view:
    655     X = as_view(
--> 656         _subset(self._adata_ref.X, (self._oidx, self._vidx)),
    657         ElementRef(self, "X"),
    658     )
    659 else:
    660     X = self._X

File /usr/local/Cellar/python@3.9/3.9.18/Frameworks/Python.framework/Versions/3.9/lib/python3.9/functools.py:888, in singledispatch.<locals>.wrapper(*args, **kw)
    884 if not args:
    885     raise TypeError(f'{funcname} requires at least '
    886                     '1 positional argument')
--> 888 return dispatch(args[0].__class__)(*args, **kw)

File ~/github/anndata/anndata/_core/index.py:144, in _subset(a, subset_idx)
    142 if all(isinstance(x, cabc.Iterable) for x in subset_idx):
    143     subset_idx = np.ix_(*subset_idx)
--> 144 return a[subset_idx]

IndexError: arrays used as indices must be of integer (or boolean) type

Works when X is sparse. Probably not a super common use case.

Versions

-----
IPython             8.14.0
anndata             0.10.0rc2.dev2+gfa8149d9.d20230927
numpy               1.24.4
session_info        1.0.0
-----
asciitree           NA
asttokens           NA
awkward             2.3.1
awkward_cpp         NA
backcall            0.2.0
cloudpickle         2.2.1
colorama            0.4.6
cython_runtime      NA
cytoolz             0.10.1
dask                2023.9.1
dateutil            2.8.2
decorator           5.1.0
entrypoints         0.3
exceptiongroup      1.0.4
executing           0.8.2
fasteners           0.17.3
google              NA
h5py                3.9.0
importlib_metadata  NA
jedi                0.18.1
jinja2              3.1.1
llvmlite            0.40.1
markupsafe          2.1.1
msgpack             1.0.3
natsort             8.3.0
numba               0.57.1
numcodecs           0.10.2
numexpr             2.8.1
packaging           23.1
pandas              2.1.0
parso               0.8.2
pexpect             4.8.0
pickleshare         0.7.5
prompt_toolkit      3.0.38
psutil              5.9.0
ptyprocess          0.7.0
pure_eval           0.2.1
pyarrow             12.0.1
pygments            2.16.1
pytz                2022.7.1
regex               2.5.112
ruamel              NA
scipy               1.11.2
setuptools_scm      NA
sitecustomize       NA
six                 1.16.0
sparse              0.14.0
sphinxcontrib       NA
stack_data          0.1.4
tblib               1.7.0
tlz                 0.10.1
toolz               0.12.0
traitlets           5.6.0
typing_extensions   NA
wcwidth             0.2.5
xxhash              NA
yaml                5.4.1
zappy               NA
zarr                2.16.1
zipp                NA
zoneinfo            NA
-----
Python 3.9.18 (main, Aug 24 2023, 21:32:48) [Clang 14.0.3 (clang-1403.0.22.14.1)]
macOS-13.4.1-x86_64-i386-64bit
-----
Session information updated at 2023-09-27 12:34
@ivirshup ivirshup changed the title Subsetting to w/ empty list when X is dense errors Subsetting w/ empty list when X is dense throws error Sep 27, 2023
@ivirshup ivirshup modified the milestones: 0.10.1, 0.10.2, 0.10.3 Oct 4, 2023
@flying-sheep flying-sheep modified the milestones: 0.10.3, 0.10.4 Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants