From c214eecbc24b73659a60cbc6083cc3c0d82f6444 Mon Sep 17 00:00:00 2001 From: Ryan Harvey Date: Thu, 26 Sep 2024 13:55:54 -0400 Subject: [PATCH] add columns to dict and then convert to dataframe to prevent warnings --- neuro_py/io/loading.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/neuro_py/io/loading.py b/neuro_py/io/loading.py index a669fbb..64d2e3f 100644 --- a/neuro_py/io/loading.py +++ b/neuro_py/io/loading.py @@ -488,7 +488,7 @@ def un_nest_df(df): data = sio.loadmat(filename) # construct data frame with features per neuron - df = pd.DataFrame() + df = {} # count units n_cells = data["cell_metrics"]["UID"][0][0][0].size dt = data["cell_metrics"].dtype @@ -497,11 +497,17 @@ def un_nest_df(df): try: if (data["cell_metrics"][dn][0][0][0][0].size == 1) & ( data["cell_metrics"][dn][0][0][0].size == n_cells - ): - df[dn] = data["cell_metrics"][dn][0][0][0] + ): + # check if nested within brackets + try: + df[dn] = list(chain(*data["cell_metrics"][dn][0][0][0])) + except Exception: + df[dn] = data["cell_metrics"][dn][0][0][0] except Exception: continue + df = pd.DataFrame(df) + # load in tag # check if tags exist within cell_metrics if "tags" in data.get("cell_metrics").dtype.names: