Skip to content

Schemas

siapy.datasets.schemas

Target

Bases: BaseModel, ABC

model_config class-attribute instance-attribute

model_config = ConfigDict(arbitrary_types_allowed=True)

value instance-attribute

value: Series

from_dict abstractmethod classmethod

from_dict(data: dict[str, Any]) -> Target
PARAMETER DESCRIPTION
data

TYPE: dict[str, Any]

Source code in siapy/datasets/schemas.py
28
29
30
@classmethod
@abstractmethod
def from_dict(cls, data: dict[str, Any]) -> "Target": ...

from_iterable abstractmethod classmethod

from_iterable(data: Iterable) -> Target
PARAMETER DESCRIPTION
data

TYPE: Iterable

Source code in siapy/datasets/schemas.py
32
33
34
@classmethod
@abstractmethod
def from_iterable(cls, data: Iterable) -> "Target": ...

to_dict abstractmethod

to_dict() -> dict[str, Any]
Source code in siapy/datasets/schemas.py
36
37
@abstractmethod
def to_dict(self) -> dict[str, Any]: ...

to_dataframe abstractmethod

to_dataframe() -> DataFrame
Source code in siapy/datasets/schemas.py
39
40
@abstractmethod
def to_dataframe(self) -> pd.DataFrame: ...

reset_index abstractmethod

reset_index() -> Target
Source code in siapy/datasets/schemas.py
42
43
@abstractmethod
def reset_index(self) -> "Target": ...

ClassificationTarget

Bases: Target

model_config class-attribute instance-attribute

model_config = ConfigDict(arbitrary_types_allowed=True)

label instance-attribute

label: Series

value instance-attribute

value: Series

encoding instance-attribute

encoding: Series

from_iterable classmethod

from_iterable(data: Iterable) -> ClassificationTarget
PARAMETER DESCRIPTION
data

TYPE: Iterable

Source code in siapy/datasets/schemas.py
59
60
61
62
@classmethod
def from_iterable(cls, data: Iterable) -> "ClassificationTarget":
    label = pd.DataFrame(data, columns=["label"])
    return generate_classification_target(label, "label")

from_dict classmethod

from_dict(data: dict[str, Any]) -> ClassificationTarget
PARAMETER DESCRIPTION
data

TYPE: dict[str, Any]

Source code in siapy/datasets/schemas.py
64
65
66
67
68
69
@classmethod
def from_dict(cls, data: dict[str, Any]) -> "ClassificationTarget":
    label = pd.Series(data["label"], name="label")
    value = pd.Series(data["value"], name="value")
    encoding = pd.Series(data["encoding"], name="encoding")
    return cls(label=label, value=value, encoding=encoding)

to_dict

to_dict() -> dict[str, Any]
Source code in siapy/datasets/schemas.py
71
72
73
74
75
76
def to_dict(self) -> dict[str, Any]:
    return {
        "label": self.label.to_list(),
        "value": self.value.to_list(),
        "encoding": self.encoding.to_list(),
    }

to_dataframe

to_dataframe() -> DataFrame
Source code in siapy/datasets/schemas.py
78
79
def to_dataframe(self) -> pd.DataFrame:
    return pd.concat([self.value, self.label], axis=1)

reset_index

reset_index() -> ClassificationTarget
Source code in siapy/datasets/schemas.py
81
82
83
84
85
86
def reset_index(self) -> "ClassificationTarget":
    return ClassificationTarget(
        label=self.label.reset_index(drop=True),
        value=self.value.reset_index(drop=True),
        encoding=self.encoding,
    )

RegressionTarget

Bases: Target

model_config class-attribute instance-attribute

model_config = ConfigDict(arbitrary_types_allowed=True)

value instance-attribute

value: Series

name instance-attribute

name: str

from_iterable classmethod

from_iterable(data: Iterable) -> RegressionTarget
PARAMETER DESCRIPTION
data

TYPE: Iterable

Source code in siapy/datasets/schemas.py
100
101
102
103
@classmethod
def from_iterable(cls, data: Iterable) -> "RegressionTarget":
    value = pd.DataFrame(data, columns=["value"])
    return generate_regression_target(value, "value")

from_dict classmethod

from_dict(data: dict[str, Any]) -> RegressionTarget
PARAMETER DESCRIPTION
data

TYPE: dict[str, Any]

Source code in siapy/datasets/schemas.py
105
106
107
108
109
@classmethod
def from_dict(cls, data: dict[str, Any]) -> "RegressionTarget":
    value = pd.Series(data["value"], name="value")
    name = data["name"]
    return cls(value=value, name=name)

to_dict

to_dict() -> dict[str, Any]
Source code in siapy/datasets/schemas.py
111
112
113
114
115
def to_dict(self) -> dict[str, Any]:
    return {
        "value": self.value.to_list(),
        "name": self.name,
    }

to_dataframe

to_dataframe() -> DataFrame
Source code in siapy/datasets/schemas.py
117
118
def to_dataframe(self) -> pd.DataFrame:
    return pd.DataFrame(self.value)

reset_index

reset_index() -> RegressionTarget
Source code in siapy/datasets/schemas.py
120
121
def reset_index(self) -> "RegressionTarget":
    return RegressionTarget(value=self.value.reset_index(drop=True), name=self.name)

TabularDatasetData

TabularDatasetData(*args: Any, **kwargs: Any)

Bases: BaseModel

PARAMETER DESCRIPTION
*args

TYPE: Any DEFAULT: ()

**kwargs

TYPE: Any DEFAULT: {}

Source code in siapy/datasets/schemas.py
131
132
133
def __init__(self, *args: Any, **kwargs: Any):
    super().__init__(*args, **kwargs)
    self._validate_lengths()

model_config class-attribute instance-attribute

model_config = ConfigDict(arbitrary_types_allowed=True)

pixels instance-attribute

pixels: DataFrame

signals instance-attribute

signals: DataFrame

metadata instance-attribute

metadata: DataFrame

target class-attribute instance-attribute

target: Target | None = None

from_dict classmethod

from_dict(data: dict[str, Any]) -> TabularDatasetData
PARAMETER DESCRIPTION
data

TYPE: dict[str, Any]

Source code in siapy/datasets/schemas.py
152
153
154
155
156
157
158
@classmethod
def from_dict(cls, data: dict[str, Any]) -> "TabularDatasetData":
    pixels = pd.DataFrame(data["pixels"])
    signals = pd.DataFrame(data["signals"])
    metadata = pd.DataFrame(data["metadata"])
    target = TabularDatasetData.target_from_dict(data.get("target", None))
    return cls(pixels=pixels, signals=signals, metadata=metadata, target=target)

target_from_dict staticmethod

target_from_dict(data: dict[str, Any] | None) -> Target | None
PARAMETER DESCRIPTION
data

TYPE: dict[str, Any] | None

Source code in siapy/datasets/schemas.py
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
@staticmethod
def target_from_dict(data: dict[str, Any] | None) -> Target | None:
    if data is None:
        return None

    regression_keys = set(RegressionTarget.model_fields.keys())
    classification_keys = set(ClassificationTarget.model_fields.keys())
    data_keys = set(data.keys())

    if data_keys.issubset(regression_keys):
        return RegressionTarget.from_dict(data)
    elif data_keys.issubset(classification_keys):
        return ClassificationTarget.from_dict(data)
    else:
        raise InvalidInputError(data, "Invalid target dict.")

to_dict

to_dict() -> dict[str, Any]
Source code in siapy/datasets/schemas.py
195
196
197
198
199
200
201
def to_dict(self) -> dict[str, Any]:
    return {
        "pixels": self.pixels.to_dict(),
        "signals": self.signals.to_dict(),
        "metadata": self.metadata.to_dict(),
        "target": self.target.to_dict() if self.target is not None else None,
    }

to_dataframe

to_dataframe() -> DataFrame
Source code in siapy/datasets/schemas.py
203
204
205
206
207
208
def to_dataframe(self) -> pd.DataFrame:
    combined_df = pd.concat([self.pixels, self.signals, self.metadata], axis=1)
    if self.target is not None:
        target_series = self.target.to_dataframe()
        combined_df = pd.concat([combined_df, target_series], axis=1)
    return combined_df

reset_index

reset_index() -> TabularDatasetData
Source code in siapy/datasets/schemas.py
210
211
212
213
214
215
216
def reset_index(self) -> "TabularDatasetData":
    return TabularDatasetData(
        pixels=self.pixels.reset_index(drop=True),
        signals=self.signals.reset_index(drop=True),
        metadata=self.metadata.reset_index(drop=True),
        target=self.target.reset_index() if self.target is not None else None,
    )