tables_io.types

Type definitions and related functions for tables_io

Functions

table_type(→ int)

Identify the type of table we have

is_table_like(→ bool)

Test to see if an object is one of the supported table types

is_tabledict_like(→ bool)

Test to see if an object is a Mapping, (str, Table-like),

file_type(→ int)

Identify the type of file we have

tType_to_int(→ int)

Takes table type as an int or str, and converts it to the corresponding

get_table_type(→ str)

Gets the table type of a Table-like or TableDict-like object, and returns the name of that type.

Module Contents

table_type(obj) int[source]

Identify the type of table we have

Parameters:

obj (object) – The input object

Returns:

otype – The object type, one of TABULAR_FORMATS.keys()

Return type:

int

Raises:
  • TypeError – The object is not a supported type

  • IndexError – One of the columns in a Mapping is the wrong length

is_table_like(obj) bool[source]

Test to see if an object is one of the supported table types

Parameters:

obj (object) – The input object

Returns:

table-like – True is the object is Table-like, False otherwise

Return type:

bool

is_tabledict_like(obj) bool[source]

Test to see if an object is a Mapping, (str, Table-like), or TableDict-like.

Parameters:

obj (object) – The input object

Returns:

tabledict – True is the object is a Mapping, (str, Table-like), False otherwise

Return type:

bool

file_type(filepath: str, fmt: str | None = None) int[source]

Identify the type of file we have

Parameters:
  • filepath (str) – The path to the file

  • fmt (str or None) – Overrides the file extension

Returns:

otype – The object type, one of FILE_FORMATS.keys()

Return type:

int

Raises:

KeyError – The file format is not a support value

tType_to_int(tType: str | int) int[source]
Takes table type as an int or str, and converts it to the corresponding

int if it’s a str.

Parameters:

tType (Union[str, int]) – The tabular format

Returns:

The number corresponding to the tabular format

Return type:

int

Raises:

TypeError – Raised if the given str is not one of the available tabular format options.

get_table_type(obj) str[source]

Gets the table type of a Table-like or TableDict-like object, and returns the name of that type. If the object is a TableDict-like object, it will check that all Table-like objects have the same type. Will raise an error if the object is not of a supported type.

Parameters:

obj (Table-like or TableDict-like object) – The object to determine the type of.

Returns:

Name of the tabular type

Return type:

str

Raises:

TypeError – Raises a TypeError if the table is not of a supported type