lamindb 0.74.3__py3-none-any.whl → 0.75.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.
@@ -4,13 +4,13 @@ from collections import defaultdict
4
4
  from typing import TYPE_CHECKING, Dict
5
5
 
6
6
  import numpy as np
7
- from lamin_utils import colors, logger
7
+ from lamin_utils import colors
8
8
  from lnschema_core.models import Feature
9
9
 
10
10
  from lamindb._from_values import _print_values
11
11
  from lamindb._record import (
12
12
  REGISTRY_UNIQUE_FIELD,
13
- get_default_str_field,
13
+ get_name_field,
14
14
  transfer_fk_to_default_db_bulk,
15
15
  transfer_to_default_db,
16
16
  )
@@ -28,17 +28,19 @@ if TYPE_CHECKING:
28
28
  def get_labels_as_dict(self: HasFeatures, links: bool = False):
29
29
  exclude_set = {
30
30
  "feature_sets",
31
- "unordered_artifacts",
32
- "input_of",
31
+ "artifacts",
32
+ "input_of_runs",
33
33
  "collections",
34
- "source_code_of",
34
+ "_source_code_artifact_of",
35
35
  "report_of",
36
36
  "environment_of",
37
- "collection_links",
38
- "artifact_links",
39
- "feature_set_links",
37
+ "links_collection",
38
+ "links_artifact",
39
+ "links_feature_set",
40
40
  "previous_runs",
41
- "feature_values",
41
+ "_feature_values",
42
+ "_lnschema_core_collection__actions_+",
43
+ "_actions",
42
44
  }
43
45
  labels = {} # type: ignore
44
46
  if self.id is None:
@@ -62,7 +64,7 @@ def print_labels(self: HasFeatures, field: str = "name", print_types: bool = Fal
62
64
  try:
63
65
  labels_list = list(labels.values_list(field, flat=True))
64
66
  if len(labels_list) > 0:
65
- get_default_str_field(labels)
67
+ get_name_field(labels)
66
68
  print_values = _print_values(labels_list, n=10)
67
69
  type_str = f": {related_model}" if print_types else ""
68
70
  labels_msg += f" .{related_name}{type_str} = {print_values}\n"
@@ -84,18 +86,14 @@ def validate_labels(labels: QuerySet | list | dict):
84
86
  return [], []
85
87
  registry = labels[0].__class__
86
88
  field = REGISTRY_UNIQUE_FIELD.get(registry.__name__.lower(), "uid")
87
- if hasattr(registry, "ontology_id"):
88
- field = "ontology_id"
89
- elif hasattr(registry, "ensembl_gene_id"):
90
- field = "ensembl_gene_id"
91
- elif hasattr(registry, "uniprotkb_id"):
92
- field = "uniprotkb_id"
89
+ if hasattr(registry, "_ontology_id_field"):
90
+ field = registry._ontology_id_field
93
91
  # if the field value is None, use uid field
94
92
  label_uids = np.array(
95
93
  [getattr(label, field) for label in labels if label is not None]
96
94
  )
97
95
  # save labels from ontology_ids
98
- if field == "ontology_id" and len(label_uids) > 0:
96
+ if hasattr(registry, "_ontology_id_field") and len(label_uids) > 0:
99
97
  try:
100
98
  save(registry.from_values(label_uids, field=field))
101
99
  except Exception: # noqa S110
@@ -201,10 +199,10 @@ class LabelManager:
201
199
  transfer_fk_to_default_db_bulk(new_labels, using_key)
202
200
  for label in labels:
203
201
  # if the link table doesn't follow this convention, we'll ignore it
204
- if not hasattr(label, f"{data_name_lower}_links"):
202
+ if not hasattr(label, f"links_{data_name_lower}"):
205
203
  key = None
206
204
  else:
207
- link = getattr(label, f"{data_name_lower}_links").get(
205
+ link = getattr(label, f"links_{data_name_lower}").get(
208
206
  **{f"{data_name_lower}_id": data.id}
209
207
  )
210
208
  if link.feature is not None:
@@ -10,7 +10,7 @@ import pandas as pd
10
10
  from lamin_utils import logger
11
11
  from lamindb_setup.core.upath import UPath
12
12
 
13
- from .storage._backed_access import (
13
+ from .storage._anndata_accessor import (
14
14
  ArrayType,
15
15
  ArrayTypes,
16
16
  GroupType,
@@ -11,7 +11,6 @@ from lamin_utils import logger
11
11
  from lamindb_setup.core.hashing import hash_file
12
12
  from lnschema_core import Run, Transform, ids
13
13
  from lnschema_core.models import Param, ParamValue, RunParamValue
14
- from lnschema_core.types import TransformType
15
14
  from lnschema_core.users import current_user_id
16
15
 
17
16
  from ._settings import settings
@@ -27,6 +26,7 @@ from .versioning import bump_version as bump_version_function
27
26
 
28
27
  if TYPE_CHECKING:
29
28
  from lamindb_setup.core.types import UPathStr
29
+ from lnschema_core.types import TransformType
30
30
 
31
31
  is_run_from_ipython = getattr(builtins, "__IPYTHON__", False)
32
32
 
@@ -279,14 +279,14 @@ class run_context:
279
279
  ).one_or_none()
280
280
  if is_run_from_ipython:
281
281
  key, name = cls._track_notebook(path=path)
282
- transform_type = TransformType.notebook
282
+ transform_type = "notebook"
283
283
  transform_ref = None
284
284
  transform_ref_type = None
285
285
  else:
286
286
  (name, key, transform_ref, transform_ref_type) = cls._track_script(
287
287
  path=path
288
288
  )
289
- transform_type = TransformType.script
289
+ transform_type = "script"
290
290
  # overwrite whatever is auto-detected in the notebook or script
291
291
  if transform_settings.name is not None:
292
292
  name = transform_settings.name
@@ -323,9 +323,7 @@ class run_context:
323
323
  cls.transform = transform_exists
324
324
 
325
325
  if new_run is None: # for notebooks, default to loading latest runs
326
- new_run = (
327
- False if cls.transform.type == TransformType.notebook.value else True
328
- ) # type: ignore
326
+ new_run = False if cls.transform.type == "notebook" else True # type: ignore
329
327
 
330
328
  run = None
331
329
  from lamindb._run import Run
@@ -479,7 +477,7 @@ class run_context:
479
477
  transform.save()
480
478
  logger.important(f"updated: {transform}")
481
479
  # check whether transform source code was already saved
482
- if transform.source_code_id is not None:
480
+ if transform._source_code_artifact_id is not None:
483
481
  response = None
484
482
  if is_run_from_ipython:
485
483
  if os.getenv("LAMIN_TESTING") is None:
@@ -491,7 +489,7 @@ class run_context:
491
489
  response = "y"
492
490
  else:
493
491
  hash, _ = hash_file(cls.path) # ignore hash_type for now
494
- if hash != transform.source_code.hash:
492
+ if hash != transform._source_code_artifact.hash:
495
493
  # only if hashes don't match, we need user input
496
494
  if os.getenv("LAMIN_TESTING") is None:
497
495
  response = input(
@@ -83,7 +83,7 @@ def file_tsv_rnaseq_nfcore_salmon_merged_gene_counts(
83
83
  ln.settings.verbosity = "error"
84
84
  ln.Feature(name="assay", dtype=[bt.ExperimentalFactor]).save()
85
85
  ln.Feature(name="organism", dtype=[bt.Organism]).save()
86
- bt.ExperimentalFactor.from_public(ontology_id="EFO:0008896").save()
86
+ bt.ExperimentalFactor.from_source(ontology_id="EFO:0008896").save()
87
87
  ln.settings.verbosity = verbosity
88
88
 
89
89
  return Path(filepath)
@@ -186,16 +186,16 @@ def anndata_mouse_sc_lymph_node(
186
186
  verbosity = ln.settings.verbosity
187
187
  ln.settings.verbosity = "error"
188
188
  # strain
189
- bt.ExperimentalFactor.from_public(ontology_id="EFO:0004472").save()
189
+ bt.ExperimentalFactor.from_source(ontology_id="EFO:0004472").save()
190
190
  # developmental stage
191
- bt.ExperimentalFactor.from_public(ontology_id="EFO:0001272").save()
191
+ bt.ExperimentalFactor.from_source(ontology_id="EFO:0001272").save()
192
192
  # tissue
193
- bt.Tissue.from_public(ontology_id="UBERON:0001542").save()
193
+ bt.Tissue.from_source(ontology_id="UBERON:0001542").save()
194
194
  # cell types
195
195
  ln.save(bt.CellType.from_values(["CL:0000115", "CL:0000738"], "ontology_id"))
196
196
  # assays
197
197
  ln.Feature(name="assay", dtype=[bt.ExperimentalFactor]).save()
198
- bt.ExperimentalFactor.from_public(ontology_id="EFO:0008913").save()
198
+ bt.ExperimentalFactor.from_source(ontology_id="EFO:0008913").save()
199
199
  # genes
200
200
  validated = bt.Gene.public(organism="mouse").validate(
201
201
  adata.var.index, field="ensembl_gene_id"
@@ -323,7 +323,7 @@ def anndata_human_immune_cells(
323
323
  ln.Feature(name="tissue", dtype=[bt.Tissue]).save()
324
324
  ln.Feature(name="organism", dtype=[bt.Organism]).save()
325
325
  ln.Feature(name="donor", dtype=[ln.ULabel]).save()
326
- bt.ExperimentalFactor.from_public(ontology_id="EFO:0008913").save()
326
+ bt.ExperimentalFactor.from_source(ontology_id="EFO:0008913").save()
327
327
  ln.save([ln.ULabel(name=name) for name in adata.obs.donor.unique()])
328
328
  ln.settings.verbosity = verbosity
329
329
  return adata
@@ -332,7 +332,7 @@ def anndata_human_immune_cells(
332
332
  def anndata_with_obs() -> ad.AnnData:
333
333
  """Create a mini anndata with cell_type, disease and tissue."""
334
334
  import anndata as ad
335
- import bionty_base
335
+ import bionty.base as bionty_base
336
336
 
337
337
  celltypes = ["T cell", "hematopoietic stem cell", "hepatocyte", "my new cell type"]
338
338
  celltype_ids = ["CL:0000084", "CL:0000037", "CL:0000182", ""]
@@ -10,6 +10,7 @@ The registry base class:
10
10
  NoTitleError
11
11
  MissingTransformSettings
12
12
  UpdateTransformSettings
13
+ IntegrityError
13
14
 
14
15
  """
15
16
 
@@ -25,6 +26,16 @@ class ValidationError(SystemExit):
25
26
  # -------------------------------------------------------------------------------------
26
27
 
27
28
 
29
+ class IntegrityError(Exception):
30
+ """Integrity error.
31
+
32
+ For instance, it's not allowed to delete artifacts outside managed storage
33
+ locations.
34
+ """
35
+
36
+ pass
37
+
38
+
28
39
  class NotebookNotSavedError(Exception):
29
40
  """Notebook wasn't saved."""
30
41
 
@@ -6,6 +6,7 @@
6
6
  AnnDataAccessor
7
7
  BackedAccessor
8
8
  """
9
+
9
10
  from lamindb_setup.core.upath import LocalPathClasses, UPath, infer_filesystem
10
11
 
11
12
  from ._anndata_sizes import size_adata