skfolio.utils.validation.validate_asset_panel#

skfolio.utils.validation.validate_asset_panel(_estimator, /, asset_panel, required_fields=None, reserved_fields=None, finite_or_nan=None, finite_when_active=None, strictly_positive_or_nan=None, strictly_positive_when_active=None, non_negative_or_nan=None, reset=True, copy=False)[source]#

Validate an AssetPanel and set estimator metadata attributes.

This function validates that the panel contains required fields, doesn’t contain reserved ones and sets standard metadata attributes on the estimator.

Parameters:
_estimatorestimator instance

The estimator on which to set validation attributes.

asset_panelAssetPanel or AssetPanelView

AssetPanel. AssetPanel already validates that all fields have consistent shapes and consistent masks, allowing this validation to be lightweight.

required_fieldslist of str, optional

Fields that must be present in the AssetPanel. If any are missing, a ValueError is raised.

reserved_fieldslist of str, optional

Fields that must NOT be present in the AssetPanel. These are typically names the estimator will create internally. If any are found, a ValueError is raised.

finite_or_nanlist of str, optional

Fields whose values must be finite or NaN.

finite_when_activelist of str, optional

Fields whose values must be finite wherever active_mask is True. This is typically used for fields like “market_cap” that must be forward-filled for holidays before constructing the AssetPanel.

strictly_positive_or_nanlist of str, optional

Fields whose values must be strictly positive and finite, or NaN.

strictly_positive_when_activelist of str, optional

Fields whose values must be strictly positive and finite wherever active_mask is True.

non_negative_or_nanlist of str, optional

Fields whose values must be non-negative and finite, or NaN.

resetbool, default=True

If True, sets metadata attributes on the estimator: - asset_names_: array of asset identifiers - n_assets_: number of assets

If False, validates that existing attributes match the panel.

copybool, default=False

If True, returns a shallow copy of the panel (new dict containers with shared arrays). Use this when the estimator needs to add fields without mutating the user’s input.

Returns:
AssetPanel or AssetPanelView

The validated panel, or a shallow copy if copy=True.

Raises:
TypeError

If asset_panel is not an AssetPanel or AssetPanelView.

ValueError

If required fields are missing, reserved fields are present, a field validation rule is violated or (when reset=False) panel doesn’t match stored metadata.