def test_should_update_the_batch_with_outcomes_in_exec_mode(self):
     values = [1, 2, 3]
     expression = FunctionExpression(lambda x: values,
                                     mode=ExecutionMode.EXEC,
                                     name="test")
     expected_batch = FrameBatch(frames=pd.DataFrame(),
                                 outcomes={"test": [1, 2, 3]})
     input_batch = FrameBatch(frames=pd.DataFrame())
     expression.evaluate(input_batch)
     self.assertEqual(expected_batch, input_batch)
    def test_should_use_the_same_function_if_not_gpu_compatible(self):
        mock_function = MagicMock(return_value=pd.DataFrame())

        expression = FunctionExpression(mock_function,
                                        mode=ExecutionMode.EXEC,
                                        name="test", is_temp=True)

        input_batch = Batch(frames=pd.DataFrame())
        expression.evaluate(input_batch)
        mock_function.assert_called()
 def test_should_update_temp_outcomes_when_is_temp_set_exec_mode(self):
     values = [1, 2, 3]
     expression = FunctionExpression(lambda x: values,
                                     mode=ExecutionMode.EXEC,
                                     name="test",
                                     is_temp=True)
     expected_batch = Batch(frames=pd.DataFrame(),
                            temp_outcomes={"test": [1, 2, 3]})
     input_batch = Batch(frames=pd.DataFrame())
     expression.evaluate(input_batch)
     self.assertEqual(expected_batch, input_batch)
    def test_should_execute_same_function_if_no_gpu(self, context):
        context_instance = context.return_value
        mock_function = MagicMock(spec=GPUCompatible,
                                  return_value=pd.DataFrame())

        context_instance.gpu_device.return_value = NO_GPU

        expression = FunctionExpression(mock_function,
                                        mode=ExecutionMode.EXEC,
                                        name="test", is_temp=True)

        input_batch = Batch(frames=pd.DataFrame())
        expression.evaluate(input_batch)
        mock_function.assert_called()
    def test_function_move_the_device_to_gpu_if_compatible(self, context):
        context_instance = context.return_value
        mock_function = MagicMock(spec=GPUCompatible)
        gpu_mock_function = Mock(return_value=pd.DataFrame())
        gpu_device_id = '2'

        mock_function.to_device.return_value = gpu_mock_function
        context_instance.gpu_device.return_value = gpu_device_id

        expression = FunctionExpression(mock_function,
                                        mode=ExecutionMode.EXEC,
                                        name="test", is_temp=True)

        input_batch = Batch(frames=pd.DataFrame())
        expression.evaluate(input_batch)
        mock_function.to_device.assert_called_with(gpu_device_id)
        gpu_mock_function.assert_called()
 def test_when_function_executor_with_a_child_should_allow_chaining(self):
     expression = FunctionExpression(lambda x: x)
     child = FunctionExpression(lambda x: list(map(lambda t: t + 1, x)))
     expression.append_child(child)
     values = [1, 2, 3]
     actual = expression.evaluate(values)
     expected = [2, 3, 4]
     self.assertEqual(expected, actual)
Exemple #7
0
 def test_when_function_executor_with_a_child_should_allow_chaining(self):
     expression = FunctionExpression(lambda x: pd.DataFrame(x))
     child = FunctionExpression(lambda x: x + 1)
     expression.append_child(child)
     values = Batch(pd.DataFrame([1, 2, 3]))
     actual = expression.evaluate(values)
     expected = Batch(pd.DataFrame([2, 3, 4]))
     self.assertEqual(expected, actual)
 def test_should_filter_function_output(self):
     expression = FunctionExpression(lambda x: x + 1, output='id')
     values = pd.DataFrame({'id': [1, 2], 'data': [1, 2]})
     actual = expression.evaluate(Batch(values))
     expected = Batch(pd.DataFrame(values['id']) + 1)
     self.assertEqual(expected, actual)
 def test_should_work_for_function_without_children_eval_mode(self):
     expression = FunctionExpression(lambda x: pd.DataFrame(x))
     values = Batch(pd.DataFrame([1, 2, 3]))
     actual = expression.evaluate(values)
     self.assertEqual(values, actual)
 def test_should_work_for_function_without_children_eval_mode(self):
     expression = FunctionExpression(lambda x: x)
     values = [1, 2, 3]
     actual = expression.evaluate(values)
     self.assertEqual(values, actual)