skfolio.utils.tools.input_to_array#
- skfolio.utils.tools.input_to_array(items, n_assets, fill_value, dim, assets_names, name, investable_mask=None)[source]#
Convert a collection of items (array-like or dictionary) into a numpy array and verify its shape.
When
investable_maskis provided, dictionary inputs are resolved against the fullassets_namesand then subsetted, while array inputs sized to the full universe are sliced down to the investable assets. This allows callers to pass user-facing parameters (keyed by asset name or sized for the full universe) and transparently obtain arrays sized for the investable subset.- Parameters:
- itemsnp.ndarray | dict | list
Items to verify and convert to array.
- n_assetsint
Expected number of assets in the output array (i.e. the investable count when
investable_maskis provided).- fill_valueAny
When
itemsis a dictionary, elements that are not inasset_namesare filled withfill_valuein the converted array.- dimint
Dimension of the final array. Possible values are
1or2.- assets_namesndarray, optional
Asset names used when
itemsis a dictionary. Wheninvestable_maskis provided, this must contain the full-universe names.- namestr
Name of the items used for error messages.
- investable_maskndarray of shape (n_full_assets,), optional
Boolean mask selecting investable assets from the full universe. When provided, dictionary inputs are first resolved against the full universe then sliced, and array-like inputs sized to the full universe are sliced along the last axis.
- Returns:
- valuesndarray of shape (n_assets) for dim=1 or (n_groups, n_assets) for dim=2
Converted array.