Skip to content

Fix extract_columns fill_with for columns passed as (name, doc) tuples - #1731

Open
breken-ai wants to merge 1 commit into
apache:mainfrom
breken-ai:fix/extract-columns-fill-with-docstring-tuples
Open

breken-ai wants to merge 1 commit into
apache:mainfrom
breken-ai:fix/extract-columns-fill-with-docstring-tuples

Conversation

@breken-ai

Copy link
Copy Markdown

@extract_columns accepts columns as plain names or as (name, doc) tuples. With fill_with= set, the filler looped over the raw arguments, so documented columns were never filled. It checked ("b", "doc b") in df, added a junk column named after the whole tuple, and left b missing. Requesting b then failed.

@extract_columns(("a", "doc a"), ("b", "doc b"), fill_with=0)
def df() -> pd.DataFrame:
    return pd.DataFrame({"a": [1, 2]})

dr.execute(["b"])
# InvalidDecoratorException: No such column: b produced by df.
# It only produced Index(['a', ('a', 'doc a'), ('b', 'doc b')], dtype='object')

The same call with plain names (extract_columns("a", "b", fill_with=0)) works.

Changes

  • hamilton/function_modifiers/expanders.py: extract_columns.transform_node computes the column names once (unwrapping (name, doc) tuples, as the extractor loop below already does). The sync and async df_generators use those names to fill missing columns.
  • tests/function_modifiers/test_expanders.py: two regressions (sync and async) for fill_with with documented columns.

How I tested this

  • New tests on unmodified main (661aa888): both fail. Sync: the dataframe columns are ['col_1', ('col_1', 'col_1 doc'), ('col_3', 'col_3 doc')] instead of ['col_1', 'col_3']. Async fails the same way.
  • With the fix, both pass.
  • pytest tests/function_modifiers tests/test_function_modifiers.py tests/test_end_to_end.py tests/test_hamilton_driver.py tests/test_async_driver.py: 529 passed.
  • ruff check and ruff format --check (0.15.14, the pre-commit version) are clean on the changed files. git diff --check is clean.

Notes

The filler has iterated over self.columns like this since at least 0857e5d (2023-03).

Checklist

  • PR has an informative and human-readable title (this will be pulled into the release notes)
  • Changes are limited to a single goal (no scope creep)
  • Code passed the pre-commit check & code is left cleaner/nicer than when first encountered.
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output) — no new functions
  • Placeholder code is flagged / future TODOs are captured in comments — none added
  • Project documentation has been updated if adding/changing functionality — no documented behavior changes; this makes the code match the existing docs

AI disclosure (per the ASF Generative Tooling guidance): this change was written with an AI coding tool (Claude Code, Claude Opus 5.5) working through the breken-ai account. The tool found the bug, wrote the fix and the test, and wrote this description. The commit carries a Generated-by: trailer. The diff is a small original change to existing Hamilton code and includes no third-party material. The red/green runs above are real and can be re-run from the diff. If you would rather not take AI-assisted contributions here, say so and I will close this.

extract_columns accepts columns as plain names or as (name, doc) tuples.
The fill_with path looped over the raw arguments, so with tuples it
checked `("b", "doc") in df`, added a junk column named after the tuple,
and never filled `b`. Requesting `b` then failed with "No such column".

Fill using the column names only, in both the sync and async generators.

Generated-by: Claude Code (Claude Opus 5.5)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant