Skip to content

fix: broadcast scalar receiver in fill_null when value is a column for pandas-like and pyarrow - #4009

Open
FBruzzesi wants to merge 5 commits into
mainfrom
fix/eager-lit-fill-null
Open

FBruzzesi wants to merge 5 commits into
mainfrom
fix/eager-lit-fill-null

Conversation

@FBruzzesi

Copy link
Copy Markdown
Member

Description

nw.lit(None).fill_null(nw.col("a")) (and other scalar-like receivers, e.g. nw.col("a").max()) raised on pandas-like and pyarrow when used alone, and on pandas silently returned the first value repeated when selected next to a full-length column. The receiver is now broadcast to the length of value before filling, matching Polars.

This removes the xfail on test_fill_null_scalar_receiver added in #3972 and extends it to cover both cases.


NOTE:

What type of PR is this? (check all applicable)

  • 💾 Refactor
  • ✨ Feature
  • 🐛 Bug Fix
  • 🔧 Optimization
  • 📝 Documentation
  • ✅ Test
  • 🐳 Other

@FBruzzesi FBruzzesi added fix pyarrow Issue is related to pyarrow backend pandas-like Issue is related to pandas-like backends labels Sep 29, 2026
Comment on lines +623 to +626
# `where` rather than `fillna`: pandas 3.1 deprecates filling a NumPy-backed
# literal from a nullable or pyarrow-backed `value`.
native = receiver.native
return receiver._with_native(native.where(native.notna(), value.native))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a bad idea?

Comment on lines -630 to +647
res_ser = self._with_native(
ser.fillna(value=native_value, **kwargs), preserve_broadcast=True
)
result = native.fillna(value=native_value, **kwargs)
else:
res_ser = self._with_native(
ser.ffill(limit=limit, **kwargs)
result = (
native.ffill(limit=limit, **kwargs)
if strategy == "forward"
else ser.bfill(limit=limit, **kwargs),
preserve_broadcast=True,
else native.bfill(limit=limit, **kwargs)
)
return res_ser
return self._with_native(result, preserve_broadcast=True)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing really to see here

Comment on lines +128 to +129
and self._metadata.is_scalar_like
and not value._metadata.is_scalar_like

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are just to keep the native fill_null a native op without all the extra checks

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

fix pandas-like Issue is related to pandas-like backends pyarrow Issue is related to pyarrow backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant