ds_common_placeholder_py_lib.functions.tables ============================================= .. py:module:: ds_common_placeholder_py_lib.functions.tables .. autoapi-nested-parse:: **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 ---------- .. autoapisummary:: 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 Functions --------- .. autoapisummary:: ds_common_placeholder_py_lib.functions.tables.json_value ds_common_placeholder_py_lib.functions.tables.get_column_as_list ds_common_placeholder_py_lib.functions.tables.get_value_from_dataframe ds_common_placeholder_py_lib.functions.tables.frame_rows ds_common_placeholder_py_lib.functions.tables.dataframe_to_json_array ds_common_placeholder_py_lib.functions.tables.json_parse Module Contents --------------- .. py:function:: json_value(value: Any) -> Any *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. .. py:function:: get_column_as_list(args: list[Any]) -> list[Any] 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). :raises PlaceholderError: ``type`` if the table is not one. .. py:function:: get_value_from_dataframe(args: list[Any]) -> Any 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). :raises PlaceholderError: ``argument`` if *index* is not an integer or the frame's row labels are not unique or not single-level. .. py:function:: frame_rows(table: Any) -> list[dict[str, Any]] A DataFrame's rows as objects, column labels as text (as the other functions address them; unique: ``_table``). .. py:function:: dataframe_to_json_array(args: list[Any]) -> str 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 MissingValue: For no value (``missing_value``). :raises PlaceholderError: ``type`` if it is not a table, or a cell is not JSON. .. py:function:: json_parse(args: list[Any]) -> Any Parse a JSON text. :raises MissingValue: For no value (``missing_value``). :raises PlaceholderError: ``type`` if the value is not a string, ``argument`` if it is not JSON. .. py:data:: is_empty .. py:data:: is_string_empty .. py:data:: is_list_empty .. py:data:: is_dict_empty .. py:data:: is_dataframe_empty