lamindb 0.77.3__py3-none-any.whl → 1.0rc1__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 +39 -32
- lamindb/_artifact.py +95 -64
- lamindb/_can_curate.py +13 -6
- lamindb/_collection.py +51 -49
- lamindb/_feature.py +9 -9
- lamindb/_finish.py +92 -79
- lamindb/_from_values.py +13 -10
- lamindb/_is_versioned.py +2 -1
- lamindb/_parents.py +23 -16
- lamindb/_query_manager.py +3 -3
- lamindb/_query_set.py +85 -18
- lamindb/_record.py +114 -41
- lamindb/_run.py +3 -3
- lamindb/_save.py +5 -6
- lamindb/{_feature_set.py → _schema.py} +34 -31
- lamindb/_storage.py +2 -1
- lamindb/_transform.py +51 -23
- lamindb/_ulabel.py +17 -8
- lamindb/_view.py +13 -13
- lamindb/base/__init__.py +24 -0
- lamindb/base/fields.py +281 -0
- lamindb/base/ids.py +103 -0
- lamindb/base/types.py +51 -0
- lamindb/base/users.py +30 -0
- lamindb/base/validation.py +67 -0
- lamindb/core/__init__.py +18 -15
- lamindb/core/_context.py +295 -224
- lamindb/core/_data.py +44 -49
- lamindb/core/_describe.py +41 -31
- lamindb/core/_django.py +29 -27
- lamindb/core/_feature_manager.py +130 -129
- lamindb/core/_label_manager.py +7 -8
- lamindb/core/_mapped_collection.py +17 -14
- lamindb/core/_settings.py +1 -12
- lamindb/core/_sync_git.py +56 -9
- lamindb/core/_track_environment.py +1 -1
- lamindb/core/datasets/_core.py +5 -6
- lamindb/core/exceptions.py +0 -7
- lamindb/core/fields.py +1 -1
- lamindb/core/loaders.py +0 -1
- lamindb/core/{schema.py → relations.py} +22 -19
- lamindb/core/storage/_anndata_accessor.py +1 -2
- lamindb/core/storage/_backed_access.py +2 -1
- lamindb/core/storage/_tiledbsoma.py +38 -13
- lamindb/core/storage/objects.py +1 -1
- lamindb/core/storage/paths.py +13 -8
- lamindb/core/subsettings/__init__.py +0 -2
- lamindb/core/types.py +2 -23
- lamindb/core/versioning.py +11 -7
- lamindb/{_curate.py → curators/__init__.py} +122 -23
- lamindb/curators/_spatial.py +528 -0
- lamindb/integrations/_vitessce.py +1 -3
- lamindb/migrations/0052_squashed.py +1261 -0
- lamindb/migrations/0053_alter_featureset_hash_alter_paramvalue_created_by_and_more.py +57 -0
- lamindb/migrations/0054_alter_feature_previous_runs_and_more.py +35 -0
- lamindb/migrations/0055_artifact_type_artifactparamvalue_and_more.py +61 -0
- lamindb/migrations/0056_rename_ulabel_ref_is_name_artifactulabel_label_ref_is_name_and_more.py +22 -0
- lamindb/migrations/0057_link_models_latest_report_and_others.py +356 -0
- lamindb/migrations/0058_artifact__actions_collection__actions.py +22 -0
- lamindb/migrations/0059_alter_artifact__accessor_alter_artifact__hash_type_and_more.py +31 -0
- lamindb/migrations/0060_alter_artifact__actions.py +22 -0
- lamindb/migrations/0061_alter_collection_meta_artifact_alter_run_environment_and_more.py +45 -0
- lamindb/migrations/0062_add_is_latest_field.py +32 -0
- lamindb/migrations/0063_populate_latest_field.py +45 -0
- lamindb/migrations/0064_alter_artifact_version_alter_collection_version_and_more.py +33 -0
- lamindb/migrations/0065_remove_collection_feature_sets_and_more.py +22 -0
- lamindb/migrations/0066_alter_artifact__feature_values_and_more.py +352 -0
- lamindb/migrations/0067_alter_featurevalue_unique_together_and_more.py +20 -0
- lamindb/migrations/0068_alter_artifactulabel_unique_together_and_more.py +20 -0
- lamindb/migrations/0069_alter_artifact__accessor_alter_artifact__hash_type_and_more.py +1294 -0
- lamindb/migrations/0069_squashed.py +1770 -0
- lamindb/migrations/0070_lamindbv1_migrate_data.py +78 -0
- lamindb/migrations/0071_lamindbv1_migrate_schema.py +741 -0
- lamindb/migrations/0072_remove_user__branch_code_remove_user_aux_and_more.py +148 -0
- lamindb/migrations/0073_merge_ourprojects.py +945 -0
- lamindb/migrations/0074_lamindbv1_part4.py +374 -0
- lamindb/migrations/0075_lamindbv1_part5.py +276 -0
- lamindb/migrations/0076_lamindbv1_part6.py +621 -0
- lamindb/migrations/0077_lamindbv1_part6b.py +228 -0
- lamindb/migrations/0078_lamindbv1_part6c.py +468 -0
- lamindb/migrations/0079_alter_rundata_value_json_and_more.py +36 -0
- lamindb/migrations/__init__.py +0 -0
- lamindb/models.py +4064 -0
- {lamindb-0.77.3.dist-info → lamindb-1.0rc1.dist-info}/METADATA +13 -19
- lamindb-1.0rc1.dist-info/RECORD +100 -0
- {lamindb-0.77.3.dist-info → lamindb-1.0rc1.dist-info}/WHEEL +1 -1
- lamindb/core/subsettings/_transform_settings.py +0 -21
- lamindb-0.77.3.dist-info/RECORD +0 -63
- {lamindb-0.77.3.dist-info → lamindb-1.0rc1.dist-info}/LICENSE +0 -0
lamindb/_run.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
|
-
from
|
3
|
+
from lamindb.models import ParamManager, Run, Transform
|
4
4
|
|
5
5
|
|
6
6
|
def __init__(run: Run, *args, **kwargs):
|
@@ -18,7 +18,7 @@ def __init__(run: Run, *args, **kwargs):
|
|
18
18
|
reference_type: str | None = (
|
19
19
|
kwargs.pop("reference_type") if "reference_type" in kwargs else None
|
20
20
|
)
|
21
|
-
|
21
|
+
initiated_by_run: Run | None = kwargs.pop("initiated_by_run", None)
|
22
22
|
if transform is None:
|
23
23
|
raise TypeError("Pass transform parameter")
|
24
24
|
if transform._state.adding:
|
@@ -27,7 +27,7 @@ def __init__(run: Run, *args, **kwargs):
|
|
27
27
|
super(Run, run).__init__(
|
28
28
|
transform=transform,
|
29
29
|
reference=reference,
|
30
|
-
|
30
|
+
initiated_by_run=initiated_by_run,
|
31
31
|
reference_type=reference_type,
|
32
32
|
)
|
33
33
|
|
lamindb/_save.py
CHANGED
@@ -5,15 +5,14 @@ import shutil
|
|
5
5
|
import traceback
|
6
6
|
from collections import defaultdict
|
7
7
|
from datetime import datetime
|
8
|
-
from
|
9
|
-
from typing import TYPE_CHECKING, overload
|
8
|
+
from typing import TYPE_CHECKING
|
10
9
|
|
11
|
-
import
|
12
|
-
from django.db import IntegrityError, transaction
|
10
|
+
from django.db import transaction
|
13
11
|
from django.utils.functional import partition
|
14
12
|
from lamin_utils import logger
|
15
13
|
from lamindb_setup.core.upath import LocalPathClasses
|
16
|
-
|
14
|
+
|
15
|
+
from lamindb.models import Artifact, Record
|
17
16
|
|
18
17
|
from .core._settings import settings
|
19
18
|
from .core.storage.paths import (
|
@@ -64,7 +63,7 @@ def save(records: Iterable[Record], ignore_conflicts: bool | None = False) -> No
|
|
64
63
|
Update a single existing record:
|
65
64
|
|
66
65
|
>>> transform = ln.Transform.get("0Cb86EZj")
|
67
|
-
>>> transform.
|
66
|
+
>>> transform.description = "New description"
|
68
67
|
>>> transform.save()
|
69
68
|
|
70
69
|
"""
|
@@ -7,14 +7,16 @@ import numpy as np
|
|
7
7
|
from lamin_utils import logger
|
8
8
|
from lamindb_setup.core._docs import doc_args
|
9
9
|
from lamindb_setup.core.hashing import hash_set
|
10
|
-
|
11
|
-
from
|
10
|
+
|
11
|
+
from lamindb.base import ids
|
12
|
+
from lamindb.base.types import FieldAttr, ListLike
|
13
|
+
from lamindb.models import Feature, Record, Schema
|
12
14
|
|
13
15
|
from ._feature import convert_pandas_dtype_to_lamin_dtype
|
14
16
|
from ._record import init_self_from_db
|
15
17
|
from ._utils import attach_func_to_class_method
|
16
18
|
from .core.exceptions import ValidationError
|
17
|
-
from .core.
|
19
|
+
from .core.relations import (
|
18
20
|
dict_related_model_to_related_name,
|
19
21
|
get_related_name,
|
20
22
|
)
|
@@ -47,7 +49,7 @@ def validate_features(features: list[Record]) -> Record:
|
|
47
49
|
)
|
48
50
|
feature_types = {feature.__class__ for feature in features}
|
49
51
|
if len(feature_types) > 1:
|
50
|
-
raise TypeError("
|
52
|
+
raise TypeError("schema can only contain a single type")
|
51
53
|
for feature in features:
|
52
54
|
if feature._state.adding:
|
53
55
|
raise ValueError("Can only construct feature sets from validated features")
|
@@ -56,7 +58,7 @@ def validate_features(features: list[Record]) -> Record:
|
|
56
58
|
|
57
59
|
def __init__(self, *args, **kwargs):
|
58
60
|
if len(args) == len(self._meta.concrete_fields):
|
59
|
-
super(
|
61
|
+
super(Schema, self).__init__(*args, **kwargs)
|
60
62
|
return None
|
61
63
|
# now we proceed with the user-facing constructor
|
62
64
|
if len(args) > 1:
|
@@ -72,29 +74,29 @@ def __init__(self, *args, **kwargs):
|
|
72
74
|
dtype = None if features_registry == Feature else NUMBER_TYPE
|
73
75
|
n_features = len(features)
|
74
76
|
features_hash = hash_set({feature.uid for feature in features})
|
75
|
-
|
76
|
-
if
|
77
|
-
logger.debug(f"loaded: {
|
78
|
-
init_self_from_db(self,
|
77
|
+
schema = Schema.filter(hash=features_hash).one_or_none()
|
78
|
+
if schema is not None:
|
79
|
+
logger.debug(f"loaded: {schema}")
|
80
|
+
init_self_from_db(self, schema)
|
79
81
|
return None
|
80
82
|
else:
|
81
83
|
hash = features_hash
|
82
84
|
self._features = (get_related_name(features_registry), features)
|
83
85
|
|
84
|
-
super(
|
86
|
+
super(Schema, self).__init__(
|
85
87
|
uid=ids.base62_20(),
|
86
88
|
name=name,
|
87
89
|
dtype=get_type_str(dtype),
|
88
90
|
n=n_features,
|
89
|
-
registry=features_registry.
|
91
|
+
registry=features_registry.__get_name_with_module__(),
|
90
92
|
hash=hash,
|
91
93
|
)
|
92
94
|
|
93
95
|
|
94
|
-
@doc_args(
|
95
|
-
def save(self, *args, **kwargs) ->
|
96
|
+
@doc_args(Schema.save.__doc__)
|
97
|
+
def save(self, *args, **kwargs) -> Schema:
|
96
98
|
"""{}""" # noqa: D415
|
97
|
-
super(
|
99
|
+
super(Schema, self).save(*args, **kwargs)
|
98
100
|
if hasattr(self, "_features"):
|
99
101
|
related_name, records = self._features
|
100
102
|
getattr(self, related_name).set(records)
|
@@ -110,7 +112,7 @@ def get_type_str(dtype: str | None) -> str | None:
|
|
110
112
|
|
111
113
|
|
112
114
|
@classmethod # type:ignore
|
113
|
-
@doc_args(
|
115
|
+
@doc_args(Schema.from_values.__doc__)
|
114
116
|
def from_values(
|
115
117
|
cls,
|
116
118
|
values: ListLike,
|
@@ -121,7 +123,7 @@ def from_values(
|
|
121
123
|
organism: Record | str | None = None,
|
122
124
|
source: Record | None = None,
|
123
125
|
raise_validation_error: bool = True,
|
124
|
-
) ->
|
126
|
+
) -> Schema:
|
125
127
|
"""{}""" # noqa: D415
|
126
128
|
if not isinstance(field, FieldAttr):
|
127
129
|
raise TypeError("Argument `field` must be a Record field, e.g., `Feature.name`")
|
@@ -152,16 +154,16 @@ def from_values(
|
|
152
154
|
organism=organism,
|
153
155
|
source=source,
|
154
156
|
)
|
155
|
-
|
157
|
+
schema = Schema(
|
156
158
|
features=validated_features,
|
157
159
|
name=name,
|
158
160
|
dtype=get_type_str(type),
|
159
161
|
)
|
160
|
-
return
|
162
|
+
return schema
|
161
163
|
|
162
164
|
|
163
165
|
@classmethod # type:ignore
|
164
|
-
@doc_args(
|
166
|
+
@doc_args(Schema.from_df.__doc__)
|
165
167
|
def from_df(
|
166
168
|
cls,
|
167
169
|
df: pd.DataFrame,
|
@@ -170,7 +172,7 @@ def from_df(
|
|
170
172
|
mute: bool = False,
|
171
173
|
organism: Record | str | None = None,
|
172
174
|
source: Record | None = None,
|
173
|
-
) ->
|
175
|
+
) -> Schema | None:
|
174
176
|
"""{}""" # noqa: D415
|
175
177
|
registry = field.field.model
|
176
178
|
validated = registry.validate(df.columns, field=field, mute=mute, organism=organism)
|
@@ -182,7 +184,7 @@ def from_df(
|
|
182
184
|
validated_features = Feature.from_values(
|
183
185
|
df.columns, field=field, organism=organism
|
184
186
|
)
|
185
|
-
|
187
|
+
schema = Schema(validated_features, name=name, dtype=None)
|
186
188
|
else:
|
187
189
|
dtypes = [col.dtype for (_, col) in df.loc[:, validated].items()]
|
188
190
|
if len(set(dtypes)) != 1:
|
@@ -194,16 +196,16 @@ def from_df(
|
|
194
196
|
organism=organism,
|
195
197
|
source=source,
|
196
198
|
)
|
197
|
-
|
199
|
+
schema = Schema(
|
198
200
|
features=validated_features,
|
199
201
|
name=name,
|
200
202
|
dtype=get_type_str(dtype),
|
201
203
|
)
|
202
|
-
return
|
204
|
+
return schema
|
203
205
|
|
204
206
|
|
205
207
|
@property # type: ignore
|
206
|
-
@doc_args(
|
208
|
+
@doc_args(Schema.members.__doc__)
|
207
209
|
def members(self) -> QuerySet:
|
208
210
|
"""{}""" # noqa: D415
|
209
211
|
if self._state.adding:
|
@@ -216,11 +218,11 @@ def members(self) -> QuerySet:
|
|
216
218
|
return self.__getattribute__(related_name).all()
|
217
219
|
|
218
220
|
|
219
|
-
def _get_related_name(self:
|
220
|
-
|
221
|
+
def _get_related_name(self: Schema) -> str:
|
222
|
+
_schemas_m2m_related_models = dict_related_model_to_related_name(
|
221
223
|
self, instance=self._state.db
|
222
224
|
)
|
223
|
-
related_name =
|
225
|
+
related_name = _schemas_m2m_related_models.get(self.itype)
|
224
226
|
return related_name
|
225
227
|
|
226
228
|
|
@@ -235,13 +237,14 @@ if ln_setup._TESTING:
|
|
235
237
|
from inspect import signature
|
236
238
|
|
237
239
|
SIGS = {
|
238
|
-
name: signature(getattr(
|
240
|
+
name: signature(getattr(Schema, name))
|
239
241
|
for name in METHOD_NAMES
|
240
242
|
if name != "__init__"
|
241
243
|
}
|
242
244
|
|
243
245
|
for name in METHOD_NAMES:
|
244
|
-
attach_func_to_class_method(name,
|
246
|
+
attach_func_to_class_method(name, Schema, globals())
|
245
247
|
|
246
|
-
|
247
|
-
|
248
|
+
Schema.members = members
|
249
|
+
Schema._get_related_name = _get_related_name
|
250
|
+
Schema.feature_sets = Schema._artifacts_m2m # backward compat
|
lamindb/_storage.py
CHANGED
lamindb/_transform.py
CHANGED
@@ -1,26 +1,31 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
|
+
import warnings
|
3
4
|
from typing import TYPE_CHECKING
|
4
5
|
|
5
6
|
from lamin_utils import logger
|
6
7
|
from lamindb_setup.core._docs import doc_args
|
7
|
-
|
8
|
+
|
9
|
+
from lamindb.models import Run, Transform
|
8
10
|
|
9
11
|
from ._parents import _view_parents
|
10
12
|
from ._run import delete_run_artifacts
|
13
|
+
from .core._settings import settings
|
11
14
|
from .core.exceptions import InconsistentKey
|
12
15
|
from .core.versioning import message_update_key_in_version_family, process_revises
|
13
16
|
|
14
17
|
if TYPE_CHECKING:
|
15
|
-
from
|
18
|
+
from lamindb.base.types import TransformType
|
16
19
|
|
17
20
|
|
18
21
|
def __init__(transform: Transform, *args, **kwargs):
|
19
22
|
if len(args) == len(transform._meta.concrete_fields):
|
20
23
|
super(Transform, transform).__init__(*args, **kwargs)
|
21
24
|
return None
|
22
|
-
name: str | None = kwargs.pop("name") if "name" in kwargs else None
|
23
25
|
key: str | None = kwargs.pop("key") if "key" in kwargs else None
|
26
|
+
description: str | None = (
|
27
|
+
kwargs.pop("description") if "description" in kwargs else None
|
28
|
+
)
|
24
29
|
revises: Transform | None = kwargs.pop("revises") if "revises" in kwargs else None
|
25
30
|
version: str | None = kwargs.pop("version") if "version" in kwargs else None
|
26
31
|
type: TransformType | None = kwargs.pop("type") if "type" in kwargs else "pipeline"
|
@@ -28,47 +33,77 @@ def __init__(transform: Transform, *args, **kwargs):
|
|
28
33
|
reference_type: str | None = (
|
29
34
|
kwargs.pop("reference_type") if "reference_type" in kwargs else None
|
30
35
|
)
|
31
|
-
|
32
|
-
|
33
|
-
|
36
|
+
using_key = (
|
37
|
+
kwargs.pop("using_key") if "using_key" in kwargs else settings._using_key
|
38
|
+
)
|
39
|
+
if "name" in kwargs:
|
40
|
+
if key is None:
|
41
|
+
key = kwargs.pop("name")
|
42
|
+
warnings.warn(
|
43
|
+
f"`name` will be removed soon, please pass '{key}' to `key` instead",
|
44
|
+
FutureWarning,
|
45
|
+
stacklevel=2,
|
46
|
+
)
|
47
|
+
else:
|
48
|
+
# description wasn't exist, so no check necessary
|
49
|
+
description = kwargs.pop("name")
|
50
|
+
warnings.warn(
|
51
|
+
f"`name` will be removed soon, please pass '{description}' to `description` instead",
|
52
|
+
FutureWarning,
|
53
|
+
stacklevel=2,
|
54
|
+
)
|
34
55
|
# below is internal use that we'll hopefully be able to eliminate
|
35
56
|
uid: str | None = kwargs.pop("uid") if "uid" in kwargs else None
|
36
57
|
if not len(kwargs) == 0:
|
37
58
|
raise ValueError(
|
38
|
-
"Only
|
59
|
+
"Only key, description, version, type, revises, reference, "
|
39
60
|
f"reference_type can be passed, but you passed: {kwargs}"
|
40
61
|
)
|
41
62
|
if revises is None:
|
42
63
|
# need to check uid before checking key
|
43
64
|
if uid is not None:
|
44
65
|
revises = (
|
45
|
-
Transform.
|
66
|
+
Transform.objects.using(using_key)
|
67
|
+
.filter(uid__startswith=uid[:-4], is_latest=True)
|
46
68
|
.order_by("-created_at")
|
47
69
|
.first()
|
48
70
|
)
|
49
71
|
elif key is not None:
|
50
|
-
|
51
|
-
Transform.
|
72
|
+
candidate_for_revises = (
|
73
|
+
Transform.objects.using(using_key)
|
74
|
+
.filter(key=key, is_latest=True)
|
52
75
|
.order_by("-created_at")
|
53
76
|
.first()
|
54
77
|
)
|
78
|
+
if candidate_for_revises is not None:
|
79
|
+
revises = candidate_for_revises
|
80
|
+
if candidate_for_revises.source_code is None:
|
81
|
+
# no source code was yet saved, return the same transform
|
82
|
+
logger.important(
|
83
|
+
"no source code was yet saved, returning existing transform with same key"
|
84
|
+
)
|
85
|
+
uid = revises.uid
|
55
86
|
if revises is not None and uid is not None and uid == revises.uid:
|
56
87
|
from ._record import init_self_from_db, update_attributes
|
57
88
|
|
89
|
+
if revises.key != key:
|
90
|
+
logger.warning("ignoring inconsistent key")
|
58
91
|
init_self_from_db(transform, revises)
|
59
|
-
update_attributes(transform, {"
|
92
|
+
update_attributes(transform, {"description": description})
|
60
93
|
return None
|
61
94
|
if revises is not None and key is not None and revises.key != key:
|
62
95
|
note = message_update_key_in_version_family(
|
63
96
|
suid=revises.stem_uid,
|
64
97
|
existing_key=revises.key,
|
65
98
|
new_key=key,
|
66
|
-
registry="
|
99
|
+
registry="Transform",
|
67
100
|
)
|
68
101
|
raise InconsistentKey(
|
69
|
-
f"`key` is {key}, but `revises.key` is '{revises.key}'\n\nEither do *not* pass `key`.\n\n{note}"
|
102
|
+
f"`key` is '{key}', but `revises.key` is '{revises.key}'\n\nEither do *not* pass `key`.\n\n{note}"
|
70
103
|
)
|
71
|
-
new_uid, version,
|
104
|
+
new_uid, version, key, description, revises = process_revises(
|
105
|
+
revises, version, key, description, Transform
|
106
|
+
)
|
72
107
|
# this is only because the user-facing constructor allows passing a uid
|
73
108
|
# most others don't
|
74
109
|
if uid is None:
|
@@ -78,7 +113,7 @@ def __init__(transform: Transform, *args, **kwargs):
|
|
78
113
|
has_consciously_provided_uid = True
|
79
114
|
super(Transform, transform).__init__(
|
80
115
|
uid=uid,
|
81
|
-
|
116
|
+
description=description,
|
82
117
|
key=key,
|
83
118
|
type=type,
|
84
119
|
version=version,
|
@@ -90,13 +125,6 @@ def __init__(transform: Transform, *args, **kwargs):
|
|
90
125
|
|
91
126
|
|
92
127
|
def delete(self) -> None:
|
93
|
-
_source_code_artifact = None
|
94
|
-
if self._source_code_artifact is not None:
|
95
|
-
_source_code_artifact = self._source_code_artifact
|
96
|
-
self._source_code_artifact = None
|
97
|
-
self.save()
|
98
|
-
if _source_code_artifact is not None:
|
99
|
-
_source_code_artifact.delete(permanent=True)
|
100
128
|
# query all runs and delete their artifacts
|
101
129
|
runs = Run.filter(transform=self)
|
102
130
|
for run in runs:
|
@@ -116,7 +144,7 @@ def latest_run(self) -> Run:
|
|
116
144
|
def view_lineage(self, with_successors: bool = False, distance: int = 5):
|
117
145
|
return _view_parents(
|
118
146
|
record=self,
|
119
|
-
field="
|
147
|
+
field="key",
|
120
148
|
with_children=with_successors,
|
121
149
|
distance=distance,
|
122
150
|
attr_name="predecessors",
|
lamindb/_ulabel.py
CHANGED
@@ -1,15 +1,11 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
|
-
from typing import TYPE_CHECKING
|
4
|
-
|
5
3
|
import lamindb_setup as ln_setup
|
6
|
-
from
|
7
|
-
from lnschema_core import ULabel
|
4
|
+
from lamin_utils import logger
|
8
5
|
|
9
|
-
from .
|
6
|
+
from lamindb.models import ULabel
|
10
7
|
|
11
|
-
|
12
|
-
from lnschema_core.types import ListLike
|
8
|
+
from ._utils import attach_func_to_class_method
|
13
9
|
|
14
10
|
|
15
11
|
def __init__(self, *args, **kwargs):
|
@@ -19,7 +15,9 @@ def __init__(self, *args, **kwargs):
|
|
19
15
|
# now we proceed with the user-facing constructor
|
20
16
|
if len(args) > 0:
|
21
17
|
raise ValueError("Only one non-keyword arg allowed")
|
22
|
-
name: str
|
18
|
+
name: str = kwargs.pop("name") if "name" in kwargs else None
|
19
|
+
type: str | None = kwargs.pop("type") if "type" in kwargs else None
|
20
|
+
is_type: str | None = kwargs.pop("is_type") if "is_type" in kwargs else None
|
23
21
|
description: str | None = (
|
24
22
|
kwargs.pop("description") if "description" in kwargs else None
|
25
23
|
)
|
@@ -31,8 +29,19 @@ def __init__(self, *args, **kwargs):
|
|
31
29
|
raise ValueError(
|
32
30
|
"Only name, description, reference, reference_type are valid keyword arguments"
|
33
31
|
)
|
32
|
+
if is_type:
|
33
|
+
if name.endswith("s"):
|
34
|
+
logger.warning(
|
35
|
+
"`name` ends with 's', in case you're naming with plural, consider the singular for a type name"
|
36
|
+
)
|
37
|
+
if name[0].islower():
|
38
|
+
logger.warning(
|
39
|
+
"`name` starts with lowercase, in case you're naming a type, consider starting with uppercase"
|
40
|
+
)
|
34
41
|
super(ULabel, self).__init__(
|
35
42
|
name=name,
|
43
|
+
type=type,
|
44
|
+
is_type=is_type,
|
36
45
|
description=description,
|
37
46
|
reference=reference,
|
38
47
|
reference_type=reference_type,
|
lamindb/_view.py
CHANGED
@@ -8,9 +8,9 @@ from typing import TYPE_CHECKING
|
|
8
8
|
from lamin_utils import colors, logger
|
9
9
|
from lamindb_setup import settings
|
10
10
|
from lamindb_setup._init_instance import get_schema_module_name
|
11
|
-
from lnschema_core import Feature, Record
|
12
11
|
|
13
12
|
from lamindb.core import FeatureValue, ParamValue
|
13
|
+
from lamindb.models import Feature, Record
|
14
14
|
|
15
15
|
from ._feature import convert_pandas_dtype_to_lamin_dtype
|
16
16
|
|
@@ -97,7 +97,7 @@ def display_df_with_descriptions(
|
|
97
97
|
def view(
|
98
98
|
df: pd.DataFrame | None = None,
|
99
99
|
limit: int = 7,
|
100
|
-
|
100
|
+
modules: str | None = None,
|
101
101
|
registries: list[str] | None = None,
|
102
102
|
) -> None:
|
103
103
|
"""View metadata.
|
@@ -105,8 +105,8 @@ def view(
|
|
105
105
|
Args:
|
106
106
|
df: A DataFrame to display.
|
107
107
|
limit: Display the latest `n` records
|
108
|
-
|
109
|
-
`None` and displays all
|
108
|
+
modules: schema module to view. Default's to
|
109
|
+
`None` and displays all registry modules.
|
110
110
|
registries: List of Record names. Defaults to
|
111
111
|
`None` and lists all registries.
|
112
112
|
|
@@ -128,13 +128,13 @@ def view(
|
|
128
128
|
else:
|
129
129
|
show = logger.print
|
130
130
|
|
131
|
-
if
|
132
|
-
|
131
|
+
if modules is not None:
|
132
|
+
module_names = [modules]
|
133
133
|
else:
|
134
|
-
|
134
|
+
module_names = ["core"] + list(settings.instance.modules)
|
135
135
|
|
136
|
-
for
|
137
|
-
schema_module = importlib.import_module(get_schema_module_name(
|
136
|
+
for module_name in module_names:
|
137
|
+
schema_module = importlib.import_module(get_schema_module_name(module_name))
|
138
138
|
# the below is necessary because a schema module might not have been
|
139
139
|
# explicitly accessed
|
140
140
|
importlib.reload(schema_module)
|
@@ -146,7 +146,7 @@ def view(
|
|
146
146
|
and issubclass(registry, Record)
|
147
147
|
and registry is not Record
|
148
148
|
}
|
149
|
-
if
|
149
|
+
if module_name == "core":
|
150
150
|
all_registries.update({FeatureValue, ParamValue})
|
151
151
|
if registries is not None:
|
152
152
|
filtered_registries = {
|
@@ -156,9 +156,9 @@ def view(
|
|
156
156
|
}
|
157
157
|
else:
|
158
158
|
filtered_registries = all_registries
|
159
|
-
if len(
|
160
|
-
section = f"* module: {colors.green(colors.bold(
|
161
|
-
section_no_color = f"* module: {
|
159
|
+
if len(module_names) > 1:
|
160
|
+
section = f"* module: {colors.green(colors.bold(module_name))} *"
|
161
|
+
section_no_color = f"* module: {module_name} *"
|
162
162
|
logger.print("*" * len(section_no_color))
|
163
163
|
logger.print(section)
|
164
164
|
logger.print("*" * len(section_no_color))
|
lamindb/base/__init__.py
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
"""Base library.
|
2
|
+
|
3
|
+
Is available also when no instance is connected.
|
4
|
+
|
5
|
+
Modules:
|
6
|
+
|
7
|
+
.. autosummary::
|
8
|
+
:toctree: .
|
9
|
+
|
10
|
+
types
|
11
|
+
|
12
|
+
Utils:
|
13
|
+
|
14
|
+
.. autosummary::
|
15
|
+
:toctree: .
|
16
|
+
|
17
|
+
doc_args
|
18
|
+
deprecated
|
19
|
+
|
20
|
+
"""
|
21
|
+
|
22
|
+
from lamindb_setup.core import deprecated, doc_args
|
23
|
+
|
24
|
+
from . import types
|