lamindb 0.76.7__py3-none-any.whl → 0.76.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lamindb/__init__.py +113 -113
- lamindb/_artifact.py +1205 -1178
- lamindb/_can_validate.py +579 -579
- lamindb/_collection.py +387 -387
- lamindb/_curate.py +1601 -1601
- lamindb/_feature.py +155 -155
- lamindb/_feature_set.py +242 -242
- lamindb/_filter.py +23 -23
- lamindb/_finish.py +256 -256
- lamindb/_from_values.py +382 -382
- lamindb/_is_versioned.py +40 -40
- lamindb/_parents.py +476 -476
- lamindb/_query_manager.py +125 -125
- lamindb/_query_set.py +362 -362
- lamindb/_record.py +649 -649
- lamindb/_run.py +57 -57
- lamindb/_save.py +308 -295
- lamindb/_storage.py +14 -14
- lamindb/_transform.py +127 -127
- lamindb/_ulabel.py +56 -56
- lamindb/_utils.py +9 -9
- lamindb/_view.py +72 -72
- lamindb/core/__init__.py +94 -94
- lamindb/core/_context.py +574 -574
- lamindb/core/_data.py +438 -438
- lamindb/core/_feature_manager.py +867 -867
- lamindb/core/_label_manager.py +253 -253
- lamindb/core/_mapped_collection.py +597 -597
- lamindb/core/_settings.py +187 -187
- lamindb/core/_sync_git.py +138 -138
- lamindb/core/_track_environment.py +27 -27
- lamindb/core/datasets/__init__.py +59 -59
- lamindb/core/datasets/_core.py +571 -571
- lamindb/core/datasets/_fake.py +36 -36
- lamindb/core/exceptions.py +90 -77
- lamindb/core/fields.py +12 -12
- lamindb/core/loaders.py +164 -164
- lamindb/core/schema.py +56 -56
- lamindb/core/storage/__init__.py +25 -25
- lamindb/core/storage/_anndata_accessor.py +740 -740
- lamindb/core/storage/_anndata_sizes.py +41 -41
- lamindb/core/storage/_backed_access.py +98 -98
- lamindb/core/storage/_tiledbsoma.py +204 -204
- lamindb/core/storage/_valid_suffixes.py +21 -21
- lamindb/core/storage/_zarr.py +110 -110
- lamindb/core/storage/objects.py +62 -62
- lamindb/core/storage/paths.py +172 -141
- lamindb/core/subsettings/__init__.py +12 -12
- lamindb/core/subsettings/_creation_settings.py +38 -38
- lamindb/core/subsettings/_transform_settings.py +21 -21
- lamindb/core/types.py +19 -19
- lamindb/core/versioning.py +158 -158
- lamindb/integrations/__init__.py +12 -12
- lamindb/integrations/_vitessce.py +107 -107
- lamindb/setup/__init__.py +14 -14
- lamindb/setup/core/__init__.py +4 -4
- {lamindb-0.76.7.dist-info → lamindb-0.76.8.dist-info}/LICENSE +201 -201
- {lamindb-0.76.7.dist-info → lamindb-0.76.8.dist-info}/METADATA +3 -3
- lamindb-0.76.8.dist-info/RECORD +60 -0
- {lamindb-0.76.7.dist-info → lamindb-0.76.8.dist-info}/WHEEL +1 -1
- lamindb-0.76.7.dist-info/RECORD +0 -60
@@ -1,41 +1,41 @@
|
|
1
|
-
from __future__ import annotations
|
2
|
-
|
3
|
-
import warnings
|
4
|
-
|
5
|
-
import scipy.sparse as sparse
|
6
|
-
from pandas import DataFrame
|
7
|
-
|
8
|
-
|
9
|
-
def _size_val(val):
|
10
|
-
with warnings.catch_warnings():
|
11
|
-
warnings.filterwarnings("ignore", category=FutureWarning)
|
12
|
-
|
13
|
-
if sparse.issparse(val):
|
14
|
-
val_csr = sparse.csr_matrix(val)
|
15
|
-
return val_csr.data.nbytes + val_csr.indptr.nbytes + val_csr.indices.nbytes
|
16
|
-
else:
|
17
|
-
return val.__sizeof__()
|
18
|
-
|
19
|
-
|
20
|
-
def _size_elem(elem):
|
21
|
-
if hasattr(elem, "keys") and not isinstance(elem, DataFrame):
|
22
|
-
return sum([_size_val(elem[k]) for k in elem.keys()])
|
23
|
-
else:
|
24
|
-
return _size_val(elem)
|
25
|
-
|
26
|
-
|
27
|
-
def _size_raw(raw):
|
28
|
-
return _size_val(raw.X) + _size_val(raw.var) + _size_elem(raw.varm)
|
29
|
-
|
30
|
-
|
31
|
-
def size_adata(adata):
|
32
|
-
with warnings.catch_warnings():
|
33
|
-
warnings.filterwarnings("ignore", category=FutureWarning)
|
34
|
-
|
35
|
-
total_size = adata.__sizeof__()
|
36
|
-
|
37
|
-
raw = adata.raw
|
38
|
-
if raw is not None:
|
39
|
-
total_size += _size_raw(raw)
|
40
|
-
|
41
|
-
return total_size
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
import warnings
|
4
|
+
|
5
|
+
import scipy.sparse as sparse
|
6
|
+
from pandas import DataFrame
|
7
|
+
|
8
|
+
|
9
|
+
def _size_val(val):
|
10
|
+
with warnings.catch_warnings():
|
11
|
+
warnings.filterwarnings("ignore", category=FutureWarning)
|
12
|
+
|
13
|
+
if sparse.issparse(val):
|
14
|
+
val_csr = sparse.csr_matrix(val)
|
15
|
+
return val_csr.data.nbytes + val_csr.indptr.nbytes + val_csr.indices.nbytes
|
16
|
+
else:
|
17
|
+
return val.__sizeof__()
|
18
|
+
|
19
|
+
|
20
|
+
def _size_elem(elem):
|
21
|
+
if hasattr(elem, "keys") and not isinstance(elem, DataFrame):
|
22
|
+
return sum([_size_val(elem[k]) for k in elem.keys()])
|
23
|
+
else:
|
24
|
+
return _size_val(elem)
|
25
|
+
|
26
|
+
|
27
|
+
def _size_raw(raw):
|
28
|
+
return _size_val(raw.X) + _size_val(raw.var) + _size_elem(raw.varm)
|
29
|
+
|
30
|
+
|
31
|
+
def size_adata(adata):
|
32
|
+
with warnings.catch_warnings():
|
33
|
+
warnings.filterwarnings("ignore", category=FutureWarning)
|
34
|
+
|
35
|
+
total_size = adata.__sizeof__()
|
36
|
+
|
37
|
+
raw = adata.raw
|
38
|
+
if raw is not None:
|
39
|
+
total_size += _size_raw(raw)
|
40
|
+
|
41
|
+
return total_size
|
@@ -1,98 +1,98 @@
|
|
1
|
-
from __future__ import annotations
|
2
|
-
|
3
|
-
from dataclasses import dataclass
|
4
|
-
from typing import TYPE_CHECKING, Any, Callable
|
5
|
-
|
6
|
-
from anndata._io.specs.registry import get_spec
|
7
|
-
from lnschema_core import Artifact
|
8
|
-
|
9
|
-
from ._anndata_accessor import AnnDataAccessor, StorageType, registry
|
10
|
-
from ._tiledbsoma import _open_tiledbsoma
|
11
|
-
from .paths import filepath_from_artifact
|
12
|
-
|
13
|
-
if TYPE_CHECKING:
|
14
|
-
from fsspec.core import OpenFile
|
15
|
-
from tiledbsoma import Collection as SOMACollection
|
16
|
-
from tiledbsoma import Experiment as SOMAExperiment
|
17
|
-
from upath import UPath
|
18
|
-
|
19
|
-
|
20
|
-
# this dynamically creates a subclass of a context manager class
|
21
|
-
# and reassigns it to an instance of the superclass
|
22
|
-
# so that the instance calls finalize on close or exit
|
23
|
-
def _track_writes_factory(obj: Any, finalize: Callable):
|
24
|
-
closed: bool = False
|
25
|
-
|
26
|
-
tracked_class = obj.__class__
|
27
|
-
type_dict = {"__doc__": tracked_class.__doc__}
|
28
|
-
if hasattr(tracked_class, "__slots__"):
|
29
|
-
type_dict["__slots__"] = ()
|
30
|
-
if hasattr(tracked_class, "__exit__"):
|
31
|
-
|
32
|
-
def __exit__(self, exc_type, exc_val, exc_tb):
|
33
|
-
nonlocal closed
|
34
|
-
tracked_class.__exit__(self, exc_type, exc_val, exc_tb)
|
35
|
-
if not closed:
|
36
|
-
finalize()
|
37
|
-
closed = True
|
38
|
-
|
39
|
-
type_dict["__exit__"] = __exit__
|
40
|
-
if hasattr(tracked_class, "close"):
|
41
|
-
|
42
|
-
def close(self, *args, **kwargs):
|
43
|
-
nonlocal closed
|
44
|
-
tracked_class.close(self, *args, **kwargs)
|
45
|
-
if not closed:
|
46
|
-
finalize()
|
47
|
-
closed = True
|
48
|
-
|
49
|
-
type_dict["close"] = close
|
50
|
-
|
51
|
-
Track = type(tracked_class.__name__ + "Track", (tracked_class,), type_dict)
|
52
|
-
obj.__class__ = Track
|
53
|
-
return obj
|
54
|
-
|
55
|
-
|
56
|
-
@dataclass
|
57
|
-
class BackedAccessor:
|
58
|
-
"""h5py.File or zarr.Group accessor."""
|
59
|
-
|
60
|
-
connection: OpenFile
|
61
|
-
"""The connection."""
|
62
|
-
storage: StorageType
|
63
|
-
"""The storage access."""
|
64
|
-
|
65
|
-
|
66
|
-
def backed_access(
|
67
|
-
artifact_or_filepath: Artifact | UPath,
|
68
|
-
mode: str = "r",
|
69
|
-
using_key: str | None = None,
|
70
|
-
) -> AnnDataAccessor | BackedAccessor | SOMACollection | SOMAExperiment:
|
71
|
-
if isinstance(artifact_or_filepath, Artifact):
|
72
|
-
filepath = filepath_from_artifact(artifact_or_filepath, using_key=using_key)
|
73
|
-
else:
|
74
|
-
filepath = artifact_or_filepath
|
75
|
-
name = filepath.name
|
76
|
-
suffix = filepath.suffix
|
77
|
-
|
78
|
-
if name == "soma" or suffix == ".tiledbsoma":
|
79
|
-
if mode not in {"r", "w"}:
|
80
|
-
raise ValueError("`mode` should be either 'r' or 'w' for tiledbsoma.")
|
81
|
-
return _open_tiledbsoma(filepath, mode=mode) # type: ignore
|
82
|
-
elif suffix in {".h5", ".hdf5", ".h5ad"}:
|
83
|
-
conn, storage = registry.open("h5py", filepath, mode=mode)
|
84
|
-
elif suffix == ".zarr":
|
85
|
-
conn, storage = registry.open("zarr", filepath, mode=mode)
|
86
|
-
else:
|
87
|
-
raise ValueError(
|
88
|
-
"object should have .h5, .hdf5, .h5ad, .zarr, .tiledbsoma suffix, not"
|
89
|
-
f" {suffix}."
|
90
|
-
)
|
91
|
-
|
92
|
-
is_anndata = suffix == ".h5ad" or get_spec(storage).encoding_type == "anndata"
|
93
|
-
if is_anndata:
|
94
|
-
if mode != "r":
|
95
|
-
raise ValueError("Can only access `AnnData` with mode='r'.")
|
96
|
-
return AnnDataAccessor(conn, storage, name)
|
97
|
-
else:
|
98
|
-
return BackedAccessor(conn, storage)
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
from dataclasses import dataclass
|
4
|
+
from typing import TYPE_CHECKING, Any, Callable
|
5
|
+
|
6
|
+
from anndata._io.specs.registry import get_spec
|
7
|
+
from lnschema_core import Artifact
|
8
|
+
|
9
|
+
from ._anndata_accessor import AnnDataAccessor, StorageType, registry
|
10
|
+
from ._tiledbsoma import _open_tiledbsoma
|
11
|
+
from .paths import filepath_from_artifact
|
12
|
+
|
13
|
+
if TYPE_CHECKING:
|
14
|
+
from fsspec.core import OpenFile
|
15
|
+
from tiledbsoma import Collection as SOMACollection
|
16
|
+
from tiledbsoma import Experiment as SOMAExperiment
|
17
|
+
from upath import UPath
|
18
|
+
|
19
|
+
|
20
|
+
# this dynamically creates a subclass of a context manager class
|
21
|
+
# and reassigns it to an instance of the superclass
|
22
|
+
# so that the instance calls finalize on close or exit
|
23
|
+
def _track_writes_factory(obj: Any, finalize: Callable):
|
24
|
+
closed: bool = False
|
25
|
+
|
26
|
+
tracked_class = obj.__class__
|
27
|
+
type_dict = {"__doc__": tracked_class.__doc__}
|
28
|
+
if hasattr(tracked_class, "__slots__"):
|
29
|
+
type_dict["__slots__"] = ()
|
30
|
+
if hasattr(tracked_class, "__exit__"):
|
31
|
+
|
32
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
33
|
+
nonlocal closed
|
34
|
+
tracked_class.__exit__(self, exc_type, exc_val, exc_tb)
|
35
|
+
if not closed:
|
36
|
+
finalize()
|
37
|
+
closed = True
|
38
|
+
|
39
|
+
type_dict["__exit__"] = __exit__
|
40
|
+
if hasattr(tracked_class, "close"):
|
41
|
+
|
42
|
+
def close(self, *args, **kwargs):
|
43
|
+
nonlocal closed
|
44
|
+
tracked_class.close(self, *args, **kwargs)
|
45
|
+
if not closed:
|
46
|
+
finalize()
|
47
|
+
closed = True
|
48
|
+
|
49
|
+
type_dict["close"] = close
|
50
|
+
|
51
|
+
Track = type(tracked_class.__name__ + "Track", (tracked_class,), type_dict)
|
52
|
+
obj.__class__ = Track
|
53
|
+
return obj
|
54
|
+
|
55
|
+
|
56
|
+
@dataclass
|
57
|
+
class BackedAccessor:
|
58
|
+
"""h5py.File or zarr.Group accessor."""
|
59
|
+
|
60
|
+
connection: OpenFile
|
61
|
+
"""The connection."""
|
62
|
+
storage: StorageType
|
63
|
+
"""The storage access."""
|
64
|
+
|
65
|
+
|
66
|
+
def backed_access(
|
67
|
+
artifact_or_filepath: Artifact | UPath,
|
68
|
+
mode: str = "r",
|
69
|
+
using_key: str | None = None,
|
70
|
+
) -> AnnDataAccessor | BackedAccessor | SOMACollection | SOMAExperiment:
|
71
|
+
if isinstance(artifact_or_filepath, Artifact):
|
72
|
+
filepath, _ = filepath_from_artifact(artifact_or_filepath, using_key=using_key)
|
73
|
+
else:
|
74
|
+
filepath = artifact_or_filepath
|
75
|
+
name = filepath.name
|
76
|
+
suffix = filepath.suffix
|
77
|
+
|
78
|
+
if name == "soma" or suffix == ".tiledbsoma":
|
79
|
+
if mode not in {"r", "w"}:
|
80
|
+
raise ValueError("`mode` should be either 'r' or 'w' for tiledbsoma.")
|
81
|
+
return _open_tiledbsoma(filepath, mode=mode) # type: ignore
|
82
|
+
elif suffix in {".h5", ".hdf5", ".h5ad"}:
|
83
|
+
conn, storage = registry.open("h5py", filepath, mode=mode)
|
84
|
+
elif suffix == ".zarr":
|
85
|
+
conn, storage = registry.open("zarr", filepath, mode=mode)
|
86
|
+
else:
|
87
|
+
raise ValueError(
|
88
|
+
"object should have .h5, .hdf5, .h5ad, .zarr, .tiledbsoma suffix, not"
|
89
|
+
f" {suffix}."
|
90
|
+
)
|
91
|
+
|
92
|
+
is_anndata = suffix == ".h5ad" or get_spec(storage).encoding_type == "anndata"
|
93
|
+
if is_anndata:
|
94
|
+
if mode != "r":
|
95
|
+
raise ValueError("Can only access `AnnData` with mode='r'.")
|
96
|
+
return AnnDataAccessor(conn, storage, name)
|
97
|
+
else:
|
98
|
+
return BackedAccessor(conn, storage)
|