Skip to content

utils

openml.utils #

ProgressBar #

ProgressBar()

Bases: ProgressType

Progressbar for MinIO function's progress parameter.

Source code in openml/utils.py
def __init__(self) -> None:
    self._object_name = ""
    self._progress_bar: tqdm | None = None

set_meta #

set_meta(object_name: str, total_length: int) -> None

Initializes the progress bar.

Parameters#

object_name: str Not used.

int

File size of the object in bytes.

Source code in openml/utils.py
def set_meta(self, object_name: str, total_length: int) -> None:
    """Initializes the progress bar.

    Parameters
    ----------
    object_name: str
      Not used.

    total_length: int
      File size of the object in bytes.
    """
    self._object_name = object_name
    self._progress_bar = tqdm(total=total_length, unit_scale=True, unit="B")

update #

update(length: int) -> None

Updates the progress bar.

Parameters#

length: int Number of bytes downloaded since last update call.

Source code in openml/utils.py
def update(self, length: int) -> None:
    """Updates the progress bar.

    Parameters
    ----------
    length: int
      Number of bytes downloaded since last `update` call.
    """
    if not self._progress_bar:
        raise RuntimeError("Call `set_meta` before calling `update`.")
    self._progress_bar.update(length)
    if self._progress_bar.total <= self._progress_bar.n:
        self._progress_bar.close()

extract_xml_tags #

extract_xml_tags(xml_tag_name: str, node: Mapping[str, Any], *, allow_none: bool = True) -> Any | None

Helper to extract xml tags from xmltodict.

Parameters#

xml_tag_name : str Name of the xml tag to extract from the node.

Mapping[str, Any]

Node object returned by xmltodict from which xml_tag_name should be extracted.

bool

If False, the tag needs to exist in the node. Will raise a ValueError if it does not.

Returns#

object

Source code in openml/utils.py
def extract_xml_tags(
    xml_tag_name: str,
    node: Mapping[str, Any],
    *,
    allow_none: bool = True,
) -> Any | None:
    """Helper to extract xml tags from xmltodict.

    Parameters
    ----------
    xml_tag_name : str
        Name of the xml tag to extract from the node.

    node : Mapping[str, Any]
        Node object returned by ``xmltodict`` from which ``xml_tag_name``
        should be extracted.

    allow_none : bool
        If ``False``, the tag needs to exist in the node. Will raise a
        ``ValueError`` if it does not.

    Returns
    -------
    object
    """
    if xml_tag_name in node and node[xml_tag_name] is not None:
        if isinstance(node[xml_tag_name], (dict, str)):
            return [node[xml_tag_name]]
        if isinstance(node[xml_tag_name], list):
            return node[xml_tag_name]

        raise ValueError("Received not string and non list as tag item")

    if allow_none:
        return None

    raise ValueError(f"Could not find tag '{xml_tag_name}' in node '{node!s}'")