Skip to content

utils

is_timeseries_feature(df, name)

Check if the given column is a time series feature.

A time series feature contains a list of structs with fields time and value.

Parameters:

Name Type Description Default
df DataFrame

The DataFrame to check.

required
name str

The column to check.

required

Returns:

Type Description
bool

True if the column is a time series feature, False otherwise.

Source code in src/flowcean/utils/is_time_series.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def is_timeseries_feature(df: pl.DataFrame, name: str) -> bool:
    """Check if the given column is a time series feature.

    A time series feature contains a list of structs with fields _time_ and
    _value_.

    Args:
        df: The DataFrame to check.
        name: The column to check.

    Returns:
        True if the column is a time series feature, False otherwise.
    """
    data_type = df.select(name).dtypes[0]

    if data_type.base_type() != pl.List:
        return False

    inner_type: pl.DataType = cast(pl.DataType, cast(pl.List, data_type).inner)
    if inner_type.base_type() != pl.Struct:
        return False

    field_names = [field.name for field in cast(pl.Struct, inner_type).fields]
    return "time" in field_names and "value" in field_names