scverse / mudata

Multimodal Data (.h5mu) implementation for Python
https://mudata.rtfd.io
BSD 3-Clause "New" or "Revised" License
72 stars 16 forks source link

Bug: key error when running .update() #28

Closed linnabrown closed 1 year ago

linnabrown commented 1 year ago

Describe the bug

There is a potential bug for updating the mdata (mdata.update()).


KeyError Traceback (most recent call last) /srv/conda/envs/notebook/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance) 3360 try: -> 3361 return self._engine.get_loc(casted_key) 3362 except KeyError as err:

/srv/conda/envs/notebook/lib/python3.7/site-packages/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

/srv/conda/envs/notebook/lib/python3.7/site-packages/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'var_ad2_1'

The above exception was the direct cause of the following exception:

KeyError Traceback (most recent call last) /tmp/ipykernel_170/756227330.py in ----> 1 mdata.update()

/srv/conda/envs/notebook/lib/python3.7/site-packages/mudata/_core/mudata.py in update(self) 1127 Update both .obs and .var of MuData with the data from all the modalities 1128 """ -> 1129 self.update_var() 1130 self.update_obs() 1131

/srv/conda/envs/notebook/lib/python3.7/site-packages/mudata/_core/mudata.py in update_var(self) 960 """ 961 join_common = self.axis == 0 --> 962 self._update_attr("var", axis=0, join_common=join_common) 963 964 def var_names_make_unique(self):

/srv/conda/envs/notebook/lib/python3.7/site-packages/mudata/_core/mudata.py in _update_attr(self, attr, axis, join_common) 729 # NOTE: .get_index doesn't work with duplicated indices 730 # index_order = prev_index.get_indexer(now_index) --> 731 index_order = [prev_index.get_loc(i) for i in now_index] 732 733 for mx_key, mx in attrm.items():

/srv/conda/envs/notebook/lib/python3.7/site-packages/mudata/_core/mudata.py in (.0) 729 # NOTE: .get_index doesn't work with duplicated indices 730 # index_order = prev_index.get_indexer(now_index) --> 731 index_order = [prev_index.get_loc(i) for i in now_index] 732 733 for mx_key, mx in attrm.items():

/srv/conda/envs/notebook/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance) 3361 return self._engine.get_loc(casted_key) 3362 except KeyError as err: -> 3363 raise KeyError(key) from err 3364 3365 if is_scalar(key) and isna(key) and not self.hasnans:

KeyError: 'var_ad2_1'

To Reproduce I just run the example notebook provided by the official tutorial. The error happened when running the code in the notebook cell.

Expected behaviour The expected output is just to print the updated var names.

System

gtca commented 1 year ago

Hey @linnabrown,

This has been fixed in the upcoming mudata == 0.2.1 so the current master branch in the repository should resolve it. Should also made be available in PyPI soon so that pip install will also work!