コード例 #1
0
 def _test_transform_column_calls(self, col_format):
     t = r.ColumnTransformer("color", "price", col_format=col_format)
     t._transform_column = MagicMock(return_value=[1, 1, 1])
     df = create_df_all()
     t.fit_transform(df)
     calls = [call(df, "price"), call(df, "color")]
     t._transform_column.assert_has_calls(calls, any_order=True)
コード例 #2
0
 def _test_transform_column_values(self, col_format):
     t = r.ColumnTransformer("color", "price", col_format=col_format)
     t._transform_column = MagicMock(return_value=[1, 1, 1])
     df = create_df_all()
     df_out = t.fit_transform(df)
     df_expected = pd.DataFrame({
         col_format.format("color"): [1, 1, 1],
         col_format.format("price"): [1, 1, 1],
         "amount": [1, 2, 3]
     })
     self.assertTrue(df_out.equals(df_expected))
     self.assertFalse(df.equals(df_expected))  # No changes on input df.
コード例 #3
0
 def test_inverse_transform_column_values(self):
     t = r.ColumnTransformer("color", "price", col_format="{}_out")
     t._transform_column = MagicMock(return_value=[1, 1, 1])
     t._inverse_transform_column = MagicMock(return_value=[2, 2, 2])
     df = create_df_all()
     df_out = t.fit_transform(df)
     df_out = t.inverse_transform(df_out)
     df_expected = pd.DataFrame({
         "color": [2, 2, 2],
         "price": [2, 2, 2],
         "amount": [1, 2, 3]
     })
     self.assertTrue(df_out.equals(df_expected))
     self.assertFalse(df.equals(df_expected))  # No changes on input df.
コード例 #4
0
 def test_transform_column_1_N(self):
     t = r.ColumnTransformer("color")
     t.get_column_mapping = MagicMock(
         return_value={"color": ["color1", "color2"]})
     t._transform_column = MagicMock(return_value=[[1, 2], [1, 2], [1, 2]])
     df = create_df_all()
     df_out = t.fit_transform(df)
     df_expected = pd.DataFrame({
         "color1": [1, 1, 1],
         "color2": [2, 2, 2],
         "price": [1.5, 2.5, 3.5],
         "amount": [1, 2, 3]
     })
     calls = [call(df, "color")]
     t._transform_column.assert_has_calls(calls, any_order=True)
     print(df_out)
     print(df_expected)
     self.assertTrue(df_out.equals(df_expected))