Skip to content

Commit

Permalink
struct logical type arrow conversion (#3193)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Apr 20, 2022
1 parent aa03cac commit 0f00810
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions polars/polars-core/src/chunked_array/logical/struct_/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ pub struct StructChunked {
}

/// Returns an ['ArrayRef'](arrow::array::ArrayRef) for a given
/// [`Series`], handling nested Struct-type series seperately.
/// [`Series`], handling nested Struct-type series separately.
fn array_ref_for_series(series: &Series) -> ArrayRef {
match series.dtype() {
DataType::Struct(_) => {
let s = series.struct_().unwrap();
s.arrow_array.clone()
}
_ => series.chunks()[0].clone() as ArrayRef,
_ => series.to_arrow(0),
}
}

Expand Down
8 changes: 8 additions & 0 deletions py-polars/tests/test_struct.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime

import pandas as pd
import pytest

Expand Down Expand Up @@ -172,3 +174,9 @@ def test_struct_to_pandas() -> None:
assert isinstance(pl_df.dtypes[0], pl.datatypes.Struct)

assert pl_df.to_pandas().equals(df)


def test_struct_logical_types_to_pandas() -> None:
timestamp = datetime(2022, 1, 1)
df = pd.DataFrame([{"struct": {"timestamp": timestamp}}])
assert pl.from_pandas(df).dtypes == [pl.Struct]

0 comments on commit 0f00810

Please sign in to comment.