Skip to content

Commit

Permalink
fix series to arrow for dates
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jan 7, 2022
1 parent 941c49a commit 84c7a81
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion polars/polars-core/src/series/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl Series {
/// Convert a chunk in the Series to the correct Arrow type.
/// This conversion is needed because polars doesn't use a
/// 1 on 1 mapping for logical/ categoricals, etc.
pub(crate) fn to_arrow(&self, chunk_idx: usize) -> ArrayRef {
pub fn to_arrow(&self, chunk_idx: usize) -> ArrayRef {
match self.dtype() {
#[cfg(feature = "dtype-categorical")]
DataType::Categorical => {
Expand Down
3 changes: 2 additions & 1 deletion py-polars/src/series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,8 @@ impl PySeries {
let gil = Python::acquire_gil();
let py = gil.python();
let pyarrow = py.import("pyarrow")?;
arrow_interop::to_py::to_py_array(self.series.chunks()[0].clone(), py, pyarrow)

arrow_interop::to_py::to_py_array(self.series.to_arrow(0), py, pyarrow)
}

#[cfg(feature = "is_in")]
Expand Down
8 changes: 8 additions & 0 deletions py-polars/tests/test_datelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,11 @@ def test_truncate_negative_offset() -> None:
datetime(2021, 5, 1),
datetime(2021, 4, 1),
]


def test_to_arrow() -> None:
date_series = pl.Series("dates", ["2022-01-16", "2022-01-17"]).str.strptime(
pl.Date, "%Y-%m-%d"
)
arr = date_series.to_arrow()
assert arr.type == pa.date32()

0 comments on commit 84c7a81

Please sign in to comment.