ds_provider_unimicro_py_lib.utils ================================= .. py:module:: ds_provider_unimicro_py_lib.utils .. autoapi-nested-parse:: **File:** ``__init__.py`` **Region:** ``ds_provider_unimicro_py_lib/utils`` Shared utilities for the Unimicro provider. Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/ds_provider_unimicro_py_lib/utils/dataframe/index /autoapi/ds_provider_unimicro_py_lib/utils/incremental/index /autoapi/ds_provider_unimicro_py_lib/utils/params/index /autoapi/ds_provider_unimicro_py_lib/utils/ranges/index Attributes ---------- .. autoapisummary:: ds_provider_unimicro_py_lib.utils.RESERVED_PARAMS Functions --------- .. autoapisummary:: ds_provider_unimicro_py_lib.utils.project_fields ds_provider_unimicro_py_lib.utils.build_checkpoint ds_provider_unimicro_py_lib.utils.build_incremental_filter ds_provider_unimicro_py_lib.utils.greatest_incremental_value ds_provider_unimicro_py_lib.utils.expand_combinations ds_provider_unimicro_py_lib.utils.expand_int_values Package Contents ---------------- .. py:function:: project_fields(output: pandas.DataFrame, fields: list[str] | None) -> pandas.DataFrame Restrict the output to ``fields`` (ignoring names that are not present), if configured. :param output: The normalized output dataframe. :param 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. :rtype: pd.DataFrame .. py:function:: build_checkpoint(last_loaded_records: int | None, last_modified_date: str | None) -> dict[str, Any] Build a checkpoint dictionary to track the last successfully read page. :param last_loaded_records: The number of records that were successfully read (records to skip). :type last_loaded_records: int | None :param last_modified_date: The last modified date to include in the checkpoint. :type last_modified_date: str | None :returns: A checkpoint dictionary containing the incremental and pagination values. :rtype: dict[str, Any] .. py:function:: build_incremental_filter(last_modified_date: str) -> str Build the provider-specific incremental filter. :param 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. :rtype: str .. py:function:: greatest_incremental_value(records: pandas.DataFrame) -> str | None Determine the greatest incremental value (last modified date) from the fetched records. :param records: The dataframe of all fetched records. :type records: pd.DataFrame :returns: The greatest ISO-8601 timestamp found in ``CreatedAt``/``UpdatedAt``, or None if there are no valid timestamps. :rtype: str | None .. py:data:: RESERVED_PARAMS .. py:function:: expand_combinations(expand: dict[str, list[int] | int | str] | None) -> list[dict[str, int]] Build the cartesian product of the ``expand`` values. :param 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. :rtype: list[dict[str, int]] .. py:function:: expand_int_values(value: int | str | list[int], *, field_name: str) -> list[int] Normalize an int, ``start-end`` range string, or list of ints into a list of ints.