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

feat: More dtypes supports cast to list #11025

Merged
merged 2 commits into from
Sep 11, 2023
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ xxhash-rust = { version = "0.8.6", features = ["xxh3"] }
[workspace.dependencies.arrow]
package = "arrow2"
git = "https://github.com/jorgecarleitao/arrow2"
rev = "ba6a882bc1542b0b899774b696ebea77482b5c31"
rev = "7c93e358fc400bf3c0c0219c22eefc6b38fc2d12"
# branch = ""
# version = "0.17.4"
default-features = false
Expand Down
3 changes: 2 additions & 1 deletion py-polars/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 20 additions & 7 deletions py-polars/tests/unit/datatypes/test_list.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
from __future__ import annotations

from datetime import date, datetime, time
from typing import TYPE_CHECKING, Any

import pandas as pd
import pytest

import polars as pl
from polars.testing import assert_series_equal

if TYPE_CHECKING:
from polars import PolarsDataType


def test_dtype() -> None:
# inferred
Expand Down Expand Up @@ -460,13 +464,22 @@ def test_list_recursive_categorical_cast() -> None:
assert s.to_list() == values


def test_non_nested_cast_to_list() -> None:
df = pl.DataFrame({"a": [1, 2, 3]})

df = df.with_columns([pl.col("a").cast(pl.List(pl.Int64))])

expected = pl.Series("a", [[1], [2], [3]])
assert_series_equal(df.to_series(), expected)
@pytest.mark.parametrize(
("data", "expected_data", "dtype"),
[
([1, 2], [[1], [2]], pl.Int64),
([1.0, 2.0], [[1.0], [2.0]], pl.Float64),
(["x", "y"], [["x"], ["y"]], pl.Utf8),
([True, False], [[True], [False]], pl.Boolean),
],
)
def test_non_nested_cast_to_list(
data: list[Any], expected_data: list[Any], dtype: PolarsDataType
) -> None:
s = pl.Series(data, dtype=dtype)
casted_s = s.cast(pl.List(dtype))
expected = pl.Series(expected_data, dtype=pl.List(dtype))
assert_series_equal(casted_s, expected)


def test_list_new_from_index_logical() -> None:
Expand Down
Loading