Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import_from_source fails when no parents column is present. #141

Open
Zethson opened this issue Oct 30, 2024 · 0 comments
Open

import_from_source fails when no parents column is present. #141

Zethson opened this issue Oct 30, 2024 · 0 comments
Assignees

Comments

@Zethson
Copy link
Member

Zethson commented Oct 30, 2024

Context: https://laminlabs.slack.com/archives/C04MU979KD3/p1730300809261839

bt.Disease.import_from_source()

where the source is not mondo but ICD9

-->
{
	"name": "KeyError",
	"message": "\"['parents'] not found in axis\"",
	"stack": "---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[7], line 1
----> 1 bt.Disease.import_from_source()

File ~/miniconda3/envs/pertpy/lib/python3.12/site-packages/bionty/models.py:241, in BioRecord.import_from_source(cls, source, ontology_ids, organism, ignore_conflicts)
    238 from .core._add_ontology import add_ontology_from_df, check_source_in_db
    240 if hasattr(cls, \"ontology_id\"):
--> 241     add_ontology_from_df(
    242         registry=cls,
    243         ontology_ids=ontology_ids,
    244         organism=organism,
    245         source=source,
    246         ignore_conflicts=ignore_conflicts,
    247     )
    248 else:
    249     import lamindb as ln

File ~/miniconda3/envs/pertpy/lib/python3.12/site-packages/bionty/core/_add_ontology.py:173, in add_ontology_from_df(registry, ontology_ids, organism, source, ignore_conflicts)
    164 n_in_db = all_records.count()
    166 check_source_in_db(
    167     registry=registry,
    168     source=source_record,
    169     n_all=n_all,
    170     n_in_db=n_in_db,
    171 )
--> 173 records = create_records(registry, df_new, source_record)
    174 new_records = [r for r in records if r._state.adding]
    175 if ontology_ids is None:

File ~/miniconda3/envs/pertpy/lib/python3.12/site-packages/bionty/core/_add_ontology.py:53, in create_records(registry, df, source_record)
     45 def create_records(
     46     registry: Type[BioRecord], df: pd.DataFrame, source_record: Source
     47 ) -> List[Record]:
     48     import lamindb as ln
     50     df_records = (
     51         df.reset_index()
     52         .rename(columns={\"definition\": \"description\"})
---> 53         .drop(columns=[\"parents\"])
     54         .to_dict(orient=\"records\")
     55     )
     56     try:
     57         ln.settings.creation.search_names = False

File ~/miniconda3/envs/pertpy/lib/python3.12/site-packages/pandas/core/frame.py:5581, in DataFrame.drop(self, labels, axis, index, columns, level, inplace, errors)
   5433 def drop(
   5434     self,
   5435     labels: IndexLabel | None = None,
   (...)
   5442     errors: IgnoreRaise = \"raise\",
   5443 ) -> DataFrame | None:
   5444     \"\"\"
   5445     Drop specified labels from rows or columns.
   5446 
   (...)
   5579             weight  1.0     0.8
   5580     \"\"\"
-> 5581     return super().drop(
   5582         labels=labels,
   5583         axis=axis,
   5584         index=index,
   5585         columns=columns,
   5586         level=level,
   5587         inplace=inplace,
   5588         errors=errors,
   5589     )

File ~/miniconda3/envs/pertpy/lib/python3.12/site-packages/pandas/core/generic.py:4788, in NDFrame.drop(self, labels, axis, index, columns, level, inplace, errors)
   4786 for axis, labels in axes.items():
   4787     if labels is not None:
-> 4788         obj = obj._drop_axis(labels, axis, level=level, errors=errors)
   4790 if inplace:
   4791     self._update_inplace(obj)

File ~/miniconda3/envs/pertpy/lib/python3.12/site-packages/pandas/core/generic.py:4830, in NDFrame._drop_axis(self, labels, axis, level, errors, only_slice)
   4828         new_axis = axis.drop(labels, level=level, errors=errors)
   4829     else:
-> 4830         new_axis = axis.drop(labels, errors=errors)
   4831     indexer = axis.get_indexer(new_axis)
   4833 # Case for non-unique axis
   4834 else:

File ~/miniconda3/envs/pertpy/lib/python3.12/site-packages/pandas/core/indexes/base.py:7070, in Index.drop(self, labels, errors)
   7068 if mask.any():
   7069     if errors != \"ignore\":
-> 7070         raise KeyError(f\"{labels[mask].tolist()} not found in axis\")
   7071     indexer = indexer[~mask]
   7072 return self.delete(indexer)

KeyError: \"['parents'] not found in axis\""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants