Skip to content

time_series_type

get_time_series_value_type(t)

Returns the Polars data type of the value in a time-series type.

Parameters:

Name Type Description Default
t DataType

The Polars data type.

required

Returns:

Type Description
PolarsDataType

The time-series type of the data type.

Source code in src/flowcean/polars/time_series_type.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def get_time_series_value_type(t: pl.DataType) -> PolarsDataType:
    """Returns the Polars data type of the value in a time-series type.

    Args:
        t: The Polars data type.

    Returns:
        The time-series type of the data type.
    """
    # Unpack the time-series structure.
    # First check if the data type is a list...
    if not isinstance(t, pl.List):
        msg = f"Expected a List data type, got {t}."
        raise TypeError(msg)
    t = cast("pl.List", t)

    # ... of structs.
    if not isinstance(t.inner, pl.Struct):
        msg = f"Expected a List of Structs, got a List of {t}."
        raise TypeError(msg)
    t = cast("pl.Struct", t.inner)

    # Then check if the struct has a field named "value".
    value_field = [field for field in t.fields if field.name == "value"]

    if len(value_field) != 1:
        msg = (
            f"Expected structs to have a field named 'value', got {t.fields}."
        )
        raise TypeError(msg)

    # Finally, return the data type of the "value" field.
    return value_field[0].dtype

get_time_series_time_type(t)

Returns the Polars data type of the time in a time-series type.

Parameters:

Name Type Description Default
t DataType

The Polars data type.

required

Returns:

Type Description
PolarsDataType

The time-series type of the data type.

Source code in src/flowcean/polars/time_series_type.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
def get_time_series_time_type(t: pl.DataType) -> PolarsDataType:
    """Returns the Polars data type of the time in a time-series type.

    Args:
        t: The Polars data type.

    Returns:
        The time-series type of the data type.
    """
    # Unpack the time-series structure.
    # First check if the data type is a list...
    if not isinstance(t, pl.List):
        msg = f"Expected a List data type, got {t}."
        raise TypeError(msg)
    t = cast("pl.List", t)

    # ... of structs.
    if not isinstance(t.inner, pl.Struct):
        msg = f"Expected a List of Structs, got a List of {t}."
        raise TypeError(msg)
    t = cast("pl.Struct", t.inner)

    # Then check if the struct has a field named "time".
    time_field = [field for field in t.fields if field.name == "time"]

    if len(time_field) != 1:
        msg = f"Expected structs to have a field named 'time', got {t.fields}."
        raise TypeError(msg)

    # Finally, return the data type of the "time" field.
    return time_field[0].dtype