Repository: Project-MONAI/MONAI
File: monai/transforms/transform.py (Python)

Code before:
        unpack_items: whether to unpack parameters using `*`. Defaults to False.
        log_stats: log errors when they occur in the processing pipeline. By default, this is set to False, which
            disables the logger for processing pipeline errors. Setting it to None or True will enable logging to the
            default logger name. Setting it to a string specifies the logger to which errors should be logged.
        lazy: whether to execute in lazy mode or not. See the :ref:`Lazy Resampling topic<lazy_resampling> for more
            information about lazy resampling. Defaults to None.
        overrides: optional overrides to apply to transform parameters. This parameter is ignored unless transforms
            are being executed lazily. See the :ref:`Lazy Resampling topic<lazy_resampling> for more details and
            examples of its usage.

    Raises:
        Exception: When ``transform`` raises an exception.

    Returns:
        Union[List[ReturnType], ReturnType]: The return type of `transform` or a list thereof.
    """
    try:
        if isinstance(data, (list, tuple)) and (map_items or type(map_items) is int):
            # if map_items is an int, apply the transform to each item in the list `map_items` times
            if type(map_items) is int and map_items > 0:
                return [
                    apply_transform(transform, item, map_items - 2, unpack_items, log_stats, lazy, overrides)
                    for item in data
                ]
            else:
                return [_apply_transform(transform, item, unpack_items, lazy, overrides, log_stats) for item in data]
        return _apply_transform(transform, data, unpack_items, lazy, overrides, log_stats)
    except Exception as e:
        # if in debug mode, don't swallow exception so that the breakpoint
        # appears where the exception was raised.
        if MONAIEnvVars.debug():
            raise
        if log_stats is not False and not isinstance(transform, transforms.compose.Compose):
            # log the input data information of exact transform in the transform chain
            if isinstance(log_stats, str):
                datastats = transforms.utility.array.DataStats(data_shape=False, value_range=False, name=log_stats)
            else:
                datastats = transforms.utility.array.DataStats(data_shape=False, value_range=False)
            logger = logging.getLogger(datastats._logger_name)
            logger.error(f"\n=== Transform input info -- {type(transform).__name__} ===")
            if isinstance(data, (list, tuple)):
                data = data[0]

            def _log_stats(data, prefix: str | None = "Data"):
                if isinstance(data, (np.ndarray, torch.Tensor)):
                    # log data type, shape, range for array
                    datastats(img=data, data_shape=True, value_range=True, prefix=prefix)
                else:
                    # log data type and value for other metadata
                    datastats(img=data, data_value=True, prefix=prefix)


Review comment (suggestion):
```suggestion
        map_items_ = int(map_items) if isinstance(map_items, bool) else map_items
        if isinstance(data, (list, tuple)) and map_items_ > 0:
            return [
                apply_transform(transform, item, map_items - 1, unpack_items, log_stats, lazy, overrides)
                for item in data
            ]
```

Simplified logic so that bool is considered a user friendly version of 1.

Code after:
              to the first level of items in `data`.
            - If an integer is provided, it specifies the maximum level of nesting to which the transformation
              should be recursively applied. This allows treating multi-sample transforms applied after another
              multi-sample transform while controlling how deep the mapping goes.
        unpack_items: whether to unpack parameters using `*`. Defaults to False.
        log_stats: log errors when they occur in the processing pipeline. By default, this is set to False, which
            disables the logger for processing pipeline errors. Setting it to None or True will enable logging to the
            default logger name. Setting it to a string specifies the logger to which errors should be logged.
        lazy: whether to execute in lazy mode or not. See the :ref:`Lazy Resampling topic<lazy_resampling> for more
            information about lazy resampling. Defaults to None.
        overrides: optional overrides to apply to transform parameters. This parameter is ignored unless transforms
            are being executed lazily. See the :ref:`Lazy Resampling topic<lazy_resampling> for more details and
            examples of its usage.

    Raises:
        Exception: When ``transform`` raises an exception.

    Returns:
        Union[List[ReturnType], ReturnType]: The return type of `transform` or a list thereof.
    """
    try:
        map_items_ = int(map_items) if isinstance(map_items, bool) else map_items
        if isinstance(data, (list, tuple)) and map_items_ > 0:
            return [
                apply_transform(transform, item, map_items_ - 1, unpack_items, log_stats, lazy, overrides)
                for item in data
            ]
        return _apply_transform(transform, data, unpack_items, lazy, overrides, log_stats)
    except Exception as e:
        # if in debug mode, don't swallow exception so that the breakpoint
        # appears where the exception was raised.
        if MONAIEnvVars.debug():
            raise
        if log_stats is not False and not isinstance(transform, transforms.compose.Compose):
            # log the input data information of exact transform in the transform chain
            if isinstance(log_stats, str):
                datastats = transforms.utility.array.DataStats(data_shape=False, value_range=False, name=log_stats)
            else:
                datastats = transforms.utility.array.DataStats(data_shape=False, value_range=False)
            logger = logging.getLogger(datastats._logger_name)
            logger.error(f"\n=== Transform input info -- {type(transform).__name__} ===")
            if isinstance(data, (list, tuple)):
                data = data[0]

            def _log_stats(data, prefix: str | None = "Data"):
                if isinstance(data, (np.ndarray, torch.Tensor)):
                    # log data type, shape, range for array
                    datastats(img=data, data_shape=True, value_range=True, prefix=prefix)
                else:
                    # log data type and value for other metadata
                    datastats(img=data, data_value=True, prefix=prefix)