lamindb 0.77.2__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.
Files changed (89) hide show
  1. lamindb/__init__.py +39 -32
  2. lamindb/_artifact.py +95 -64
  3. lamindb/_can_curate.py +19 -10
  4. lamindb/_collection.py +51 -49
  5. lamindb/_feature.py +9 -9
  6. lamindb/_finish.py +99 -86
  7. lamindb/_from_values.py +20 -17
  8. lamindb/_is_versioned.py +2 -1
  9. lamindb/_parents.py +23 -16
  10. lamindb/_query_manager.py +3 -3
  11. lamindb/_query_set.py +85 -18
  12. lamindb/_record.py +121 -46
  13. lamindb/_run.py +3 -3
  14. lamindb/_save.py +14 -8
  15. lamindb/{_feature_set.py → _schema.py} +34 -31
  16. lamindb/_storage.py +2 -1
  17. lamindb/_transform.py +51 -23
  18. lamindb/_ulabel.py +17 -8
  19. lamindb/_view.py +15 -14
  20. lamindb/base/__init__.py +24 -0
  21. lamindb/base/fields.py +281 -0
  22. lamindb/base/ids.py +103 -0
  23. lamindb/base/types.py +51 -0
  24. lamindb/base/users.py +30 -0
  25. lamindb/base/validation.py +67 -0
  26. lamindb/core/__init__.py +19 -14
  27. lamindb/core/_context.py +297 -228
  28. lamindb/core/_data.py +44 -49
  29. lamindb/core/_describe.py +41 -31
  30. lamindb/core/_django.py +59 -44
  31. lamindb/core/_feature_manager.py +192 -168
  32. lamindb/core/_label_manager.py +22 -22
  33. lamindb/core/_mapped_collection.py +17 -14
  34. lamindb/core/_settings.py +1 -12
  35. lamindb/core/_sync_git.py +56 -9
  36. lamindb/core/_track_environment.py +1 -1
  37. lamindb/core/datasets/_core.py +5 -6
  38. lamindb/core/exceptions.py +0 -7
  39. lamindb/core/fields.py +1 -1
  40. lamindb/core/loaders.py +18 -2
  41. lamindb/core/{schema.py → relations.py} +22 -19
  42. lamindb/core/storage/_anndata_accessor.py +1 -2
  43. lamindb/core/storage/_backed_access.py +2 -1
  44. lamindb/core/storage/_tiledbsoma.py +40 -13
  45. lamindb/core/storage/objects.py +1 -1
  46. lamindb/core/storage/paths.py +13 -8
  47. lamindb/core/subsettings/__init__.py +0 -2
  48. lamindb/core/types.py +2 -23
  49. lamindb/core/versioning.py +11 -7
  50. lamindb/{_curate.py → curators/__init__.py} +700 -57
  51. lamindb/curators/_spatial.py +528 -0
  52. lamindb/integrations/_vitessce.py +1 -3
  53. lamindb/migrations/0052_squashed.py +1261 -0
  54. lamindb/migrations/0053_alter_featureset_hash_alter_paramvalue_created_by_and_more.py +57 -0
  55. lamindb/migrations/0054_alter_feature_previous_runs_and_more.py +35 -0
  56. lamindb/migrations/0055_artifact_type_artifactparamvalue_and_more.py +61 -0
  57. lamindb/migrations/0056_rename_ulabel_ref_is_name_artifactulabel_label_ref_is_name_and_more.py +22 -0
  58. lamindb/migrations/0057_link_models_latest_report_and_others.py +356 -0
  59. lamindb/migrations/0058_artifact__actions_collection__actions.py +22 -0
  60. lamindb/migrations/0059_alter_artifact__accessor_alter_artifact__hash_type_and_more.py +31 -0
  61. lamindb/migrations/0060_alter_artifact__actions.py +22 -0
  62. lamindb/migrations/0061_alter_collection_meta_artifact_alter_run_environment_and_more.py +45 -0
  63. lamindb/migrations/0062_add_is_latest_field.py +32 -0
  64. lamindb/migrations/0063_populate_latest_field.py +45 -0
  65. lamindb/migrations/0064_alter_artifact_version_alter_collection_version_and_more.py +33 -0
  66. lamindb/migrations/0065_remove_collection_feature_sets_and_more.py +22 -0
  67. lamindb/migrations/0066_alter_artifact__feature_values_and_more.py +352 -0
  68. lamindb/migrations/0067_alter_featurevalue_unique_together_and_more.py +20 -0
  69. lamindb/migrations/0068_alter_artifactulabel_unique_together_and_more.py +20 -0
  70. lamindb/migrations/0069_alter_artifact__accessor_alter_artifact__hash_type_and_more.py +1294 -0
  71. lamindb/migrations/0069_squashed.py +1770 -0
  72. lamindb/migrations/0070_lamindbv1_migrate_data.py +78 -0
  73. lamindb/migrations/0071_lamindbv1_migrate_schema.py +741 -0
  74. lamindb/migrations/0072_remove_user__branch_code_remove_user_aux_and_more.py +148 -0
  75. lamindb/migrations/0073_merge_ourprojects.py +945 -0
  76. lamindb/migrations/0074_lamindbv1_part4.py +374 -0
  77. lamindb/migrations/0075_lamindbv1_part5.py +276 -0
  78. lamindb/migrations/0076_lamindbv1_part6.py +621 -0
  79. lamindb/migrations/0077_lamindbv1_part6b.py +228 -0
  80. lamindb/migrations/0078_lamindbv1_part6c.py +468 -0
  81. lamindb/migrations/0079_alter_rundata_value_json_and_more.py +36 -0
  82. lamindb/migrations/__init__.py +0 -0
  83. lamindb/models.py +4064 -0
  84. {lamindb-0.77.2.dist-info → lamindb-1.0rc1.dist-info}/METADATA +15 -20
  85. lamindb-1.0rc1.dist-info/RECORD +100 -0
  86. {lamindb-0.77.2.dist-info → lamindb-1.0rc1.dist-info}/WHEEL +1 -1
  87. lamindb/core/subsettings/_transform_settings.py +0 -21
  88. lamindb-0.77.2.dist-info/RECORD +0 -63
  89. {lamindb-0.77.2.dist-info → lamindb-1.0rc1.dist-info}/LICENSE +0 -0
lamindb/base/types.py ADDED
@@ -0,0 +1,51 @@
1
+ """Types.
2
+
3
+ Central object types.
4
+
5
+ .. autosummary::
6
+ :toctree: .
7
+
8
+ ArtifactKind
9
+ TransformType
10
+ FeatureDtype
11
+
12
+ Basic types.
13
+
14
+ .. autosummary::
15
+ :toctree: .
16
+
17
+ UPathStr
18
+ StrField
19
+ ListLike
20
+ FieldAttr
21
+ """
22
+
23
+ from __future__ import annotations
24
+
25
+ from typing import Literal, Union
26
+
27
+ import numpy as np
28
+ import pandas as pd
29
+ from django.db.models.query_utils import DeferredAttribute as FieldAttr
30
+ from lamindb_setup.core.types import UPathStr # noqa: F401
31
+
32
+ # need to use Union because __future__.annotations doesn't do the job here <3.10
33
+ # typing.TypeAlias, >3.10 on but already deprecated
34
+ ListLike = Union[list[str], pd.Series, np.array]
35
+ StrField = Union[str, FieldAttr] # typing.TypeAlias
36
+
37
+ TransformType = Literal[
38
+ "pipeline", "notebook", "upload", "script", "function", "linker"
39
+ ]
40
+ ArtifactKind = Literal["dataset", "model"]
41
+ FeatureDtype = Literal[
42
+ "cat", # categorical variables
43
+ "num", # numerical variables
44
+ "str", # string variables
45
+ "int", # integer variables
46
+ "float", # float variables
47
+ "bool", # boolean variables
48
+ "date", # date variables
49
+ "datetime", # datetime variables
50
+ "object", # this is a pandas type, we're only using it for complicated types, not for strings
51
+ ]
lamindb/base/users.py ADDED
@@ -0,0 +1,30 @@
1
+ user_id_cache = {}
2
+
3
+
4
+ def current_user_id() -> int:
5
+ import lamindb_setup as ln_setup
6
+ from lamindb_setup import settings
7
+ from lamindb_setup._init_instance import register_user
8
+
9
+ from lamindb.models import User
10
+
11
+ def query_user_id():
12
+ if ln_setup.core.django.IS_MIGRATING:
13
+ return 1
14
+ else:
15
+ exc_attr = (
16
+ "DoesNotExist" if hasattr(User, "DoesNotExist") else "_DoesNotExist"
17
+ )
18
+ try:
19
+ user_id = User.objects.get(uid=settings.user.uid).id
20
+ except getattr(User, exc_attr):
21
+ register_user(settings.user)
22
+ user_id = User.objects.get(uid=settings.user.uid).id
23
+ return user_id
24
+
25
+ if settings._instance_exists:
26
+ if settings.instance.slug not in user_id_cache:
27
+ user_id_cache[settings.instance.slug] = query_user_id()
28
+ return user_id_cache[settings.instance.slug]
29
+ else:
30
+ return query_user_id()
@@ -0,0 +1,67 @@
1
+ from typing import TYPE_CHECKING, Literal, Union, get_args, get_origin, get_type_hints
2
+
3
+ from lamin_utils import colors
4
+
5
+ if TYPE_CHECKING:
6
+ from .models import Record
7
+
8
+
9
+ class FieldValidationError(SystemExit):
10
+ """Field validation error."""
11
+
12
+ pass
13
+
14
+
15
+ def validate_literal_fields(record: "Record", kwargs) -> None:
16
+ """Validate all Literal type fields in a record.
17
+
18
+ Args:
19
+ record: record being validated
20
+
21
+ Raises:
22
+ ValidationError: If any field value is not in its Literal's allowed values
23
+ """
24
+ # check is based on string to avoid circular imports
25
+ if record.__class__.__name__ == "Feature":
26
+ # the FeatureDtype is more complicated than a simple literal
27
+ # because it allows constructs like cat[ULabel] etc.
28
+ # the User model is used at startup and throws a datetime-related error otherwise
29
+ # simmilar for Storage & Source
30
+ return None
31
+ try:
32
+ type_hints = get_type_hints(record.__class__)
33
+ except TypeError:
34
+ # for 3.9, get_type_hints errors with | in type hints
35
+ return
36
+ errors = {}
37
+
38
+ for field_name, field_type in type_hints.items():
39
+ # Handle both plain Literal and Union/Optional Literal types
40
+ origin = get_origin(field_type)
41
+ if origin is Union:
42
+ # For Optional/Union types, find the Literal type if it exists
43
+ literal_type = next(
44
+ (t for t in get_args(field_type) if get_origin(t) is Literal), None
45
+ )
46
+ else:
47
+ # For plain types, check if it's a Literal
48
+ literal_type = field_type if origin is Literal else None
49
+
50
+ # Skip if no Literal type found
51
+ if literal_type is None:
52
+ continue
53
+
54
+ value = kwargs.get(field_name)
55
+ if value is not None:
56
+ valid_values = set(get_args(literal_type))
57
+ if value not in valid_values:
58
+ errors[field_name] = (
59
+ f"{field_name}: {colors.yellow(value)} is not a valid value"
60
+ f"\n → Valid values are: {colors.green(', '.join(sorted(valid_values)))}"
61
+ )
62
+
63
+ if errors:
64
+ message = "\n "
65
+ for _, error in errors.items():
66
+ message += error + "\n "
67
+ raise FieldValidationError(message)
lamindb/core/__init__.py CHANGED
@@ -5,10 +5,12 @@ Registries:
5
5
  .. autosummary::
6
6
  :toctree: .
7
7
 
8
+ BasicRecord
8
9
  Record
9
10
  Registry
10
11
  QuerySet
11
12
  QueryManager
13
+ Schema
12
14
  RecordList
13
15
  FeatureManager
14
16
  ParamManager
@@ -33,6 +35,7 @@ Curators:
33
35
  DataFrameCurator
34
36
  AnnDataCurator
35
37
  MuDataCurator
38
+ SOMACurator
36
39
  CurateLookup
37
40
 
38
41
  Settings & context:
@@ -58,7 +61,6 @@ Modules:
58
61
  loaders
59
62
  datasets
60
63
  storage
61
- types
62
64
  exceptions
63
65
  subsettings
64
66
  logger
@@ -67,7 +69,21 @@ Modules:
67
69
 
68
70
  from lamin_utils import logger
69
71
  from lamin_utils._inspect import InspectResult
70
- from lnschema_core.models import (
72
+
73
+ from lamindb._query_manager import QueryManager
74
+ from lamindb._query_set import QuerySet, RecordList
75
+ from lamindb.core._feature_manager import FeatureManager, ParamManager
76
+ from lamindb.core._label_manager import LabelManager
77
+ from lamindb.curators import (
78
+ AnnDataCurator,
79
+ BaseCurator,
80
+ CurateLookup,
81
+ DataFrameCurator,
82
+ MuDataCurator,
83
+ SOMACurator,
84
+ )
85
+ from lamindb.models import (
86
+ BasicRecord,
71
87
  CanCurate,
72
88
  FeatureValue,
73
89
  HasParents,
@@ -75,23 +91,12 @@ from lnschema_core.models import (
75
91
  ParamValue,
76
92
  Record,
77
93
  Registry,
94
+ Schema,
78
95
  TracksRun,
79
96
  TracksUpdates,
80
97
  ValidateFields,
81
98
  )
82
99
 
83
- from lamindb._curate import (
84
- AnnDataCurator,
85
- BaseCurator,
86
- CurateLookup,
87
- DataFrameCurator,
88
- MuDataCurator,
89
- )
90
- from lamindb._query_manager import QueryManager
91
- from lamindb._query_set import QuerySet, RecordList
92
- from lamindb.core._feature_manager import FeatureManager, ParamManager
93
- from lamindb.core._label_manager import LabelManager
94
-
95
100
  from . import _data, datasets, exceptions, fields, loaders, subsettings, types
96
101
  from ._context import Context
97
102
  from ._mapped_collection import MappedCollection