from typing import List
from typing import Tuple
from typing import Set
from typing import Dict


def _recursive_replace(data):
    """Searches data structure and replaces 'nan' and 'inf' with respective float values"""
    if isinstance(data, str):
        if data == "nan":
            return float("nan")
        if data == "inf":
            return float("inf")
    if isinstance(data, List):
        return [_recursive_replace(v) for v in data]
    if isinstance(data, Tuple):
        return tuple([_recursive_replace(v) for v in data])
    if isinstance(data, Set):
        return set([_recursive_replace(v) for v in data])
    if isinstance(data, Dict):
        return {k: _recursive_replace(v) for k, v in data.items()}
    return data