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

.shape attribute of arrays created with from_h5ad generates error #10

Closed
bkmartinjr opened this issue Apr 27, 2022 · 4 comments
Closed
Assignees

Comments

@bkmartinjr
Copy link
Member

Create an scgroup with from_h5ad, open a component array (eg, obs) and inspect its shape parameter -- generates an error.

Test case: run the following from the apis/python directory and you will get an error on the line that prints the shape parameter.

Output:

$ python temp/test1.py
0.14.1
/home/bruce/projects/TileDB-SingleCell/venv/lib/python3.9/site-packages/anndata/compat/__init__.py:232: FutureWarning: Moving element from .uns['neighbors']['distances'] to .obsp['distances'].

This is where adjacency matrices should go now.
  warn(
/home/bruce/projects/TileDB-SingleCell/venv/lib/python3.9/site-packages/anndata/compat/__init__.py:232: FutureWarning: Moving element from .uns['neighbors']['connectivities'] to .obsp['connectivities'].

This is where adjacency matrices should go now.
  warn(
Traceback (most recent call last):
  File "/home/bruce/projects/TileDB-SingleCell/apis/python/temp/test1.py", line 16, in <module>
    sys.exit(main())
  File "/home/bruce/projects/TileDB-SingleCell/apis/python/temp/test1.py", line 12, in main
    print(obs.shape)
  File "tiledb/libtiledb.pyx", line 3607, in tiledb.libtiledb.Array.shape.__get__
  File "tiledb/libtiledb.pyx", line 3014, in tiledb.libtiledb.ArraySchema.shape.__get__
  File "tiledb/libtiledb.pyx", line 2329, in tiledb.libtiledb.Domain.shape.__get__
  File "tiledb/libtiledb.pyx", line 2188, in genexpr
  File "tiledb/libtiledb.pyx", line 2188, in genexpr
  File "tiledb/libtiledb.pyx", line 2056, in tiledb.libtiledb.Dim.shape.__get__
  File "tiledb/libtiledb.pyx", line 2041, in tiledb.libtiledb.Dim._shape
AttributeError: 'NoneType' object has no attribute 'item'

Test case:

import sys
import tiledb
import tiledbsc


def main():
    print(tiledb.__version__)
    sc = tiledbsc.SCGroup("./temp/test1", verbose=False)
    sc.from_h5ad("./anndata/pbmc3k_processed.h5ad")

    obs = tiledb.open("./temp/test1/obs")
    print(obs.shape)


if __name__ == "__main__":
    sys.exit(main())
@johnkerl
Copy link
Member

The sparse matrices in the group all have exceptions on A.shape; the dense ones do not:

#!/usr/bin/env python

import tiledb
import tiledbsc

#g = tiledbsc.SCGroup("test")
#g.from_h5ad("/Users/johnkerl/scdata/anndata/pbmc-small.h5ad")

for x in ['X/data', 'obs', 'var', 'obsm/X_pca', 'varm/PCs', 'obsp/distances']:
    with tiledb.open('./test/' + x) as A:
        print()
        print(A.uri)
        #print(A.schema)
        try:
            print(A.shape)
        except:
            print('exc')

#./test/X/data         sparse=True,
#./test/obs            sparse=True,
#./test/var            sparse=True,
#./test/obsm/X_pca     sparse=False,
#./test/varm/PCs       sparse=False,
#./test/obsp/distances sparse=False,

#./test/X/data         exc
#./test/obs            exc
#./test/var            exc
#./test/obsm/X_pca     (80, 19)
#./test/varm/PCs       (20, 19)
#./test/obsp/distances (80, 80)

I'll check on what the expected behavior is for .shape on a sparse array (throwing an exception doesn't feel right).

@johnkerl
Copy link
Member

I checked with the team and this is a bug in TileDB-Py:

  • Sparse array with int dims has a .shape
  • Sparse array with float or string dims does not
    • With float dims, .shape correctly does TypeError: shape valid only for integer domains
    • With string dims, we get the less-helpful error message reported here

@johnkerl
Copy link
Member

TileDB-Py PR: TileDB-Inc/TileDB-Py#1055

@johnkerl
Copy link
Member

The true ask here is handled in #125.

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

No branches or pull requests

2 participants