tableserializer.table module

Submodules

tableserializer.table.preprocessor module

class tableserializer.table.preprocessor.TablePreprocessor(apply_before_row_sampling: bool = False)[source]

Bases: ABC, SignatureProvidingInstance

A table preprocessor transforms a table before serialization. Generally, table preprocessors can augment the tabular data, compress it (e.g., by removing id columns), …

Parameters:

apply_before_row_sampling (bool) – Set to true to execute the preprocessor before the row sampling.

abstractmethod process(table: Table) → Table[source]

Transform a table before serialization.

Parameters:

table (Table) – Table to preprocess.

Returns:

Preprocessed table.

Return type:

Table

class tableserializer.table.preprocessor.ColumnDroppingPreprocessor(columns_to_drop: List[str], apply_before_row_sampling=False)[source]

Bases: TablePreprocessor

Table preprocessor that transforms a table by dropping specified columns.

Parameters:
  • columns_to_drop (List[str]) – List of column names of columns to drop.

  • apply_before_row_sampling (bool) – Set to true to execute the preprocessor before the row sampling.

process(table: Table) → Table[source]

Transform a table before serialization.

Parameters:

table (Table) – Table to preprocess.

Returns:

Preprocessed table.

Return type:

Table

class tableserializer.table.preprocessor.StringTruncationPreprocessor(max_len: int, apply_before_row_sampling=False)[source]

Bases: TablePreprocessor

Table preprocessor that truncates strings in the table to a set maximum length before serialization.

Parameters:
  • max_len (int) – Maximum length of strings for truncation.

  • apply_before_row_sampling (bool) – Set to true to execute the preprocessor before the row sampling.

process(table: Table) → Table[source]

Transform a table before serialization.

Parameters:

table (Table) – Table to preprocess.

Returns:

Preprocessed table.

Return type:

Table

tableserializer.table.row_sampler module

class tableserializer.table.row_sampler.RowSampler(rows_to_sample: int = 10)[source]

Bases: ABC, SignatureProvidingInstance

A row sampler selects a subset of rows based on a predefined policy.

Parameters:

rows_to_sample (int) – Number of rows to sample.

abstractmethod sample(table: Table) → Table[source]

Sample rows from the given table.

Parameters:

table (Table) – The table to sample from.

Returns:

Table consisting of the sampled rows.

Return type:

Table

class tableserializer.table.row_sampler.RandomRowSampler(rows_to_sample: int = 10, deterministic: bool = True)[source]

Bases: RowSampler

Samples rows randomly from the given table.

Parameters:
  • rows_to_sample (int) – Number of rows to sample.

  • deterministic (bool) – Set to true to apply a deterministic seed for the sampling process. This ensures replicability.

sample(table: Table) → Table[source]

Sample rows from the given table.

Parameters:

table (Table) – The table to sample from.

Returns:

Table consisting of the sampled rows.

Return type:

Table

class tableserializer.table.row_sampler.FirstRowSampler(rows_to_sample: int = 10)[source]

Bases: RowSampler

Sample the first rows from the given table.

Parameters:

rows_to_sample (int) – Number of rows to sample.

sample(table: Table) → Table[source]

Sample rows from the given table.

Parameters:

table (Table) – The table to sample from.

Returns:

Table consisting of the sampled rows.

Return type:

Table

class tableserializer.table.row_sampler.KMeansRowSampler(rows_to_sample: int = 10, deterministic: bool = True)[source]

Bases: RowSampler

Use k-means clustering to sample a diverse set of rows.

Parameters:
  • rows_to_sample (int) – Number of rows to sample.

  • deterministic (bool) – Set to true to apply a deterministic seed for the sampling process.

sample(table: Table) → Table[source]

Sample rows from the given table.

Parameters:

table (Table) – The table to sample from.

Returns:

Table consisting of the sampled rows.

Return type:

Table

tableserializer.table.table module

class tableserializer.table.table.Table(table_contents: DataFrame | List[Dict[str, str]] | List[List[str]])[source]

Bases: object

Represents the contents of a raw table.

Parameters:

table_contents (Union[pd.DataFrame, List[Dict[str, str]], List[List[str]]]) – Table contents in one of the supported formats.

as_list_of_lists() → List[List[str]][source]

Get the table as a list of the lists.

Returns:

Table as a list of the lists.

Return type:

List[List[str]]

as_list_of_dicts() → List[Dict[str, str]][source]

Get the table as a list of dictionaries.

Returns:

Table as a list of the dictionaries.

Return type:

List[Dict[str, str]]

as_dataframe() → DataFrame[source]

Get the table as a dataframe.

Returns:

The table as a dataframe.

Return type:

pd.DataFrame

Module contents