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

chore(python): Switch over some of the custom Python date/time conversions to native PyO3 conversions #16203

Merged
merged 9 commits into from
May 14, 2024
Prev Previous commit
Next Next commit
Pacify clippy.
  • Loading branch information
pythonspeed committed May 13, 2024
commit b9cc59099ab64a107ebf455eb7df822f33b76746
16 changes: 8 additions & 8 deletions py-polars/src/conversion/chunked_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use pyo3::intern;
use pyo3::prelude::*;
use pyo3::types::{PyBytes, PyList, PyTuple};

use super::datetime::elapsed_offset_to_timedelta;
use super::datetime::nanos_since_midnight_to_naivetime;
use super::datetime::timestamp_to_naive_datetime;
use super::datetime::{
elapsed_offset_to_timedelta, nanos_since_midnight_to_naivetime, timestamp_to_naive_datetime,
};
use super::{decimal_to_digits, struct_dict};
use crate::prelude::*;
use crate::py_modules::UTILS;
Expand Down Expand Up @@ -90,19 +90,19 @@ impl ToPyObject for Wrap<&TimeChunked> {
}
}

pub(crate) fn time_to_pyobject_iter<'a>(
ca: &'a TimeChunked,
) -> impl 'a + ExactSizeIterator<Item = Option<NaiveTime>> {
pub(crate) fn time_to_pyobject_iter(
ca: &TimeChunked,
) -> impl '_ + ExactSizeIterator<Item = Option<NaiveTime>> {
ca.0.into_iter()
.map(move |opt_v| opt_v.map(|v| nanos_since_midnight_to_naivetime(v)))
.map(move |opt_v| opt_v.map(nanos_since_midnight_to_naivetime))
}

impl ToPyObject for Wrap<&DateChunked> {
fn to_object(&self, py: Python) -> PyObject {
let iter = self
.0
.into_iter()
.map(|opt_v| opt_v.map(|v| date32_to_date(v)));
.map(|opt_v| opt_v.map(date32_to_date));
PyList::new_bound(py, iter).into_py(py)
}
}
Expand Down