ds_common_placeholder_py_lib.functions.tables

File: functions/tables.py Region: ds-common-placeholder-py-lib

Description

Functions over tables and plain values, as ds-workflow-manager’s builtins behave. A table is a JSON array of objects, or a pandas DataFrame. The package does not import pandas: a frame is recognised by its interface, and read through it without converting the whole frame.

Attributes

is_empty

is_string_empty

is_list_empty

is_dict_empty

is_dataframe_empty

Functions

json_value(value) → Any

value as plain JSON where a table library left its own types: numpy

get_column_as_list(args) → list[Any]

The distinct values of a column, in the order they first appear (as

get_value_from_dataframe(args) → Any

The value at row index and column. For a DataFrame the index is

frame_rows(table) → list[dict[str, Any]]

A DataFrame's rows as objects, column labels as text (as the other

dataframe_to_json_array(args) → str

The table's rows as a JSON array, in a string: compact, non-ASCII

json_parse(args) → Any

Parse a JSON text.

Module Contents

ds_common_placeholder_py_lib.functions.tables.json_value(value: Any) → Any[source]

value as plain JSON where a table library left its own types: numpy values as Python ones (arrays as lists), a missing value (NaN, NaT, pd.NA) or an infinite number as None, a timestamp as ISO 8601, a Decimal as a number. Anything else is returned as it is, and the caller checks that it is JSON.

ds_common_placeholder_py_lib.functions.tables.get_column_as_list(args: list[Any]) → list[Any][source]

The distinct values of a column, in the order they first appear (as the manager’s builtin does).

Raises:
  • MissingValue – For an empty table or no such column (missing_value; coalesce skips it).

  • PlaceholderError – type if the table is not one.

ds_common_placeholder_py_lib.functions.tables.get_value_from_dataframe(args: list[Any]) → Any[source]

The value at row index and column. For a DataFrame the index is its row label (as the manager’s builtin reads it), for an array the position.

Raises:
  • MissingValue – For an empty table, no such row or column (missing_value; coalesce skips it).

  • PlaceholderError – argument if index is not an integer or the frame’s row labels are not unique or not single-level.

ds_common_placeholder_py_lib.functions.tables.frame_rows(table: Any) → list[dict[str, Any]][source]

A DataFrame’s rows as objects, column labels as text (as the other functions address them; unique: _table).

ds_common_placeholder_py_lib.functions.tables.dataframe_to_json_array(args: list[Any]) → str[source]

The table’s rows as a JSON array, in a string: compact, non-ASCII escaped, a missing value as null. A DataFrame and an array of the same rows give the same text.

Raises:
ds_common_placeholder_py_lib.functions.tables.json_parse(args: list[Any]) → Any[source]

Parse a JSON text.

Raises:
ds_common_placeholder_py_lib.functions.tables.is_empty
ds_common_placeholder_py_lib.functions.tables.is_string_empty
ds_common_placeholder_py_lib.functions.tables.is_list_empty
ds_common_placeholder_py_lib.functions.tables.is_dict_empty
ds_common_placeholder_py_lib.functions.tables.is_dataframe_empty