Spaces:
Sleeping
Sleeping
File size: 2,021 Bytes
34c2609 |
1 2 3 4 5 6 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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
from typing import Any, Literal, Optional, Union
from pandas import DataFrame
class Table:
"""
Initializes a Table object.
Args:
columns (`list[str]`, *optional*, defaults to `None`):
Names of the columns in the table. Optional if `data` is provided. Not
expected if `dataframe` is provided. Currently ignored.
data (`list[list[Any]]`, *optional*, defaults to `None`):
2D row-oriented array of values.
dataframe (`pandas.`DataFrame``, *optional*, defaults to `None`):
DataFrame object used to create the table. When set, `data` and `columns`
arguments are ignored.
rows (`list[list[any]]`, *optional*, defaults to `None`):
Currently ignored.
optional (`bool` or `list[bool]`, *optional*, defaults to `True`):
Currently ignored.
allow_mixed_types (`bool`, *optional*, defaults to `False`):
Currently ignored.
log_mode: (`Literal["IMMUTABLE", "MUTABLE", "INCREMENTAL"]` or `None`, *optional*, defaults to `"IMMUTABLE"`):
Currently ignored.
"""
TYPE = "trackio.table"
def __init__(
self,
columns: Optional[list[str]] = None,
data: Optional[list[list[Any]]] = None,
dataframe: Optional[DataFrame] = None,
rows: Optional[list[list[Any]]] = None,
optional: Union[bool, list[bool]] = True,
allow_mixed_types: bool = False,
log_mode: Optional[
Literal["IMMUTABLE", "MUTABLE", "INCREMENTAL"]
] = "IMMUTABLE",
):
# TODO: implement support for columns, dtype, optional, allow_mixed_types, and log_mode.
# for now (like `rows`) they are included for API compat but don't do anything.
if dataframe is None:
self.data = data
else:
self.data = dataframe.to_dict(orient="records")
def _to_dict(self):
return {
"_type": self.TYPE,
"_value": self.data,
}
|