Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ def_data_pipeline(py::module_ &data_module)
return self;
},
py::arg("threshold"),
py::arg("fn"),
py::arg("cost_fn"),
py::arg("bucket_creation_fn") = std::nullopt,
py::arg("min_num_examples") = std::nullopt,
py::arg("max_num_examples") = std::nullopt,
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/data/data_pipeline/test_dynamic_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,22 @@ def test_op_saves_and_restores_its_state(self) -> None:

with pytest.raises(StopIteration):
next(iter(pipeline))

def test_op_works_when_cost_fn_is_passed_as_kwarg(self) -> None:
# Regression for #1103: the binding used to expose this kwarg as `fn`.
seq = list(range(1, 7))

pipeline = (
read_sequence(seq)
.dynamic_bucket(threshold=6, cost_fn=lambda x: x)
.and_return()
)

it = iter(pipeline)

assert next(it) == [1, 2, 3]
assert next(it) == [4, 5]
assert next(it) == [6]

with pytest.raises(StopIteration):
next(it)