skfolio.containers.BaseField#
- class skfolio.containers.BaseField(values, *, inactive_policy=MISSING)[source]#
Base class for fields stored in an
AssetPanel.A field stores a NumPy array for one named variable. The first two axes are always observations and assets with shape (n_observations, n_assets). Subclasses define any additional metadata required by the array layout.
- Parameters:
- valuesndarray of shape (n_observations, n_assets)
Field values. The first two axes must be observations and assets.
- Attributes:
dtypeDtype of the underlying values.
- inactive_policy
is_3dWhether or not the field is a 3D field.
is_categoricalWhether or not the field is a categorical field.
missing_maskReturn a boolean mask indicating missing entries.
n_assetsNumber of assets.
n_observationsNumber of observations.
ndimNumber of dimensions of the underlying values.
shapeShape of the underlying values.
- values
Methods
copy(*[, deep])Return a copy of the field.
with_values(values)Return a field of the same type with replacement values.
- copy(*, deep=False)[source]#
Return a copy of the field.
- Parameters:
- deepbool, default=False
If
True, copy NumPy arrays stored by the field. IfFalse, reuse the same array objects.
- Returns:
- fieldBaseField
Field instance of the same concrete class.
- property dtype#
Dtype of the underlying values.
- property is_3d#
Whether or not the field is a 3D field.
- property is_categorical#
Whether or not the field is a categorical field.
- property missing_mask#
Return a boolean mask indicating missing entries.
- Returns:
- maskndarray of bool
Boolean array with the same shape as
values. Entries areTruewherevaluesis NaN for floating-point fields andFalseelsewhere. Non-floating fields without a missing-value convention return an all-Falsemask; subclasses override this method when they define their own convention.
- property n_assets#
Number of assets.
- property n_observations#
Number of observations.
- property ndim#
Number of dimensions of the underlying values.
- property shape#
Shape of the underlying values.
- with_values(values)[source]#
Return a field of the same type with replacement values.
Metadata arrays are reused. The replacement values are validated by the concrete field class constructor.
- Parameters:
- valuesarray-like
Replacement field values.
- Returns:
- fieldBaseField
Field instance of the same concrete class.