lamindb 0.76.8__py3-none-any.whl → 0.76.10__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 +114 -113
- lamindb/_artifact.py +1206 -1205
- lamindb/_can_validate.py +621 -579
- lamindb/_collection.py +390 -387
- lamindb/_curate.py +1603 -1601
- lamindb/_feature.py +155 -155
- lamindb/_feature_set.py +244 -242
- lamindb/_filter.py +23 -23
- lamindb/_finish.py +250 -256
- lamindb/_from_values.py +403 -382
- lamindb/_is_versioned.py +40 -40
- lamindb/_parents.py +476 -476
- lamindb/_query_manager.py +125 -125
- lamindb/_query_set.py +364 -362
- lamindb/_record.py +668 -649
- lamindb/_run.py +60 -57
- lamindb/_save.py +310 -308
- lamindb/_storage.py +14 -14
- lamindb/_transform.py +130 -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 +590 -574
- lamindb/core/_data.py +510 -438
- lamindb/core/_django.py +209 -0
- lamindb/core/_feature_manager.py +994 -867
- lamindb/core/_label_manager.py +289 -253
- lamindb/core/_mapped_collection.py +631 -597
- lamindb/core/_settings.py +188 -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 +581 -571
- lamindb/core/datasets/_fake.py +36 -36
- lamindb/core/exceptions.py +90 -90
- 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 +741 -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 -172
- 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 +146 -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.8.dist-info → lamindb-0.76.10.dist-info}/LICENSE +201 -201
- {lamindb-0.76.8.dist-info → lamindb-0.76.10.dist-info}/METADATA +8 -8
- lamindb-0.76.10.dist-info/RECORD +61 -0
- {lamindb-0.76.8.dist-info → lamindb-0.76.10.dist-info}/WHEEL +1 -1
- lamindb-0.76.8.dist-info/RECORD +0 -60
lamindb/_query_manager.py
CHANGED
@@ -1,125 +1,125 @@
|
|
1
|
-
from __future__ import annotations
|
2
|
-
|
3
|
-
from typing import TYPE_CHECKING, NamedTuple
|
4
|
-
|
5
|
-
from django.db import models
|
6
|
-
from lamin_utils import logger
|
7
|
-
from lamindb_setup.core._docs import doc_args
|
8
|
-
from lnschema_core.models import Record
|
9
|
-
|
10
|
-
from lamindb.core._settings import settings
|
11
|
-
|
12
|
-
from .core._feature_manager import get_feature_set_by_slot_
|
13
|
-
|
14
|
-
if TYPE_CHECKING:
|
15
|
-
from lnschema_core.types import StrField
|
16
|
-
|
17
|
-
|
18
|
-
class QueryManager(models.Manager):
|
19
|
-
"""Manage queries through fields.
|
20
|
-
|
21
|
-
See Also:
|
22
|
-
|
23
|
-
:class:`lamindb.core.QuerySet`
|
24
|
-
`django Manager <https://docs.djangoproject.com/en/4.2/topics/db/managers/>`__
|
25
|
-
|
26
|
-
Examples:
|
27
|
-
|
28
|
-
>>> ln.save(ln.ULabel.from_values(["ULabel1", "ULabel2", "ULabel3"], field="name")) # noqa
|
29
|
-
>>> labels = ln.ULabel.filter(name__icontains = "label").all()
|
30
|
-
>>> ln.ULabel(name="ULabel1").save()
|
31
|
-
>>> label = ln.ULabel.get(name="ULabel1")
|
32
|
-
>>> label.parents.set(labels)
|
33
|
-
>>> manager = label.parents
|
34
|
-
>>> manager.df()
|
35
|
-
"""
|
36
|
-
|
37
|
-
def _track_run_input_manager(self):
|
38
|
-
if hasattr(self, "source_field_name") and hasattr(self, "target_field_name"):
|
39
|
-
if (
|
40
|
-
self.source_field_name == "collection"
|
41
|
-
and self.target_field_name == "artifact"
|
42
|
-
):
|
43
|
-
from lamindb.core._context import context
|
44
|
-
from lamindb.core._data import WARNING_RUN_TRANSFORM, _track_run_input
|
45
|
-
|
46
|
-
if (
|
47
|
-
context.run is None
|
48
|
-
and not settings.creation.artifact_silence_missing_run_warning
|
49
|
-
):
|
50
|
-
logger.warning(WARNING_RUN_TRANSFORM)
|
51
|
-
_track_run_input(self.instance)
|
52
|
-
|
53
|
-
def list(self, field: str | None = None):
|
54
|
-
"""Populate a list with the results.
|
55
|
-
|
56
|
-
Examples:
|
57
|
-
>>> ln.save(ln.ULabel.from_values(["ULabel1", "ULabel2", "ULabel3"], field="name"))
|
58
|
-
>>> labels = ln.ULabel.filter(name__icontains="label").all()
|
59
|
-
>>> ln.ULabel(name="ULabel1").save()
|
60
|
-
>>> label = ln.ULabel.get(name="ULabel1")
|
61
|
-
>>> label.parents.set(labels)
|
62
|
-
>>> label.parents.list()
|
63
|
-
>>> label.parents.list("name")
|
64
|
-
['ULabel1', 'ULabel2', 'ULabel3']
|
65
|
-
"""
|
66
|
-
self._track_run_input_manager()
|
67
|
-
if field is None:
|
68
|
-
return list(self.all())
|
69
|
-
else:
|
70
|
-
return list(self.values_list(field, flat=True))
|
71
|
-
|
72
|
-
def df(self, **kwargs):
|
73
|
-
"""Convert to DataFrame.
|
74
|
-
|
75
|
-
For `**kwargs`, see :meth:`lamindb.core.QuerySet.df`.
|
76
|
-
"""
|
77
|
-
return self.all().df(**kwargs)
|
78
|
-
|
79
|
-
def all(self):
|
80
|
-
"""Return QuerySet of all.
|
81
|
-
|
82
|
-
For `**kwargs`, see :meth:`lamindb.core.QuerySet.df`.
|
83
|
-
"""
|
84
|
-
self._track_run_input_manager()
|
85
|
-
return self._all_base_class()
|
86
|
-
|
87
|
-
@doc_args(Record.search.__doc__)
|
88
|
-
def search(self, string: str, **kwargs):
|
89
|
-
"""{}""" # noqa: D415
|
90
|
-
from ._record import _search
|
91
|
-
|
92
|
-
return _search(cls=self.all(), string=string, **kwargs)
|
93
|
-
|
94
|
-
@doc_args(Record.lookup.__doc__)
|
95
|
-
def lookup(self, field: StrField | None = None, **kwargs) -> NamedTuple:
|
96
|
-
"""{}""" # noqa: D415
|
97
|
-
from ._record import _lookup
|
98
|
-
|
99
|
-
return _lookup(cls=self.all(), field=field, **kwargs)
|
100
|
-
|
101
|
-
def __getitem__(self, item: str):
|
102
|
-
try:
|
103
|
-
source_field_name = self.source_field_name
|
104
|
-
target_field_name = self.target_field_name
|
105
|
-
|
106
|
-
if (
|
107
|
-
source_field_name in {"artifact", "collection"}
|
108
|
-
and target_field_name == "feature_set"
|
109
|
-
):
|
110
|
-
return get_feature_set_by_slot_(host=self.instance).get(item)
|
111
|
-
|
112
|
-
except Exception: # pragma: no cover
|
113
|
-
return
|
114
|
-
|
115
|
-
|
116
|
-
models.Manager.list = QueryManager.list
|
117
|
-
models.Manager.df = QueryManager.df
|
118
|
-
models.Manager.search = QueryManager.search
|
119
|
-
models.Manager.lookup = QueryManager.lookup
|
120
|
-
models.Manager.__getitem__ = QueryManager.__getitem__
|
121
|
-
models.Manager._track_run_input_manager = QueryManager._track_run_input_manager
|
122
|
-
# the two lines below would be easy if we could actually inherit; like this,
|
123
|
-
# they're suboptimal
|
124
|
-
models.Manager._all_base_class = models.Manager.all
|
125
|
-
models.Manager.all = QueryManager.all
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
from typing import TYPE_CHECKING, NamedTuple
|
4
|
+
|
5
|
+
from django.db import models
|
6
|
+
from lamin_utils import logger
|
7
|
+
from lamindb_setup.core._docs import doc_args
|
8
|
+
from lnschema_core.models import Record
|
9
|
+
|
10
|
+
from lamindb.core._settings import settings
|
11
|
+
|
12
|
+
from .core._feature_manager import get_feature_set_by_slot_
|
13
|
+
|
14
|
+
if TYPE_CHECKING:
|
15
|
+
from lnschema_core.types import StrField
|
16
|
+
|
17
|
+
|
18
|
+
class QueryManager(models.Manager):
|
19
|
+
"""Manage queries through fields.
|
20
|
+
|
21
|
+
See Also:
|
22
|
+
|
23
|
+
:class:`lamindb.core.QuerySet`
|
24
|
+
`django Manager <https://docs.djangoproject.com/en/4.2/topics/db/managers/>`__
|
25
|
+
|
26
|
+
Examples:
|
27
|
+
|
28
|
+
>>> ln.save(ln.ULabel.from_values(["ULabel1", "ULabel2", "ULabel3"], field="name")) # noqa
|
29
|
+
>>> labels = ln.ULabel.filter(name__icontains = "label").all()
|
30
|
+
>>> ln.ULabel(name="ULabel1").save()
|
31
|
+
>>> label = ln.ULabel.get(name="ULabel1")
|
32
|
+
>>> label.parents.set(labels)
|
33
|
+
>>> manager = label.parents
|
34
|
+
>>> manager.df()
|
35
|
+
"""
|
36
|
+
|
37
|
+
def _track_run_input_manager(self):
|
38
|
+
if hasattr(self, "source_field_name") and hasattr(self, "target_field_name"):
|
39
|
+
if (
|
40
|
+
self.source_field_name == "collection"
|
41
|
+
and self.target_field_name == "artifact"
|
42
|
+
):
|
43
|
+
from lamindb.core._context import context
|
44
|
+
from lamindb.core._data import WARNING_RUN_TRANSFORM, _track_run_input
|
45
|
+
|
46
|
+
if (
|
47
|
+
context.run is None
|
48
|
+
and not settings.creation.artifact_silence_missing_run_warning
|
49
|
+
):
|
50
|
+
logger.warning(WARNING_RUN_TRANSFORM)
|
51
|
+
_track_run_input(self.instance)
|
52
|
+
|
53
|
+
def list(self, field: str | None = None):
|
54
|
+
"""Populate a list with the results.
|
55
|
+
|
56
|
+
Examples:
|
57
|
+
>>> ln.save(ln.ULabel.from_values(["ULabel1", "ULabel2", "ULabel3"], field="name"))
|
58
|
+
>>> labels = ln.ULabel.filter(name__icontains="label").all()
|
59
|
+
>>> ln.ULabel(name="ULabel1").save()
|
60
|
+
>>> label = ln.ULabel.get(name="ULabel1")
|
61
|
+
>>> label.parents.set(labels)
|
62
|
+
>>> label.parents.list()
|
63
|
+
>>> label.parents.list("name")
|
64
|
+
['ULabel1', 'ULabel2', 'ULabel3']
|
65
|
+
"""
|
66
|
+
self._track_run_input_manager()
|
67
|
+
if field is None:
|
68
|
+
return list(self.all())
|
69
|
+
else:
|
70
|
+
return list(self.values_list(field, flat=True))
|
71
|
+
|
72
|
+
def df(self, **kwargs):
|
73
|
+
"""Convert to DataFrame.
|
74
|
+
|
75
|
+
For `**kwargs`, see :meth:`lamindb.core.QuerySet.df`.
|
76
|
+
"""
|
77
|
+
return self.all().df(**kwargs)
|
78
|
+
|
79
|
+
def all(self):
|
80
|
+
"""Return QuerySet of all.
|
81
|
+
|
82
|
+
For `**kwargs`, see :meth:`lamindb.core.QuerySet.df`.
|
83
|
+
"""
|
84
|
+
self._track_run_input_manager()
|
85
|
+
return self._all_base_class()
|
86
|
+
|
87
|
+
@doc_args(Record.search.__doc__)
|
88
|
+
def search(self, string: str, **kwargs):
|
89
|
+
"""{}""" # noqa: D415
|
90
|
+
from ._record import _search
|
91
|
+
|
92
|
+
return _search(cls=self.all(), string=string, **kwargs)
|
93
|
+
|
94
|
+
@doc_args(Record.lookup.__doc__)
|
95
|
+
def lookup(self, field: StrField | None = None, **kwargs) -> NamedTuple:
|
96
|
+
"""{}""" # noqa: D415
|
97
|
+
from ._record import _lookup
|
98
|
+
|
99
|
+
return _lookup(cls=self.all(), field=field, **kwargs)
|
100
|
+
|
101
|
+
def __getitem__(self, item: str):
|
102
|
+
try:
|
103
|
+
source_field_name = self.source_field_name
|
104
|
+
target_field_name = self.target_field_name
|
105
|
+
|
106
|
+
if (
|
107
|
+
source_field_name in {"artifact", "collection"}
|
108
|
+
and target_field_name == "feature_set"
|
109
|
+
):
|
110
|
+
return get_feature_set_by_slot_(host=self.instance).get(item)
|
111
|
+
|
112
|
+
except Exception: # pragma: no cover
|
113
|
+
return
|
114
|
+
|
115
|
+
|
116
|
+
models.Manager.list = QueryManager.list
|
117
|
+
models.Manager.df = QueryManager.df
|
118
|
+
models.Manager.search = QueryManager.search
|
119
|
+
models.Manager.lookup = QueryManager.lookup
|
120
|
+
models.Manager.__getitem__ = QueryManager.__getitem__
|
121
|
+
models.Manager._track_run_input_manager = QueryManager._track_run_input_manager
|
122
|
+
# the two lines below would be easy if we could actually inherit; like this,
|
123
|
+
# they're suboptimal
|
124
|
+
models.Manager._all_base_class = models.Manager.all
|
125
|
+
models.Manager.all = QueryManager.all
|