# Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License # included in the LICENSE file at the root of this repository. # # As of the Change Date specified in that file, in accordance with # the Business Source License, use of this software will be governed # by the Apache License, Version 2.0. from collections.abc import Callable from pathlib import Path from re import match import numpy as np from . import Scenario def duration_to_timedelta(duration: str) -> np.timedelta64 | None: """Converts a duration like `{time}.{frac}{unit}` to a `np.timedelta64`.""" frac_to_ns: dict[str, Callable[[str], str]] = { "s": lambda frac: frac.ljust(9, "0")[0:9], "ms": lambda frac: frac.ljust(6, "0")[0:6], "us": lambda frac: frac.ljust(3, "0")[0:3], "ns": lambda frac: "0", # ns units should not have frac } p = r"(?P