Skip to content

Commit

Permalink
fix: Fix Decimal type fill_null (#19981)
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnherfst authored Nov 25, 2024
1 parent 7e78aa9 commit f0d087d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions py-polars/polars/lazyframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -5680,6 +5680,8 @@ def fill_null(
│ 4 ┆ 13.0 │
└─────┴──────┘
"""
from polars import Decimal

dtypes: Sequence[PolarsDataType] | None

if value is not None:
Expand All @@ -5703,6 +5705,7 @@ def infer_dtype(value: Any) -> PolarsDataType:
UInt64,
Float32,
Float64,
Decimal,
]
elif isinstance(value, int):
dtypes = [Int64]
Expand Down
12 changes: 12 additions & 0 deletions py-polars/tests/unit/operations/test_fill_null.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ def test_fill_null_static_schema_4843() -> None:
assert df3.collect_schema() == {"a": pl.Int64, "b": pl.Int64}


def test_fill_null_non_lit() -> None:
df = pl.DataFrame(
{
"a": pl.Series([1, None], dtype=pl.Int32),
"b": pl.Series([None, 2], dtype=pl.UInt32),
"c": pl.Series([None, 2], dtype=pl.Int64),
"d": pl.Series([None, 2], dtype=pl.Decimal),
}
)
assert df.fill_null(0).select(pl.all().null_count()).transpose().sum().item() == 0


def test_fill_null_f32_with_lit() -> None:
# ensure the literal integer does not upcast the f32 to an f64
df = pl.DataFrame({"a": [1.1, 1.2]}, schema=[("a", pl.Float32)])
Expand Down

0 comments on commit f0d087d

Please sign in to comment.