def test_non_numeric_inputs(): with pytest.raises(TypeError): params_mle(["male", "female", "male", "female"]) with pytest.raises(TypeError): params_mle(pd.DataFrame({"var1": [1, 2, "5", "9"]})) with pytest.raises(TypeError): params_mle([True, False, True])
def test_output_type(): assert isinstance(params_mle(dummy), pd.DataFrame) assert isinstance(params_mle(matrix_type), pd.DataFrame) assert isinstance(params_mle(list_2d_type), pd.DataFrame) assert isinstance(params_mle(series_type, pd.DataFrame))
def test_empty_inputs(): with pytest.raises(AttributeError): params_mle(pd.DataFrame({"var1": [], "var2": []})) with pytest.raises(AttributeError): params_mle(list())
def test_params_mle_calc(): assert np.allclose(params_mle(dummy), expected) assert np.allclose(params_mle(series_type), expected["var1"]) assert np.allclose(params_mle(matrix_type), expected) assert np.allclose(params_mle(list_2d_type), expected)
def test_unequal_list_length(): assert np.allclose( params_mle([[0, 1, 1, -1], [-1, -1, 0, 1, np.nan, np.nan]]), expected)
def test_NA_values(): na_test = params_mle([[1, 1, np.nan], [np.nan, 2, 3]]) assert na_test.isnull().values.any() == False
def test_no_column_names(): assert list(params_mle(np.array(dummy["var1"]))) == [0] assert list(params_mle(pd.Series([0, 1, 1, -1]))) == [0] assert list(params_mle([0, 1, 1, -1])) == [0]
def test_incorrect_input_type(): with pytest.raises(TypeError): params_mle("hello") with pytest.raises(TypeError): params_mle(2.4)