Exemplo n.º 1
0
 def test_input_not_dataframe(self):
     '''
     Test function raises error when input is not dataframe
     '''
     df_input = "some string"
     with pytest.raises(TypeError):
         df_output = specify(data=df_input, response="response")
Exemplo n.º 2
0
 def test_response_not_string(self):
     '''
     Test function raises error when response is not a string
     '''
     df_input = pd.DataFrame(columns=["response", "unused_col"],
                             data=[[1,2],[2,3],[3,4]])
     response = 5
     with pytest.raises(TypeError):
         df_output = specify(data=df_input, response=response)
Exemplo n.º 3
0
 def test_wrong_response_col(self):
     '''
     Test that function raises error if provided response column is not
     in dataframe
     '''
     df_input = pd.DataFrame(columns=["response", "unused_col"],
                             data=[[1,2],[2,3],[3,4]])
     with pytest.raises(Exception):
         df_output = specify(data=df_input, response="asdfasdf")
Exemplo n.º 4
0
    def test_expected_output(self):
        '''
        Test that the resulting dataframe is returning the expected column(s)
        '''
        df_input = pd.DataFrame(columns=["response", "unused_col"],
                                data=[[1,2],[2,3],[3,4]])
        df_output = specify(data=df_input, response="response")

        assert df_output.columns.tolist() == ["response"]
Exemplo n.º 5
0
    def test_output_shape(self):
        '''
        Test that the output dataframe is of correct shape
        (response columns plus explanatory variables)
        '''
        df_input = pd.DataFrame(columns=["response", "unused_col",
                                         "explan1", "explan2", "unused_col2"],
                                data=[[1,2,3,4,5],
                                      [2,3,4,5,6],
                                      [3,4,5,6,7]])
        df_output = specify(data=df_input,
                            response="response",
                            explanatory=["explan1", "explan2"])

        assert df_output.shape == (len(df_input), 3)