# utils

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

## Functions

| Name | Description |
| --- | --- |
|
[`find_filepath_group_id`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/datasets/utils.md)
| Find the group ID assigned to an original file path. |
|
[`find_filepath_uuid`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/datasets/utils.md)
| Find the UUID assigned to an original file path. |
|
[`get_dir`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/datasets/utils.md)
| |
|
[`get_file`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/datasets/utils.md)
| |

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

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `filepath` | `PathType` | Original file path to look up. | required |
| `index` | `pl.DataFrame | None` | Optional dataframe containing `original_filepath` and `group_id` columns. | required |
| `raise_on_missing` | `bool` | Whether to raise when the path is not in the index. | `False` |

Returns

| Type | Description |
| --- | --- |
| `str | None` | Matching group ID, or `None` when `index` is `None` or the path is missing and `raise_on_missing` is `False`. |

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If `raise_on_missing` is `True` and the path is not in the index. |

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

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `filepath` | `PathType` | Original file path to look up. | required |
| `index` | `pl.DataFrame | None` | Optional dataframe containing `original_filepath` and `uuid` columns. | required |
| `raise_on_missing` | `bool` | Whether to raise when the path is not in the index. | `False` |

Returns

| Type | Description |
| --- | --- |
| `str | None` | Matching UUID, or `None` when `index` is `None` or the path is missing and `raise_on_missing` is `False`. |

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If `raise_on_missing` is `True` and the path is not in the index. |

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

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