Cases

class farn.core.case.Cases(iterable=(), /)

Bases: list[Case]

Container Class for Cases.

Inherits from List[Case] and can hence be transparently used as a Python list type. However, Cases extends its list base class by two convenience methods: to_pandas() and to_numpy(), which turn the list of Case objects into a pandas DataFrame or numpy ndarray, respectively.

__init__(*args, **kwargs)

Methods

__init__(*args, **kwargs)

add_parameters([parameters])

Manually add extra parameters.

append(object, /)

Append object to the end of the list.

clear()

Remove all items from list.

copy()

Return a shallow copy of the list.

count(value, /)

Return number of occurrences of value.

extend(iterable, /)

Extend list by appending elements from the iterable.

filter([levels, valid_only])

Return a sub-set of cases according to the passed in selection criteria.

index(value[, start, stop])

Return first index of value.

insert(index, object, /)

Insert object before index.

pop([index])

Remove and return item at index (default last).

remove(value, /)

Remove first occurrence of value.

reverse()

Reverse IN PLACE.

sort(*[, key, reverse])

Sort the list in ascending order and return None.

to_numpy()

Return parameter values of all cases as a 2-dimensional numpy array.

to_pandas(*[, use_path_as_index, ...])

Return cases as a pandas Dataframe.

add_parameters(parameters: MutableSequence[Parameter] | MutableMapping[str, str] | None = None) None

Manually add extra parameters.

filter(levels: int | Sequence[int] = -1, *, valid_only: bool = True) Cases

Return a sub-set of cases according to the passed in selection criteria.

Parameters:
  • levels (Union[int, Sequence[int]], optional) – return all cases of a distinct level, or a sequence of levels. level=-1 returns the last level (the leaf cases), by default -1

  • valid_only (bool, optional) – return only valid cases, i.e cases which pass a filter expression defined for the case’s layer, by default True

Returns:

Cases object containing all cases that match the selection criteria.

Return type:

Cases

to_numpy() ndarray[tuple[int, int], dtype[float64]]

Return parameter values of all cases as a 2-dimensional numpy array.

Returns:

2-dimensional numpy array with case specific parameter values of all cases.

Return type:

ndarray[tuple[int, int], np.dtype[np.float64 | np.int32]]

to_pandas(*, use_path_as_index: bool = True, parameters_only: bool = False) DataFrame

Return cases as a pandas Dataframe.

Returns a DataFrame with case properties and case specific parameter values of all cases.

Parameters:
  • use_path_as_index (bool, optional) – turn path column into index column, by default True

  • parameters_only (bool, optional) – reduce DataFrame to contain only the case’s parameter values, by default False

Returns:

DataFrame with case properties and case specific parameter values of all cases.

Return type:

DataFrame