table#

swordfish.table(data: Any = None, *, types: Dict[str, DataType | str] = None) Table#
swordfish.table(data: Any = None, *, names: List[str] = None, types: List[DataType | str] = None) Table
swordfish.table(*, types: Dict[str, DataType | str] = None, size: int = 0, capacity: int = 1) Table
swordfish.table(*, names: List[str] = None, types: List[DataType | str] = None, size: int = 0, capacity: int = 1) Table
swordfish.table(data: str) Table

Creates or retrieves a Swordfish Table using various initialization methods.

There are multiple modes of initialization:

  • If data is a string, it retrieves a shared Swordfish Table by its

    name.

  • If data is provided (and not a string), it converts the given

    Python object into a Table, optionally using types and names.

  • If names and types are provided (without data), an empty

    Table is created with the given column names, types, size, and capacity.

  • If types is provided as a dictionary (without data), an empty

    Table is created using the given column types, size, and capacity.

Parameters:
  • data (Any, optional) – The data to initialize the Table. Can be a Python dict, Pandas DataFrame, or a str referring to a shared Table. Defaults to None.

  • names (List[str], optional) – The column names for the Table (used when data is provided). Defaults to None.

  • types (Union[TypeDict, TypeList], optional) – A mapping of column names to their respective data types, or a list of types matching names. Defaults to None.

  • size (int, optional) – The initial number of rows in the Table (used when creating an empty Table). Defaults to 0.

  • capacity (int, optional) – The initial allocated capacity for storing rows in the Table (used when creating an empty Table). Defaults to 1.

Returns:

A Swordfish Table initialized based on the provided arguments.

Return type:

Table

Examples

Retrieving a shared Table by name:
>>> import swordfish as sf
>>> table = sf.table("shared_table_name")
Creating a Table from a Python dictionary with type mapping:
>>> my_dict = {
...     "id": [1, 2, 3, 4],
...     "name": ["Alice", "Bob", "Charlie", "David"],
...     "age": [25, 30, 35, 40],
... }
>>> column_types = {
...     "id": "LONG",
...     "name": "STRING",
...     "age": "INT",
... }
>>> t = sf.table(my_dict, types=column_types)
>>> t
id name    age
-- ------- ---
1  Alice   25
2  Bob     30
3  Charlie 35
4  David   40
Creating a Table using column names and types:
>>> t = sf.table(data=my_dict, names=["id", "name", "age"],
...              types=["LONG", "STRING", "INT"])
>>> t
id name    age
-- ------- ---
Creating an empty Table with column names, types, and initial size:
>>> t = sf.table(names=["id", "name", "age"], types=["INT", "STRING",
...              "INT"], size=5, capacity=10)
>>> t
id name    age
-- ------- ---
Creating an empty Table using a type dictionary:
>>> t = sf.table(types=column_types, size=5, capacity=10)
>>> t
id name    age
-- ------- ---