From 100e765720bda649aff69cea9d260ee3ccc77bc0 Mon Sep 17 00:00:00 2001 From: Stefan Krawczyk Date: Tue, 3 Oct 2023 14:23:31 -0700 Subject: [PATCH] Fixes inconsistency in new builder API The default should be a dictionary adapter. In the case that you were not using the "V2" functionality there was a typo and it would not set the adapter to the dictionary one, instead passing in None, and therefore defaulting to the dataframe adapter. --- hamilton/driver.py | 4 +++- tests/test_hamilton_driver.py | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/hamilton/driver.py b/hamilton/driver.py index 8e77a182b..0b5046186 100644 --- a/hamilton/driver.py +++ b/hamilton/driver.py @@ -1195,11 +1195,13 @@ def build(self) -> Driver: """Builds the driver -- note that this can return a different class, so you'll likely want to have a sense of what it returns. + Note: this defaults to a dictionary adapter if no adapter is set. + :return: The driver you specified. """ adapter = self.adapter if self.adapter is not None else base.DefaultAdapter() if not self.v2_executor: - return Driver(self.config, *self.modules, adapter=self.adapter) + return Driver(self.config, *self.modules, adapter=adapter) execution_manager = self.execution_manager if execution_manager is None: local_executor = self.local_executor or executors.SynchronousLocalTaskExecutor() diff --git a/tests/test_hamilton_driver.py b/tests/test_hamilton_driver.py index 22e040d60..7344859a8 100644 --- a/tests/test_hamilton_driver.py +++ b/tests/test_hamilton_driver.py @@ -4,6 +4,7 @@ import pytest import tests.resources.cyclic_functions +import tests.resources.dummy_functions import tests.resources.dynamic_parallelism.parallel_linear_basic import tests.resources.tagging import tests.resources.test_default_args @@ -445,3 +446,10 @@ def test_executor_validates_happy_parallel_executor(): nodes, user_nodes = dr.graph.get_upstream_nodes(["final"]) dr.graph_executor.validate(nodes | user_nodes) + + +def test_builder_defaults_to_dict_result(): + dr = Builder().with_modules(tests.resources.dummy_functions).build() + + result = dr.execute(["C"], inputs={"b": 1, "c": 1}) + assert result == {"C": 4}