# Path: argos/utils/cls.py
# def check_class(obj, target_class, allow_none = False):
#     """ Checks that the  obj is a (sub)type of target_class.
#         Raises a TypeError if this is not the case.
# 
#         :param obj: object whos type is to be checked
#         :type obj: any type
#         :param target_class: target type/class
#         :type target_class: any class or type
#         :param allow_none: if true obj may be None
#         :type allow_none: boolean
#     """
#     if not isinstance(obj, target_class):
#         if not (allow_none and obj is None):
#             raise TypeError("obj must be a of type {}, got: {}"
#                             .format(target_class, type(obj)))
# 
# def is_an_array(var, allow_none=False):
#     """ Returns True if var is a numpy array.
#     """
#     return isinstance(var, np.ndarray) or (var is None and allow_none)
# 
# def check_is_an_array(var, allow_none=False):
#     """ Calls is_an_array and raises a type error if the check fails.
#     """
#     if not is_an_array(var, allow_none=allow_none):
#         raise TypeError("var must be a NumPy array, however type(var) is {}"
#                         .format(type(var)))
# 
# def array_is_structured(array):
#     """ Returns True if the array has a structured data type.
#     """
#     return bool(array.dtype.names)


import logging
import numpy as np
import numpy.ma as ma
from argos.utils.cls import check_class, is_an_array, check_is_an_array, array_is_structured
# def replace_missing_values(array, missing_value, replacement_value):
#     """ Returns a copy of the array where the missing_values are replaced with replacement_value.
#
#         If missing_value is None, nothing is replaced, a copy of the array is returned..
#         The missing_value can be Nan or infinite, these are replaced.
#
#         If array is a masked array the masked value are replaced (masked_to_regular_array).
#     """
#     if isinstance(array, ma.MaskedArray):
#         logger.debug("^^^^^^^^^^^^^^^^^^^ mask: {}".format(array.mask))
#
#         return array
#         return masked_to_regular_array(array, replacement_value=replacement_value)
#     if missing_value is None:
#         array = np.copy(array)
#     elif np.isnan(missing_value):
#         array[np.isnan(array)] = replacement_value
#     else:
#         array[array == missing_value] = replacement_value
#
#     return array


def fillValuesToNan(masked_array):
    """ Replaces the fill_values of the masked array by NaNs

        If the array is None or it does not contain floating point values, it cannot contain NaNs.
        In that case the original array is returned.
    """
    if masked_array is not None and masked_array.dtype.kind == 'f':

# Path: argos/utils/cls.py
# def check_class(obj, target_class, allow_none = False):
#     """ Checks that the  obj is a (sub)type of target_class.
#         Raises a TypeError if this is not the case.
# 
#         :param obj: object whos type is to be checked
#         :type obj: any type
#         :param target_class: target type/class
#         :type target_class: any class or type
#         :param allow_none: if true obj may be None
#         :type allow_none: boolean
#     """
#     if not isinstance(obj, target_class):
#         if not (allow_none and obj is None):
#             raise TypeError("obj must be a of type {}, got: {}"
#                             .format(target_class, type(obj)))
# 
# def is_an_array(var, allow_none=False):
#     """ Returns True if var is a numpy array.
#     """
#     return isinstance(var, np.ndarray) or (var is None and allow_none)
# 
# def check_is_an_array(var, allow_none=False):
#     """ Calls is_an_array and raises a type error if the check fails.
#     """
#     if not is_an_array(var, allow_none=allow_none):
#         raise TypeError("var must be a NumPy array, however type(var) is {}"
#                         .format(type(var)))
# 
# def array_is_structured(array):
#     """ Returns True if the array has a structured data type.
#     """
#     return bool(array.dtype.names)


# Path: argos/utils/masks.py
import logging
import numpy as np
import numpy.ma as ma
from argos.utils.cls import check_class, is_an_array, check_is_an_array, array_is_structured

# def replace_missing_values(array, missing_value, replacement_value):
#     """ Returns a copy of the array where the missing_values are replaced with replacement_value.
#
#         If missing_value is None, nothing is replaced, a copy of the array is returned..
#         The missing_value can be Nan or infinite, these are replaced.
#
#         If array is a masked array the masked value are replaced (masked_to_regular_array).
#     """
#     if isinstance(array, ma.MaskedArray):
#         logger.debug("^^^^^^^^^^^^^^^^^^^ mask: {}".format(array.mask))
#
#         return array
#         return masked_to_regular_array(array, replacement_value=replacement_value)
#     if missing_value is None:
#         array = np.copy(array)
#     elif np.isnan(missing_value):
#         array[np.isnan(array)] = replacement_value
#     else:
#         array[array == missing_value] = replacement_value
#
#     return array


def fillValuesToNan(masked_array):
    """ Replaces the fill_values of the masked array by NaNs

        If the array is None or it does not contain floating point values, it cannot contain NaNs.
        In that case the original array is returned.
    """
    if masked_array is not None and masked_array.dtype.kind == 'f':

        check_class(masked_array, ma.masked_array)