Esempio 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")
Esempio 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)
Esempio 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")
Esempio 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"]
Esempio 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)