Skip to content

Commit f0d087d

Browse files
authored
fix: Fix Decimal type fill_null (#19981)
1 parent 7e78aa9 commit f0d087d

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

py-polars/polars/lazyframe/frame.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5680,6 +5680,8 @@ def fill_null(
56805680
│ 4 ┆ 13.0 │
56815681
└─────┴──────┘
56825682
"""
5683+
from polars import Decimal
5684+
56835685
dtypes: Sequence[PolarsDataType] | None
56845686

56855687
if value is not None:
@@ -5703,6 +5705,7 @@ def infer_dtype(value: Any) -> PolarsDataType:
57035705
UInt64,
57045706
Float32,
57055707
Float64,
5708+
Decimal,
57065709
]
57075710
elif isinstance(value, int):
57085711
dtypes = [Int64]

py-polars/tests/unit/operations/test_fill_null.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ def test_fill_null_static_schema_4843() -> None:
3131
assert df3.collect_schema() == {"a": pl.Int64, "b": pl.Int64}
3232

3333

34+
def test_fill_null_non_lit() -> None:
35+
df = pl.DataFrame(
36+
{
37+
"a": pl.Series([1, None], dtype=pl.Int32),
38+
"b": pl.Series([None, 2], dtype=pl.UInt32),
39+
"c": pl.Series([None, 2], dtype=pl.Int64),
40+
"d": pl.Series([None, 2], dtype=pl.Decimal),
41+
}
42+
)
43+
assert df.fill_null(0).select(pl.all().null_count()).transpose().sum().item() == 0
44+
45+
3446
def test_fill_null_f32_with_lit() -> None:
3547
# ensure the literal integer does not upcast the f32 to an f64
3648
df = pl.DataFrame({"a": [1.1, 1.2]}, schema=[("a", pl.Float32)])

0 commit comments

Comments
 (0)