992-refactor-lookup-actions-bug-request-key-colm - #993
Conversation
|
@thomasstvr @ebhills as we discussed yesterday I made columns parameter mandatory ## Breaking change:
MigrationBefore (will now raise # Python API
wrangles.connectors.train.lookup.write(
df,
model_id='<model-id>',
action='upsert',
variant='key',
)# Recipe
write:
- train.lookup:
model_id: <model-id>
action: upsert
variant: keyAfter (explicit # Python API
wrangles.connectors.train.lookup.write(
df,
model_id='<model-id>',
columns=['Key', 'Mapping', 'Weight'],
action='upsert',
variant='key',
)# Recipe
write:
- train.lookup:
model_id: <model-id>
action: upsert
columns:
- Key
- Mapping
- Weight
variant: keyBehaviour by action
Wildcard support
columns:
- Key
- Mapping* # matches Mapping, MappingDetail, etc.Example: upsert preserving unspecified columnsModel state before upsert — columns: update_df = pd.DataFrame({
'Key': ['apple'],
'Mapping': ['green'],
'Weight': [1.0], # new column not yet in the model
})
wrangles.connectors.train.lookup.write(
update_df,
model_id='<model-id>',
columns=['Key', 'Mapping', 'Weight'],
action='upsert',
variant='key',
)Model state after upsert:
|
|
@mborodii-prog is there a series of commits that did not get pushed or am I missing something? I can't find anything about columns being required, even the tests are passing without columns (which none seem to have). |
|
@thomasstvr It's because it will be a breaking change and on one of 1:1 call with Eric we decided to postpone that change |
|
@ebhills @thomasstvr you can use recipe 'test lookup 922' for testing in QA |
929c320 to
161b962
Compare
|
Queue triage (2026-07-27)
GitHub is the status record; update this PR rather than the external spreadsheet. |
Summary
Two bugs in
train.lookupwrite actions and thelookupwrangle are resolved.Bug 1 —
upsert/insert/updatedestroyed columns not in the incoming DataFrameProblem
When running any non-overwrite action with a DataFrame that only contains a subset of the model's columns, the columns absent from the DataFrame were silently deleted from the model.
The same issue existed for
insert(new rows hadNaNin unspecified columns, which broke JSON serialisation) andupdate.Root cause
wrangles/connectors/train.py— UPSERT branch (~line 345):The same
existing_dfreference was also used in the non-key no-MatchingColumnspath (_pd.concat([existing_df, df])), which is nowexisting_df_all.For INSERT,
_pd.concatcan produceNaNfor columns absent from new rows. Addedmerged_df = merged_df.fillna('')before building the JSON payload.Bug 2 —
Keycolumn could not be requested as output in alookupwrangleProblem
Case A —
output: KeyonlyKeyis not inmetadata["settings"]["columns"](which lists only value columns).The routing fell into the "no named columns" branch, treating
Keyas an arbitrary output name and returning a full dict of all columns instead of the key string.Case B —
output: [Key, Schema]Keynot in settings cols,Schemais → routing hit the "mixture" branch →ValueError: Lookup may only contain all named or unnamed columns.Root cause
wrangles/recipe_wrangles/main.py—lookup()(~line 980):Fix
Before the routing check,
Keyentries are extracted fromwrangle_output. The routing and API call use only the remaining non-Key columns. After the lookup completes, any requestedKeyoutput column is populated directly from the input values.Applied consistently across
by_row,by_dataframe, andby_matrixmodes.Examples after fix