Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rust, python): allow list creation of decimals #13851

Merged
merged 2 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/polars-core/src/chunked_array/builder/list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ pub fn get_list_builder(
list_capacity,
Some(inner_type_logical.clone()),
))),
#[cfg(feature = "dtype-decimal")]
DataType::Decimal(_, _) => Ok(Box::new(ListPrimitiveChunkedBuilder::<Int128Type>::new(
name,
list_capacity,
value_capacity,
inner_type_logical.clone(),
))),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would have simply expanded the match_dtype_to_logical_apply_macro but there is no Int128 dtype, so instead we have to directly supply the type here. Do we want to keep Int128 hidden or should we make a new dtype?

Copy link
Member

Choose a reason for hiding this comment

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

It should still remain hidden. Maybe we opt for supporting it one day, but not now.

_ => {
macro_rules! get_primitive_builder {
($type:ty) => {{
Expand Down
10 changes: 10 additions & 0 deletions py-polars/tests/unit/datatypes/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pickle
from datetime import date, datetime, time
from decimal import Decimal
from typing import TYPE_CHECKING, Any

import pandas as pd
Expand Down Expand Up @@ -79,6 +80,15 @@ def test_categorical() -> None:
assert out.dtype.inner.is_nested() is False # type: ignore[attr-defined]


def test_decimal() -> None:
input = [[Decimal("1.23"), Decimal("4.56")], [Decimal("7.89"), Decimal("10.11")]]
s = pl.Series(input)
assert s.dtype == pl.List(pl.Decimal)
assert s.dtype.inner == pl.Decimal # type: ignore[attr-defined]
assert s.dtype.inner.is_nested() is False # type: ignore[attr-defined]
assert s.to_list() == input


def test_cast_inner() -> None:
a = pl.Series([[1, 2]])
for t in [bool, pl.Boolean]:
Expand Down