import numbers
import math
from warnings import warn


def clean_nan_values(inputs: dict) -> dict:
    """
    Recursively replace NaN, Inf values (np.float) into None in place.

    This is because AiiDA does not support serializing these values
    as node attributes.
    """
    for key, value in inputs.items():
        if isinstance(value, dict):
            clean_nan_values(value)
        if isinstance(value, numbers.Real) and (math.isnan(value) or math.isinf(value)):
            warn('Key <{}> has value <{}> replaced by <{}>'.format(key, value, str(value)))
            inputs[key] = str(value)
    return inputs