ds_provider_unimicro_py_lib.utils

File: __init__.py Region: ds_provider_unimicro_py_lib/utils

Shared utilities for the Unimicro provider.

Submodules

Attributes

RESERVED_PARAMS

Functions

project_fields(→ pandas.DataFrame)

Restrict the output to fields (ignoring names that are not present), if configured.

build_checkpoint(→ dict[str, Any])

Build a checkpoint dictionary to track the last successfully read page.

build_incremental_filter(→ str)

Build the provider-specific incremental filter.

greatest_incremental_value(→ str | None)

Determine the greatest incremental value (last modified date) from the fetched records.

expand_combinations(→ list[dict[str, int]])

Build the cartesian product of the expand values.

expand_int_values(→ list[int])

Normalize an int, start-end range string, or list of ints into a list of ints.

Package Contents

ds_provider_unimicro_py_lib.utils.project_fields(output: pandas.DataFrame, fields: list[str] | None) → pandas.DataFrame[source]

Restrict the output to fields (ignoring names that are not present), if configured.

Parameters:
  • output – The normalized output dataframe.

  • fields – Column names to keep, in the requested order. None or empty keeps everything.

Returns:

The projected dataframe, or the input unchanged when fields is not set. If none of the requested fields exist, an empty frame with the same index is returned.

Return type:

pd.DataFrame

ds_provider_unimicro_py_lib.utils.build_checkpoint(last_loaded_records: int | None, last_modified_date: str | None) → dict[str, Any][source]

Build a checkpoint dictionary to track the last successfully read page.

Parameters:
  • last_loaded_records (int | None) – The number of records that were successfully read (records to skip).

  • last_modified_date (str | None) – The last modified date to include in the checkpoint.

Returns:

A checkpoint dictionary containing the incremental and pagination values.

Return type:

dict[str, Any]

ds_provider_unimicro_py_lib.utils.build_incremental_filter(last_modified_date: str) → str[source]

Build the provider-specific incremental filter.

Parameters:

last_modified_date – Watermark; only records created or updated after it are selected.

Returns:

Filter clause matching records with CreatedAt or UpdatedAt after the watermark.

Return type:

str

ds_provider_unimicro_py_lib.utils.greatest_incremental_value(records: pandas.DataFrame) → str | None[source]

Determine the greatest incremental value (last modified date) from the fetched records.

Parameters:

records (pd.DataFrame) – The dataframe of all fetched records.

Returns:

The greatest ISO-8601 timestamp found in CreatedAt/UpdatedAt, or None if there are no valid timestamps.

Return type:

str | None

ds_provider_unimicro_py_lib.utils.RESERVED_PARAMS
ds_provider_unimicro_py_lib.utils.expand_combinations(expand: dict[str, list[int] | int | str] | None) → list[dict[str, int]][source]

Build the cartesian product of the expand values.

Parameters:

expand – Mapping of parameter name to an int, list of ints, or start-end range string.

Returns:

One parameter mapping per request. [{}] when expand is empty or None, so callers always make at least one request.

Return type:

list[dict[str, int]]

ds_provider_unimicro_py_lib.utils.expand_int_values(value: int | str | list[int], *, field_name: str) → list[int][source]

Normalize an int, start-end range string, or list of ints into a list of ints.