lamindb 1.5.3__py3-none-any.whl → 1.6.0__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.
Files changed (66) hide show
  1. lamindb/__init__.py +25 -6
  2. lamindb/_finish.py +5 -5
  3. lamindb/_tracked.py +1 -1
  4. lamindb/_view.py +4 -4
  5. lamindb/core/_context.py +32 -6
  6. lamindb/core/_settings.py +1 -1
  7. lamindb/core/datasets/mini_immuno.py +8 -0
  8. lamindb/core/loaders.py +1 -1
  9. lamindb/core/storage/_anndata_accessor.py +9 -9
  10. lamindb/core/storage/_valid_suffixes.py +1 -0
  11. lamindb/core/storage/_zarr.py +32 -107
  12. lamindb/curators/__init__.py +19 -2
  13. lamindb/curators/_cellxgene_schemas/__init__.py +3 -3
  14. lamindb/curators/_legacy.py +15 -19
  15. lamindb/curators/core.py +247 -80
  16. lamindb/errors.py +2 -2
  17. lamindb/migrations/0069_squashed.py +8 -8
  18. lamindb/migrations/0071_lamindbv1_migrate_schema.py +3 -3
  19. lamindb/migrations/0073_merge_ourprojects.py +7 -7
  20. lamindb/migrations/0075_lamindbv1_part5.py +1 -1
  21. lamindb/migrations/0077_lamindbv1_part6b.py +3 -3
  22. lamindb/migrations/0080_polish_lamindbv1.py +2 -2
  23. lamindb/migrations/0088_schema_components.py +1 -1
  24. lamindb/migrations/0090_runproject_project_runs.py +2 -2
  25. lamindb/migrations/0091_alter_featurevalue_options_alter_space_options_and_more.py +1 -1
  26. lamindb/migrations/0094_writeloglock_writelogmigrationstate_and_more.py +84 -0
  27. lamindb/migrations/0095_remove_rundata_flextable.py +155 -0
  28. lamindb/migrations/0096_remove_artifact__param_values_and_more.py +266 -0
  29. lamindb/migrations/0097_remove_schemaparam_param_remove_paramvalue_param_and_more.py +27 -0
  30. lamindb/migrations/0098_alter_feature_type_alter_project_type_and_more.py +656 -0
  31. lamindb/migrations/0099_alter_writelog_seqno.py +22 -0
  32. lamindb/migrations/0100_branch_alter_artifact__branch_code_and_more.py +102 -0
  33. lamindb/migrations/0101_alter_artifact_hash_alter_feature_name_and_more.py +444 -0
  34. lamindb/migrations/0102_remove_writelog_branch_code_and_more.py +72 -0
  35. lamindb/migrations/0103_remove_writelog_migration_state_and_more.py +46 -0
  36. lamindb/migrations/{0090_squashed.py → 0103_squashed.py} +1013 -1009
  37. lamindb/models/__init__.py +35 -18
  38. lamindb/models/_describe.py +4 -4
  39. lamindb/models/_django.py +38 -4
  40. lamindb/models/_feature_manager.py +66 -123
  41. lamindb/models/_from_values.py +13 -13
  42. lamindb/models/_label_manager.py +8 -6
  43. lamindb/models/_relations.py +7 -7
  44. lamindb/models/artifact.py +166 -156
  45. lamindb/models/can_curate.py +25 -25
  46. lamindb/models/collection.py +48 -18
  47. lamindb/models/core.py +3 -3
  48. lamindb/models/feature.py +88 -60
  49. lamindb/models/has_parents.py +17 -17
  50. lamindb/models/project.py +52 -24
  51. lamindb/models/query_manager.py +5 -5
  52. lamindb/models/query_set.py +61 -37
  53. lamindb/models/record.py +158 -1583
  54. lamindb/models/run.py +39 -176
  55. lamindb/models/save.py +6 -6
  56. lamindb/models/schema.py +32 -43
  57. lamindb/models/sqlrecord.py +1743 -0
  58. lamindb/models/transform.py +17 -33
  59. lamindb/models/ulabel.py +21 -15
  60. {lamindb-1.5.3.dist-info → lamindb-1.6.0.dist-info}/METADATA +7 -11
  61. lamindb-1.6.0.dist-info/RECORD +118 -0
  62. lamindb/core/storage/_anndata_sizes.py +0 -41
  63. lamindb/models/flextable.py +0 -163
  64. lamindb-1.5.3.dist-info/RECORD +0 -109
  65. {lamindb-1.5.3.dist-info → lamindb-1.6.0.dist-info}/LICENSE +0 -0
  66. {lamindb-1.5.3.dist-info → lamindb-1.6.0.dist-info}/WHEEL +0 -0
@@ -3,23 +3,21 @@
3
3
  .. autosummary::
4
4
  :toctree: .
5
5
 
6
- BasicRecord
7
- Record
6
+ BaseSQLRecord
7
+ SQLRecord
8
8
  Registry
9
9
  BasicQuerySet
10
10
  QuerySet
11
11
  ArtifactSet
12
12
  QueryManager
13
- RecordList
13
+ SQLRecordList
14
14
  FeatureManager
15
- ParamManager
16
15
  LabelManager
17
16
  IsVersioned
18
17
  CanCurate
19
18
  HasParents
20
19
  TracksRun
21
20
  TracksUpdates
22
- ParamValue
23
21
  FeatureValue
24
22
  InspectResult
25
23
  ValidateFields
@@ -31,19 +29,21 @@
31
29
  from lamin_utils._inspect import InspectResult
32
30
  from ._is_versioned import IsVersioned
33
31
  from .can_curate import CanCurate
34
- from .record import (
35
- BasicRecord,
36
- Record,
32
+ from .sqlrecord import (
33
+ BaseSQLRecord,
34
+ SQLRecord,
37
35
  Registry,
38
36
  Space,
37
+ Branch,
38
+ Migration,
39
39
  ValidateFields,
40
40
  format_field_value,
41
41
  record_repr,
42
- LinkORM,
42
+ IsLink,
43
43
  )
44
44
  from .core import Storage
45
45
  from .transform import Transform
46
- from .run import Run, TracksRun, TracksUpdates, current_run, Param, ParamValue, User
46
+ from .run import Run, TracksRun, TracksUpdates, current_run, User
47
47
  from .feature import Feature, FeatureValue
48
48
  from .schema import Schema
49
49
  from .ulabel import ULabel
@@ -51,13 +51,11 @@ from .ulabel import ULabel
51
51
  # should come last as it needs everything else
52
52
  from .artifact import Artifact
53
53
  from ._feature_manager import FeatureManager
54
- from .run import ParamManager
55
54
  from ._label_manager import LabelManager
56
55
  from .collection import Collection, CollectionArtifact
57
56
  from .project import Person, Project, Reference
58
- from .flextable import FlexTable, RunData
59
57
  from .query_manager import QueryManager
60
- from .query_set import BasicQuerySet, QuerySet, RecordList
58
+ from .query_set import BasicQuerySet, QuerySet, SQLRecordList
61
59
  from .artifact_set import ArtifactSet
62
60
  from .has_parents import HasParents
63
61
  from datetime import datetime as _datetime
@@ -65,8 +63,7 @@ from datetime import datetime as _datetime
65
63
  FeatureSet = Schema # backward compat
66
64
 
67
65
  # link models
68
- from .artifact import ArtifactFeatureValue, ArtifactParamValue
69
- from .flextable import FlexTableData
66
+ from .artifact import ArtifactFeatureValue
70
67
  from .project import (
71
68
  ArtifactProject,
72
69
  TransformProject,
@@ -76,14 +73,34 @@ from .project import (
76
73
  SchemaProject,
77
74
  ArtifactReference,
78
75
  CollectionReference,
76
+ SheetProject,
77
+ RunProject,
78
+ RecordProject,
79
+ PersonProject,
79
80
  )
80
- from .record import Migration
81
- from .run import RunParamValue
81
+ from .run import RunFeatureValue
82
82
  from .schema import (
83
83
  SchemaFeature,
84
- SchemaParam,
85
84
  ArtifactSchema,
86
85
  SchemaComponent,
87
86
  SchemaOptionals,
88
87
  )
89
88
  from .ulabel import ArtifactULabel, TransformULabel, RunULabel, CollectionULabel
89
+
90
+ from .record import (
91
+ Record,
92
+ Sheet,
93
+ RecordJson,
94
+ RecordRecord,
95
+ RecordULabel,
96
+ RecordRun,
97
+ RecordArtifact,
98
+ )
99
+
100
+
101
+ LinkORM = IsLink # backward compat
102
+ ParamValue = FeatureValue # backward compat
103
+ ArtifactParamValue = ArtifactFeatureValue # backward compat
104
+ RunParamValue = RunFeatureValue # backward compat
105
+ Param = Feature # backward compat
106
+ BasicRecord = BaseSQLRecord # backward compat
@@ -89,10 +89,10 @@ def describe_header(self: Artifact | Collection | Run) -> Tree:
89
89
  logger.warning(
90
90
  f"This is not the latest version of the {self.__class__.__name__}."
91
91
  )
92
- if hasattr(self, "_branch_code"):
93
- if self._branch_code == 0: # type: ignore
94
- logger.warning("This artifact is hidden.")
95
- elif self._branch_code == -1: # type: ignore
92
+ if hasattr(self, "branch_id"):
93
+ if self.branch_id == 0: # type: ignore
94
+ logger.warning("This artifact is archived.")
95
+ elif self.branch_id == -1: # type: ignore
96
96
  logger.warning("This artifact is in the trash.")
97
97
  # initialize tree
98
98
  suffix = self.suffix if hasattr(self, "suffix") and self.suffix else ""
lamindb/models/_django.py CHANGED
@@ -15,7 +15,31 @@ from .schema import Schema
15
15
 
16
16
  if TYPE_CHECKING:
17
17
  from .artifact import Artifact
18
- from .record import Record
18
+ from .sqlrecord import SQLRecord
19
+
20
+
21
+ def patch_many_to_many_descriptor() -> None:
22
+ """Patches Django's `ManyToManyDescriptor.__get__` method to suggest better errors when saving relationships of an unsaved model.
23
+
24
+ Before this patch: Cryptic errors are raised when relationships of an unsaved
25
+ record are attempted to be modified.
26
+
27
+ After this patch: Attempts to access M2M relationships on unsaved objects
28
+ will raise ValueError, suggesting explicit .save() of the record to be modified
29
+ before relationship creation.
30
+ """
31
+ from django.db.models.fields.related_descriptors import ManyToManyDescriptor
32
+
33
+ original_get = ManyToManyDescriptor.__get__
34
+
35
+ def patched_get(self, instance, cls=None):
36
+ if instance is not None and instance.pk is None:
37
+ raise ValueError(
38
+ f"You are trying to access the many-to-many relationships of an unsaved {instance.__class__.__name__} object. Please save it first using '.save()'."
39
+ )
40
+ return original_get(self, instance, cls)
41
+
42
+ ManyToManyDescriptor.__get__ = patched_get
19
43
 
20
44
 
21
45
  def get_related_model(model, field_name):
@@ -35,7 +59,7 @@ def get_related_model(model, field_name):
35
59
 
36
60
 
37
61
  def get_artifact_with_related(
38
- artifact: Record,
62
+ artifact: SQLRecord,
39
63
  include_fk: bool = False,
40
64
  include_m2m: bool = False,
41
65
  include_feature_link: bool = False,
@@ -51,7 +75,9 @@ def get_artifact_with_related(
51
75
  foreign_key_fields = [
52
76
  f.name
53
77
  for f in model._meta.fields
54
- if f.is_relation and f.related_model.__get_module_name__() in schema_modules
78
+ if f.is_relation
79
+ and f.related_model.__get_module_name__() in schema_modules
80
+ and f.name != "branch" # TODO: re-enable at some point
55
81
  ]
56
82
 
57
83
  m2m_relations = (
@@ -89,7 +115,10 @@ def get_artifact_with_related(
89
115
 
90
116
  for link in link_tables:
91
117
  link_model = getattr(model, link).rel.related_model
92
- if not hasattr(link_model, "feature"):
118
+ if (
119
+ not hasattr(link_model, "feature")
120
+ or link_model.__name__ == "RecordArtifact"
121
+ ):
93
122
  continue
94
123
  label_field = link.removeprefix("links_").replace("_", "")
95
124
  annotations[f"linkfield_{link}"] = Subquery(
@@ -198,6 +227,8 @@ def get_schema_m2m_relations(artifact: Artifact, slot_schema: dict, limit: int =
198
227
  name_field = get_name_field(related_model)
199
228
 
200
229
  # Get the correct field names for the through table
230
+ if not hasattr(getattr(Schema, name), "through"):
231
+ continue
201
232
  through_model = getattr(Schema, name).through
202
233
 
203
234
  # Subquery to get limited related records
@@ -238,3 +269,6 @@ def get_schema_m2m_relations(artifact: Artifact, slot_schema: dict, limit: int =
238
269
  )
239
270
 
240
271
  return result
272
+
273
+
274
+ patch_many_to_many_descriptor()