Skip to content

Commit

Permalink
🎨 Fix Curator.from_mudata (#2082)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnyosun authored Oct 18, 2024
1 parent a7027eb commit 39c82df
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions lamindb/_curate.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ def _save_from_var_index_modality(
values=list(self._mdata[modality].var.index),
field=self._var_fields[modality],
key="var_index",
save_function=".add_new_from_var_index()",
save_function=f'.add_new_from_var_index("{modality}")',
using_key=self._using_key,
validated_only=validated_only,
dtype="number",
Expand Down Expand Up @@ -840,14 +840,21 @@ def add_new_from(

def validate(self, organism: str | None = None) -> bool:
"""Validate categories."""
from lamindb.core._settings import settings

self._kwargs.update({"organism": organism} if organism else {})
if self._using_key is not None and self._using_key != "default":
logger.important(
f"validating metadata using registries of instance {colors.italic(self._using_key)}"
)

# add all validated records to the current instance
self._update_registry_all()
verbosity = settings.verbosity
try:
settings.verbosity = "error"
self._update_registry_all()
finally:
settings.verbosity = verbosity

validated_var = True
non_validated_var_modality = {}
Expand All @@ -859,6 +866,7 @@ def validate(self, organism: str | None = None) -> bool:
using_key=self._using_key,
source=self._sources.get(modality, {}).get("var_index"),
exclude=self._exclude.get(modality, {}).get("var_index"),
validated_hint_print=f'.add_validated_from_var_index("{modality}")',
**self._kwargs, # type: ignore
)
validated_var &= is_validated_var
Expand Down Expand Up @@ -1385,19 +1393,28 @@ def _add_labels(

if artifact._accessor == "MuData":
for modality, modality_fields in fields.items():
column_field_modality = columns_field.get(modality)
if modality == "obs":
_add_labels(
data,
artifact,
modality_fields,
feature_ref_is_name=_ref_is_name(columns_field.get("obs")),
feature_ref_is_name=(
None
if column_field_modality is None
else _ref_is_name(column_field_modality)
),
)
else:
_add_labels(
data[modality],
artifact,
modality_fields,
feature_ref_is_name=_ref_is_name(columns_field.get(modality)),
feature_ref_is_name=(
None
if column_field_modality is None
else _ref_is_name(column_field_modality)
),
)
else:
_add_labels(
Expand Down

0 comments on commit 39c82df

Please sign in to comment.