# Path: impyute/imputation/cs/central_tendency.py
# @wrapper.wrappers
# @wrapper.checks
# def mean(data):
#     """ Substitute missing values with the mean of that column.
# 
#     Parameters
#     ----------
#     data: numpy.ndarray
#         Data to impute.
# 
#     Returns
#     -------
#     numpy.ndarray
#         Imputed data.
# 
#     """
#     nan_xy = matrix.nan_indices(data)
#     for x_i, y_i in nan_xy:
#         row_wo_nan = data[:, [y_i]][~np.isnan(data[:, [y_i]])]
#         new_value = np.mean(row_wo_nan)
#         data[x_i][y_i] = new_value
#     return data
# 
# Path: impyute/ops/error.py
# class BadInputError(Exception):
# class BadOutputError(Exception):
# 
# Path: impyute/ops/wrapper.py
# @wraps(fn)
# def wrapper(*args, **kwargs):
#     postprocess_fn = None
#     ## convert tuple to list so args can be modified
#     args = list(args)
#     ## Either make a copy or use a pointer to the original
#     if kwargs.get('inplace'):
#         args[0] = args[0]
#     else:
#         args[0] = args[0].copy()
# 
#     ## If input data is a dataframe then cast the input to an np.array
#     ## and set an indicator flag before continuing
#     pd_DataFrame = get_pandas_df()
#     if pd_DataFrame and isinstance(args[0], pd_DataFrame):
#         postprocess_fn = pd_DataFrame
#         args[0] = args[0].values
# 
#     ## function invokation
#     results = u.execute_fn_with_args_and_or_kwargs(fn, args, kwargs)
# 
#     ## cast the output back to a DataFrame.
#     if postprocess_fn is not None:
#         results = postprocess_fn(results)
# 
#     return results


import pytest
import numpy as np
    import pandas as pd
from impyute.imputation.cs import mean
from impyute.ops import error
from impyute.ops import wrapper
def test_conform_output_not_used():
    """ If neither args passed, don't do anything"""
    assert "some input" == conform_output_dummy("some input")

def test_conform_output_valid_coerce():
    """ Check value valid and coerce invalid values"""
    arr = np.array([[1.1, 0.5], [0.2, -1]])
    actual = conform_output_dummy(
            arr,
            valid_fn=is_between_0_1,
            coerce_fn=coerce_between_0_1,
            )
    expected = np.array([[1.0, 0.5], [0.2, 0.0]])
    assert np.array_equal(expected, actual)

def test_conform_output_coerce():
    """ Coerce function doesn't run if no valid_fn passed  """
    arr = np.array([[1.1, 0.5], [0.2, -1]])
    actual = conform_output_dummy(
            arr,
            coerce_fn=coerce_between_0_1,
            )
    expected = np.array([[1.1, 0.5], [0.2, -1]])
    assert np.array_equal(expected, actual)

def test_conform_output_valid():
    """ No coerce_fn with valid_fn will raise BadOutputeError if invalid values
    encountered. First invalid value is 1.1
    """
    arr = np.array([[1.1, 0.5], [0.2, -1]])

# Path: impyute/imputation/cs/central_tendency.py
# @wrapper.wrappers
# @wrapper.checks
# def mean(data):
#     """ Substitute missing values with the mean of that column.
# 
#     Parameters
#     ----------
#     data: numpy.ndarray
#         Data to impute.
# 
#     Returns
#     -------
#     numpy.ndarray
#         Imputed data.
# 
#     """
#     nan_xy = matrix.nan_indices(data)
#     for x_i, y_i in nan_xy:
#         row_wo_nan = data[:, [y_i]][~np.isnan(data[:, [y_i]])]
#         new_value = np.mean(row_wo_nan)
#         data[x_i][y_i] = new_value
#     return data
# 
# Path: impyute/ops/error.py
# class BadInputError(Exception):
# class BadOutputError(Exception):
# 
# Path: impyute/ops/wrapper.py
# @wraps(fn)
# def wrapper(*args, **kwargs):
#     postprocess_fn = None
#     ## convert tuple to list so args can be modified
#     args = list(args)
#     ## Either make a copy or use a pointer to the original
#     if kwargs.get('inplace'):
#         args[0] = args[0]
#     else:
#         args[0] = args[0].copy()
# 
#     ## If input data is a dataframe then cast the input to an np.array
#     ## and set an indicator flag before continuing
#     pd_DataFrame = get_pandas_df()
#     if pd_DataFrame and isinstance(args[0], pd_DataFrame):
#         postprocess_fn = pd_DataFrame
#         args[0] = args[0].values
# 
#     ## function invokation
#     results = u.execute_fn_with_args_and_or_kwargs(fn, args, kwargs)
# 
#     ## cast the output back to a DataFrame.
#     if postprocess_fn is not None:
#         results = postprocess_fn(results)
# 
#     return results


# Path: test/ops/test_wrapper.py
import pytest
import numpy as np
    import pandas as pd
from impyute.imputation.cs import mean
from impyute.ops import error
from impyute.ops import wrapper

def test_conform_output_not_used():
    """ If neither args passed, don't do anything"""
    assert "some input" == conform_output_dummy("some input")

def test_conform_output_valid_coerce():
    """ Check value valid and coerce invalid values"""
    arr = np.array([[1.1, 0.5], [0.2, -1]])
    actual = conform_output_dummy(
            arr,
            valid_fn=is_between_0_1,
            coerce_fn=coerce_between_0_1,
            )
    expected = np.array([[1.0, 0.5], [0.2, 0.0]])
    assert np.array_equal(expected, actual)

def test_conform_output_coerce():
    """ Coerce function doesn't run if no valid_fn passed  """
    arr = np.array([[1.1, 0.5], [0.2, -1]])
    actual = conform_output_dummy(
            arr,
            coerce_fn=coerce_between_0_1,
            )
    expected = np.array([[1.1, 0.5], [0.2, -1]])
    assert np.array_equal(expected, actual)

def test_conform_output_valid():
    """ No coerce_fn with valid_fn will raise BadOutputeError if invalid values
    encountered. First invalid value is 1.1
    """
    arr = np.array([[1.1, 0.5], [0.2, -1]])

    with pytest.raises(error.BadOutputError) as excinfo: