<a id="skfolio-containers-fieldcategorical"></a>

# skfolio.containers.FieldCategorical

<a id="skfolio.containers.FieldCategorical"></a>

### *class* skfolio.containers.FieldCategorical(values, levels, \*, inactive_policy=MISSING)

Integer-coded categorical 2D field.

Codes are stored as integers in a 2D array with axes (observations, assets).
Code -1 is reserved for missing values. Code 0 selects `levels[0]`, code 1 selects
`levels[1]` and so on.

* **Parameters:**
  **values** *integers ndarray of shape (n_observations, n_assets)*
  : Integer category codes. Missing values must be encoded with
    `MISSING_CATEGORY_CODE`.

  **levels** *ndarray of shape (n_levels,)*
  : Category labels selected by codes 0, 1 and so on.
    Labels must be unique.
* **Attributes:**
  [`dtype`](#skfolio.containers.FieldCategorical.dtype)
  : Dtype of the underlying values.

  **inactive_policy**

  [`is_3d`](#skfolio.containers.FieldCategorical.is_3d)
  : Whether or not the field is a 3D field.

  [`is_categorical`](#skfolio.containers.FieldCategorical.is_categorical)
  : Whether or not the field is a categorical field.

  **levels**

  [`missing_mask`](#skfolio.containers.FieldCategorical.missing_mask)
  : Return a boolean mask indicating missing categorical codes.

  [`n_assets`](#skfolio.containers.FieldCategorical.n_assets)
  : Number of assets.

  [`n_observations`](#skfolio.containers.FieldCategorical.n_observations)
  : Number of observations.

  [`ndim`](#skfolio.containers.FieldCategorical.ndim)
  : Number of dimensions of the underlying values.

  [`shape`](#skfolio.containers.FieldCategorical.shape)
  : Shape of the underlying values.

  **values**

### Methods

| [`copy`](#skfolio.containers.FieldCategorical.copy)(\*[, deep])            | Return a copy of the field.                              |
|------------------------------------------------------------------------------|----------------------------------------------------------|
| [`decode`](#skfolio.containers.FieldCategorical.decode)(\*[, missing_label]) | Decode integer codes to level labels.                    |
| [`with_values`](#skfolio.containers.FieldCategorical.with_values)(values)         | Return a field of the same type with replacement values. |

<a id="skfolio.containers.FieldCategorical.copy"></a>

#### copy(\*, deep=False)

Return a copy of the field.

* **Parameters:**
  **deep** *bool, default=False*
  : If `True`, copy NumPy arrays stored by the field. If `False`, reuse the same
    array objects.
* **Returns:**
  **field** *BaseField*
  : Field instance of the same concrete class.

<a id="skfolio.containers.FieldCategorical.decode"></a>

#### decode(\*, missing_label='MISSING')

Decode integer codes to level labels.

* **Parameters:**
  **missing_label** *str, default=”MISSING”*
  : Label assigned to missing or out-of-bound codes.
* **Returns:**
  **decoded** *ndarray*
  : Decoded labels with the same shape as `values`.

<a id="skfolio.containers.FieldCategorical.dtype"></a>

#### *property* dtype

Dtype of the underlying values.

<a id="skfolio.containers.FieldCategorical.is_3d"></a>

#### *property* is_3d

Whether or not the field is a 3D field.

<a id="skfolio.containers.FieldCategorical.is_categorical"></a>

#### *property* is_categorical

Whether or not the field is a categorical field.

<a id="skfolio.containers.FieldCategorical.missing_mask"></a>

#### *property* missing_mask

Return a boolean mask indicating missing categorical codes.

* **Returns:**
  **mask** *ndarray of bool*
  : Boolean array with the same shape as `values`. Entries are `True`
    where `values` equals `MISSING_CATEGORY_CODE`.

<a id="skfolio.containers.FieldCategorical.n_assets"></a>

#### *property* n_assets

Number of assets.

<a id="skfolio.containers.FieldCategorical.n_observations"></a>

#### *property* n_observations

Number of observations.

<a id="skfolio.containers.FieldCategorical.ndim"></a>

#### *property* ndim

Number of dimensions of the underlying values.

<a id="skfolio.containers.FieldCategorical.shape"></a>

#### *property* shape

Shape of the underlying values.

<a id="skfolio.containers.FieldCategorical.with_values"></a>

#### with_values(values)

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:**
  **values** *array-like*
  : Replacement field values.
* **Returns:**
  **field** *BaseField*
  : Field instance of the same concrete class.

