def METHOD_NAME(
    fdatagrid: T,
) -> T:
    data_matrix = fdatagrid.data_matrix.copy()
    for n_sample in range(fdatagrid.n_samples):
        for n_coord in range(fdatagrid.dim_codomain):
            data_points = data_matrix[n_sample, ..., n_coord]
            nan_pos = np.isnan(data_points)
            valid_pos = ~nan_pos
            coord_indices = np.argwhere(valid_pos)
            desired_coord_indices = np.argwhere(nan_pos)
            coords = _coords_from_indices(
                coord_indices,
                fdatagrid.grid_points,
            )
            desired_coords = _coords_from_indices(
                desired_coord_indices,
                fdatagrid.grid_points,
            )
            values = data_points[valid_pos]
            if fdatagrid.dim_domain == 1:
                interpolation = InterpolatedUnivariateSpline(
                    coords,
                    values,
                    k=1,
                    ext=3,
                )
            else:
                interpolation = LinearNDInterpolator(
                    coords,
                    values,
                )
            new_values = interpolation(
                desired_coords,
            )
            data_matrix[n_sample, nan_pos, n_coord] = new_values.ravel()
    return fdatagrid.copy(data_matrix=data_matrix)