<!-- # hard line break macro for HTML -->

# fiftyone.core.map.mapper

Abstract mapping backend

Copyright 2017-2026, Voxel51, Inc.
<br/>
[voxel51.com](https://voxel51.com/)
<br/>
<br/>

**Functions:**

| [`check_if_return_is_sample`](#fiftyone.core.map.mapper.check_if_return_is_sample)(sample_collection, ...)   | Check if the map function returns a sample   |
|--------------------------------------------------------------------------------------------------------------|----------------------------------------------|

**Classes:**

| [`Mapper`](#fiftyone.core.map.mapper.Mapper)(batch_cls, num_workers[, batch_size, ...])   | Base class for mapping samples in parallel                          |
|-------------------------------------------------------------------------------------------|---------------------------------------------------------------------|
| [`LocalMapper`](#fiftyone.core.map.mapper.LocalMapper)(batch_cls, num_workers[, ...])     | Base class for mapping samples in parallelizing on the same machine |

### fiftyone.core.map.mapper.check_if_return_is_sample(sample_collection: [SampleCollection](fiftyone.core.map.typing.md#fiftyone.core.map.typing.SampleCollection)[T], map_fcn: Callable[[T], R]) → [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool)

Check if the map function returns a sample

### *class* fiftyone.core.map.mapper.Mapper(batch_cls: Type[[SampleBatch](fiftyone.core.map.batcher.batch.md#fiftyone.core.map.batcher.batch.SampleBatch)], num_workers: int, batch_size: int | None = None, default_progress: [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) | None = None)

Bases: `ABC`

Base class for mapping samples in parallel

**Methods:**

| [`create`](#fiftyone.core.map.mapper.Mapper.create)(\*, config, batch_cls[, num_workers, ...])       | Create a new mapper instance                                                |
|------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------|
| [`map_samples`](#fiftyone.core.map.mapper.Mapper.map_samples)(sample_collection, map_fcn, \*[, ...]) | Applies map function to each sample and returns an iterator of the results. |

**Attributes:**

| [`num_workers`](#fiftyone.core.map.mapper.Mapper.num_workers)   | Number of workers to use           |
|-----------------------------------------------------------------|------------------------------------|
| [`batch_size`](#fiftyone.core.map.mapper.Mapper.batch_size)     | Number of samples per worker batch |

#### *classmethod* create(, config: [FiftyOneConfig](fiftyone.core.config.md#fiftyone.core.config.FiftyOneConfig), batch_cls: Type[[SampleBatch](fiftyone.core.map.batcher.batch.md#fiftyone.core.map.batcher.batch.SampleBatch)], num_workers: int | None = None, batch_size: int | None = None, \*\*\_\_)

Create a new mapper instance

#### *property* num_workers *: int*

Number of workers to use

#### *property* batch_size *: int | None*

Number of samples per worker batch

#### map_samples(sample_collection: [SampleCollection](fiftyone.core.map.typing.md#fiftyone.core.map.typing.SampleCollection)[T], map_fcn: Callable[[T | U], R], , iter_fcn: Callable[[[SampleCollection](fiftyone.core.map.typing.md#fiftyone.core.map.typing.SampleCollection)[T]], Iterable[Tuple[[ObjectId](https://pymongo.readthedocs.io/en/stable/api/bson/objectid.html#bson.objectid.ObjectId), U]]] | None = None, progress: [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) | Literal['workers'] | None = None, save: [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) = False, skip_failures: [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) = True) → Iterator[Tuple[[ObjectId](https://pymongo.readthedocs.io/en/stable/api/bson/objectid.html#bson.objectid.ObjectId), R]]

Applies map function to each sample and returns an iterator of the
results.

* **Parameters:**
  * **sample_collection** ([*SampleCollection*](fiftyone.core.collections.md#fiftyone.core.collections.SampleCollection) *[**T* *]*) – The sample collection to
    map.
  * **map_fcn** (*Callable* *[* *[**Union* *[**T* *,* *U* *]* *]* *,* *R* *]*) – The map function to apply to
    each sample.
  * **iter_fcn** (*Callable* *[* *[**T* *]* *,* *U* *]*) – The function to iterate over the
    sample collection. If not provided the iteration function
    used is `iter_samples`.
  * **progress** (*Union* *[*[*bool*](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) *,* *Literal* *[* *"workers"* *]* *]*) – Whether or
    not and how to render progress.
  * **save** ([*bool*](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) *,* *optional*) – Whether to save mutated samples mutated in
    the map function. Only valid when using the `iter_fcn` is None.
    Defaults to False.
  * **skip_failures** ([*bool*](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) *,* *optional*) – Whether to gracefully continue
    without raising an error if the map function raises an exception
    for a sample. Defaults to True.
* **Yields:**
  *Iterator[Tuple[bson.ObjectId, R]]* –

  The sample ID and the result of
  : the map function for the sample.

### *class* fiftyone.core.map.mapper.LocalMapper(batch_cls: Type[[SampleBatch](fiftyone.core.map.batcher.batch.md#fiftyone.core.map.batcher.batch.SampleBatch)], num_workers: int, batch_size: int | None = None, default_progress: [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) | None = None)

Bases: [`Mapper`](#fiftyone.core.map.mapper.Mapper), `ABC`

Base class for mapping samples in parallelizing on the same machine

**Attributes:**

| [`batch_size`](#fiftyone.core.map.mapper.LocalMapper.batch_size)   | Number of samples per worker batch   |
|--------------------------------------------------------------------|--------------------------------------|
| [`num_workers`](#fiftyone.core.map.mapper.LocalMapper.num_workers) | Number of workers to use             |

**Methods:**

| [`create`](#fiftyone.core.map.mapper.LocalMapper.create)(\*, config, batch_cls[, num_workers, ...])       | Create a new mapper instance                                                |
|-----------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------|
| [`map_samples`](#fiftyone.core.map.mapper.LocalMapper.map_samples)(sample_collection, map_fcn, \*[, ...]) | Applies map function to each sample and returns an iterator of the results. |

#### *property* batch_size *: int | None*

Number of samples per worker batch

#### *classmethod* create(, config: [FiftyOneConfig](fiftyone.core.config.md#fiftyone.core.config.FiftyOneConfig), batch_cls: Type[[SampleBatch](fiftyone.core.map.batcher.batch.md#fiftyone.core.map.batcher.batch.SampleBatch)], num_workers: int | None = None, batch_size: int | None = None, \*\*\_\_)

Create a new mapper instance

#### map_samples(sample_collection: [SampleCollection](fiftyone.core.map.typing.md#fiftyone.core.map.typing.SampleCollection)[T], map_fcn: Callable[[T | U], R], , iter_fcn: Callable[[[SampleCollection](fiftyone.core.map.typing.md#fiftyone.core.map.typing.SampleCollection)[T]], Iterable[Tuple[[ObjectId](https://pymongo.readthedocs.io/en/stable/api/bson/objectid.html#bson.objectid.ObjectId), U]]] | None = None, progress: [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) | Literal['workers'] | None = None, save: [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) = False, skip_failures: [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) = True) → Iterator[Tuple[[ObjectId](https://pymongo.readthedocs.io/en/stable/api/bson/objectid.html#bson.objectid.ObjectId), R]]

Applies map function to each sample and returns an iterator of the
results.

* **Parameters:**
  * **sample_collection** ([*SampleCollection*](fiftyone.core.collections.md#fiftyone.core.collections.SampleCollection) *[**T* *]*) – The sample collection to
    map.
  * **map_fcn** (*Callable* *[* *[**Union* *[**T* *,* *U* *]* *]* *,* *R* *]*) – The map function to apply to
    each sample.
  * **iter_fcn** (*Callable* *[* *[**T* *]* *,* *U* *]*) – The function to iterate over the
    sample collection. If not provided the iteration function
    used is `iter_samples`.
  * **progress** (*Union* *[*[*bool*](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) *,* *Literal* *[* *"workers"* *]* *]*) – Whether or
    not and how to render progress.
  * **save** ([*bool*](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) *,* *optional*) – Whether to save mutated samples mutated in
    the map function. Only valid when using the `iter_fcn` is None.
    Defaults to False.
  * **skip_failures** ([*bool*](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) *,* *optional*) – Whether to gracefully continue
    without raising an error if the map function raises an exception
    for a sample. Defaults to True.
* **Yields:**
  *Iterator[Tuple[bson.ObjectId, R]]* –

  The sample ID and the result of
  : the map function for the sample.

#### *property* num_workers *: int*

Number of workers to use
