From 50fd5c2e75b5e384d99951ccddd81b27486a535e Mon Sep 17 00:00:00 2001 From: Altana Namsaraeva <99650244+namsaraeva@users.noreply.github.com> Date: Fri, 9 Dec 2022 09:54:45 +0100 Subject: [PATCH] KeyError fix issue #423 (#428) * keyerror fix * nox fix --- ehrapy/anndata/anndata_ext.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ehrapy/anndata/anndata_ext.py b/ehrapy/anndata/anndata_ext.py index 258a2f0b..d804ff76 100644 --- a/ehrapy/anndata/anndata_ext.py +++ b/ehrapy/anndata/anndata_ext.py @@ -108,11 +108,11 @@ def _move_columns_to_obs(df: pd.DataFrame, columns_obs_only: list[str] | None) - obs = df[columns_obs_only].copy() obs = obs.set_index(df.index.map(str)) df = df.drop(columns_obs_only, axis=1) - except KeyError: - raise ColumnNotFoundError from KeyError( + except KeyError as e: + raise ColumnNotFoundError( "One or more column names passed to column_obs_only were not found in the input data. " "Are the column names spelled correctly?" - ) + ) from e else: obs = pd.DataFrame(index=df.index.map(str)) logg.info("Added all columns to `obs`.")