Skip to content

Commit

Permalink
Fixes inconsistency in new builder API
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
skrawcz committed Oct 3, 2023
1 parent 3910caf commit 100e765
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion hamilton/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions tests/test_hamilton_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}

0 comments on commit 100e765

Please sign in to comment.