Skip to content

Commit daac241

Browse files
committed
Allow diagonal elements + drop duplicated values
1 parent c120626 commit daac241

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

frites/conn/conn_utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,17 @@ def _dataarray_unstack(da, sources, targets, roi_tot, fill_value, order,
303303
"""Unstack a 1d to 2d DataArray."""
304304
import pandas as pd
305305

306+
# build the multi-index
306307
da['roi'] = pd.MultiIndex.from_arrays(
307308
[sources, targets], names=['sources', 'targets'])
309+
# test for duplicated entries
310+
st_names = pd.Series([f"{s}-{t}" for s, t in zip(sources, targets)])
311+
duplicates = np.array(list(st_names.duplicated(keep='first')))
312+
if duplicates.any():
313+
logger.warning(f"Duplicated entries found and removed : "
314+
f"{da['roi'].data[duplicates]}")
315+
da = da.sel(roi=~duplicates)
316+
# unstack to be 2D/3D
308317
da = da.unstack(fill_value=fill_value)
309318

310319
# transpose, reindex and reorder (if needed)

0 commit comments

Comments
 (0)