# utils

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

## Functions

### find_filepath_group_id

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

Find the group ID assigned to an original file path.

> **Examples**
> ```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
```

Parameters

 * `filepath` (`PathType`): Original file path to look up.
 * `index` (`pl.DataFrame | None`): Optional dataframe containing `original_filepath` and `group_id` columns.
 * `raise_on_missing` (`bool`): Whether to raise when the path is not in the index.

Returns

 * `str | None`: Matching group ID, or `None` when `index` is `None` or the path is missing and `raise_on_missing` is `False`.

Raises

 * `ValueError`: If `raise_on_missing` is `True` and the path is not in the index.

### find_filepath_uuid

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

Find the UUID assigned to an original file path.

> **Examples**
> ```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
```

Parameters

 * `filepath` (`PathType`): Original file path to look up.
 * `index` (`pl.DataFrame | None`): Optional dataframe containing `original_filepath` and `uuid` columns.
 * `raise_on_missing` (`bool`): Whether to raise when the path is not in the index.

Returns

 * `str | None`: Matching UUID, or `None` when `index` is `None` or the path is missing and `raise_on_missing` is `False`.

Raises

 * `ValueError`: If `raise_on_missing` is `True` and the path is not in the index.

### 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:
```
