nispace.utils.utils.fill_nan

nispace.utils.utils.fill_nan(data, idx, idx_label=None, which='col')[source]

Re-insert all-NaN rows/columns at given positions (inverse of dropping them).

Plain numpy/pandas (no numba). Used in api.py’s dimensionality-reduction path (X_reduction) to restore parcels/maps that were dropped (as all-NaN) before PCA/ICA/FA, so the reduced output keeps the original column/row layout with NaN at the dropped positions.

Parameters:
  • data (array-like or pd.DataFrame) – Input data to insert NaN rows/columns into.

  • idx (array-like of int) – Positions (in the output, post-insertion, array) at which to insert a new all-NaN row/column.

  • idx_label (list of str, optional) – For DataFrame input, labels to assign to the newly inserted index/column entries. Defaults to "nan" for each.

  • which (str, default="col") – Whether to insert rows (any string starting with "row") or columns (starting with "col").

Returns:

data with NaN rows/columns inserted at idx. Integer input is upcast to float (NaN requires a float dtype).

Return type:

np.ndarray or pd.DataFrame