# utils

Python API: `luxonis_ml.data.datasets.utils`

## 函数

### find_filepath_group_id

```python
def find_filepath_group_id(filepath: PathType, index: pl.DataFrame | None, *, raise_on_missing: bool = False) -> str | None:
```

查找分配给原始文件路径的组 ID。

> **示例**
> ```pycon
>>> import polars as pl
>>> path = Path("image.jpg").absolute().resolve()
>>> index = pl.DataFrame(
...     {
...         "original_filepath": [str(path)],
...         "group_id": ["group-1"],
...     }
... )
>>> find_filepath_group_id(path, index)
'group-1'
>>> find_filepath_group_id(None, None) is None
True
```

参数

 * `filepath` (`PathType`): 要查找的原始文件路径。
 * `index` (`pl.DataFrame | None`): 包含 `original_filepath` 和 `group_id` 列的可选数据帧。
 * `raise_on_missing` (`bool`): 当路径不在索引中时是否引发异常。

返回

 * `str | None`: 匹配的组 ID，或者当 `index` 为 `None` 或路径缺失且 `raise_on_missing` 为 `False` 时返回 `None`。

引发

 * `ValueError`: 如果 `raise_on_missing` 为 `True` 且路径不在索引中。

### find_filepath_uuid

```python
def find_filepath_uuid(filepath: PathType, index: pl.DataFrame | None, *, raise_on_missing: bool = False) -> str | None:
```

查找分配给原始文件路径的 UUID。

> **示例**
> ```pycon
>>> import polars as pl
>>> path = Path("image.jpg").absolute().resolve()
>>> index = pl.DataFrame(
...     {
...         "original_filepath": [str(path)],
...         "uuid": ["abc"],
...     }
... )
>>> find_filepath_uuid(path, index)
'abc'
>>> find_filepath_uuid("missing.jpg", index, raise_on_missing=True)
Traceback (most recent call last):
...
ValueError: File ...missing.jpg not found in index
```

参数

 * `filepath` (`PathType`): 要查找的原始文件路径。
 * `index` (`pl.DataFrame | None`): 包含 `original_filepath` 和 `uuid` 列的可选数据帧。
 * `raise_on_missing` (`bool`): 当路径不在索引中时是否引发异常。

返回

 * `str | None`: 匹配的 UUID，或者当 `index` 为 `None` 或路径缺失且 `raise_on_missing` 为 `False` 时返回 `None`。

引发

 * `ValueError`: 如果 `raise_on_missing` 为 `True` 且路径不在索引中。

### get_dir

```python
def get_dir(fs: LuxonisFileSystem, remote_path: PosixPathType, local_dir: PathType, mlflow_instance: ModuleType | None = None, *, default: PathType | None = None) -> Path | None:
```

### get_file

```python
def get_file(fs: LuxonisFileSystem, remote_path: PosixPathType, local_path: PathType, mlflow_instance: ModuleType | None = None, default: PathType | None = None) -> Path | None:
```
