Skip to content

Commit c214eec

Browse files
committed
add columns to dict and then convert to dataframe to prevent warnings
1 parent e11cbee commit c214eec

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

neuro_py/io/loading.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ def un_nest_df(df):
488488
data = sio.loadmat(filename)
489489

490490
# construct data frame with features per neuron
491-
df = pd.DataFrame()
491+
df = {}
492492
# count units
493493
n_cells = data["cell_metrics"]["UID"][0][0][0].size
494494
dt = data["cell_metrics"].dtype
@@ -497,11 +497,17 @@ def un_nest_df(df):
497497
try:
498498
if (data["cell_metrics"][dn][0][0][0][0].size == 1) & (
499499
data["cell_metrics"][dn][0][0][0].size == n_cells
500-
):
501-
df[dn] = data["cell_metrics"][dn][0][0][0]
500+
):
501+
# check if nested within brackets
502+
try:
503+
df[dn] = list(chain(*data["cell_metrics"][dn][0][0][0]))
504+
except Exception:
505+
df[dn] = data["cell_metrics"][dn][0][0][0]
502506
except Exception:
503507
continue
504508

509+
df = pd.DataFrame(df)
510+
505511
# load in tag
506512
# check if tags exist within cell_metrics
507513
if "tags" in data.get("cell_metrics").dtype.names:

0 commit comments

Comments
 (0)