Skip to content

[Repo Assist] Fix Frame.fillMissingWith to handle numeric type widening (issue #250)#632

Merged
dsyme merged 2 commits intomasterfrom
repo-assist/fix-issue-250-fillmissing-type-coercion-6911f80f80cdb899
Mar 17, 2026
Merged

[Repo Assist] Fix Frame.fillMissingWith to handle numeric type widening (issue #250)#632
dsyme merged 2 commits intomasterfrom
repo-assist/fix-issue-250-fillmissing-type-coercion-6911f80f80cdb899

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated fix from Repo Assist.

Closes #250

Root cause

Frame.fillMissingWith was implemented using ColumnApply<'T>, which attempts to cast each column to the fill value's type 'T using a safe conversion. When filling with an integer 0 ('T = int) but the frame contains float columns, the safe cast float → int fails (it would be lossy), so the column was silently skipped — leaving missing values unfilled.

Fix

A two-pass strategy is applied inside fillMissingWith:

  1. First pass (existing behaviour): ColumnApply<'T> converts columns whose element type can be safely widened to 'T. For example, decimal columns are converted to float when 'T = float, preserving the previously-tested behaviour.

  2. Second pass (new): VectorHelpers.transformColumn with VectorFillMissing.Constant (box value) is applied to the result. In ArrayVector, when the boxed fill value's type does not match the vector element type 'T, the code now attempts a safe numeric widening of the fill value to 'T (e.g. int 0float 0.0). If the conversion is not safe (e.g. trying to fill a string column with an int), the column is left unchanged.

Changes

File Change
src/Deedle/FrameModule.fs Two-pass implementation of fillMissingWith; updated XML doc
src/Deedle/Vectors/ArrayVector.fs Handle VectorFillMissing.Constant when fill value type doesn't match vector type; try safe conversion, leave unchanged on failure
tests/Deedle.Tests/Frame.fs Regression test for issue #250

Test Status

✅ Build succeeded (0 errors, 4 pre-existing warnings)
✅ All 589 tests passed (dotnet test tests/Deedle.Tests/Deedle.Tests.fsproj -c Release)

Generated by Repo Assist for issue #250 ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@30f2254f2a7a944da1224df45d181a3f8faefd0d

When calling Frame.fillMissingWith with an integer fill value (e.g. 0),
missing float values were not filled because ColumnApply<int> tried to
convert the float column to int (which is not a safe conversion) and
skipped the column entirely.

Fix: apply a two-pass strategy in fillMissingWith:
1. First pass (existing behavior): ColumnApply<'T> converts columns whose
   type can be safely widened to 'T. This preserves existing behaviour
   (e.g. decimal columns are converted to float when 'T = float).
2. Second pass (new): run transformColumn with VectorFillMissing.Constant
   on the result. In ArrayVector, when the boxed fill value does not
   type-match the vector's element type, attempt a safe numeric widening
   conversion of the fill value (e.g. int -> float). If not possible,
   the column is left unchanged.

Includes regression test reproducing the scenario from issue #250.

Co-authored-by: Copilot <[email protected]>
@dsyme dsyme marked this pull request as ready for review March 17, 2026 00:46
@dsyme dsyme merged commit 808b7ff into master Mar 17, 2026
2 checks passed
@dsyme dsyme deleted the repo-assist/fix-issue-250-fillmissing-type-coercion-6911f80f80cdb899 branch March 17, 2026 00:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Buggy Frame.FillMissing behavior?

1 participant