20251024 - bug in `pr.export_kinetics()`

working in bnext/experiments/20251012-plamGFP-disembork/20251023-polish-2/PURE-activity/data

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/tmp/ipykernel_3419299/4161971543.py in ?()
----> 1 pr.export_kinetics(kinetics, f"tables/{exp_name}-kinetics-table.csv", platemap)

/data/bnext/code/bnext/cdk/src/cdk/analysis/cytosol/platereader.py in ?(kinetics, output_file, platemap)
   1413             df[col] = df[col].dt.total_seconds()
   1414             df = df.rename(columns={col: f"{col} (s)"})
   1415 
   1416     if platemap is not None:
-> 1417         df = df.merge(platemap, how="left", on=kinetics_index)
   1418 
   1419     df.to_csv(output_file, index=False)

/opt/anaconda3/envs/bnext-cdk/lib/python3.12/site-packages/pandas/core/frame.py in ?(self, right, how, on, left_on, right_on, left_index, right_index, sort, suffixes, copy, indicator, validate)
  10828         validate: MergeValidate | None = None,
  10829     ) -> DataFrame:
  10830         from pandas.core.reshape.merge import merge
  10831 
> 10832         return merge(
  10833             self,
  10834             right,
  10835             how=how,

/opt/anaconda3/envs/bnext-cdk/lib/python3.12/site-packages/pandas/core/reshape/merge.py in ?(left, right, how, on, left_on, right_on, left_index, right_index, sort, suffixes, copy, indicator, validate)
    166             validate=validate,
    167             copy=copy,
    168         )
    169     else:
--> 170         op = _MergeOperation(
    171             left_df,
    172             right_df,
    173             how=how,

/opt/anaconda3/envs/bnext-cdk/lib/python3.12/site-packages/pandas/core/reshape/merge.py in ?(self, left, right, how, on, left_on, right_on, left_index, right_index, sort, suffixes, indicator, validate)
    790             self.right_join_keys,
    791             self.join_names,
    792             left_drop,
    793             right_drop,
--> 794         ) = self._get_merge_keys()
    795 
    796         if left_drop:
    797             self.left = self.left._drop_labels_or_levels(left_drop)

/opt/anaconda3/envs/bnext-cdk/lib/python3.12/site-packages/pandas/core/reshape/merge.py in ?(self)
   1293                         # Then we're either Hashable or a wrong-length arraylike,
   1294                         #  the latter of which will raise
   1295                         rk = cast(Hashable, rk)
   1296                         if rk is not None:
-> 1297                             right_keys.append(right._get_label_or_level_values(rk))
   1298                         else:
   1299                             # work-around for merge_asof(right_index=True)
   1300                             right_keys.append(right.index._values)

/opt/anaconda3/envs/bnext-cdk/lib/python3.12/site-packages/pandas/core/generic.py in ?(self, key, axis)
   1907             values = self.xs(key, axis=other_axes[0])._values
   1908         elif self._is_level_reference(key, axis=axis):
   1909             values = self.axes[axis].get_level_values(key)._values
   1910         else:
-> 1911             raise KeyError(key)
   1912 
   1913         # Check for duplicates
   1914         if values.ndim > 1:

KeyError: 'Read'

I think helpful way to put up bug reports so that people can work with you faster is:

  1. What you did [include example lines that you ran].
  2. Some context – for example something like “Running conventional PURE analysis and want to export kinetics data. This can be found in Cell X of jupyter notebook <link to notebook>
  3. A screenshot of relevant variables [like: A screenshot of your “df” here would be also beneficial to know what format you’re in. ]
  4. What you did to try to resolve it yourself and what you dont understand or think is the problem.
1 Like

FYI: Anton might be faster on debugging this since he wrote the function. But this looks like a multiIndexing issue and the fact that group_by as both Read and Name in it, but platemap doesnt. Ping me if Anton has too much on his hands and I can pop in.

Thanks @sharon this is a really good prompt for getting help with bug fixes - I’ll add it to the main Category page.