Skip to content

Commit

Permalink
order, extra docs
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Mar 16, 2024
1 parent 2d52b1c commit 948aebc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
6 changes: 4 additions & 2 deletions crates/polars-time/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ use polars_core::prelude::PolarsResult;
///
/// e.g. '2021-01-01 03:00' -> '2021-01-01 03:00CDT'
///
/// Note: this may only return `Ok(None)` if ambiguous is Ambiguous::Null.
/// Note: this may only return `Ok(None)` if ambiguous is Ambiguous::Null
/// or if non_existent is NonExistent::Null.
/// Otherwise, it will either return `Ok(Some(NaiveDateTime))` or `PolarsError`.
/// Therefore, calling `try_localize_datetime(..., Ambiguous::Raise)?.unwrap()`
///
/// Therefore, calling `try_localize_datetime(..., Ambiguous::Raise, NonExistent::Raise)?.unwrap()`
/// is safe, and will never panic.
#[cfg(feature = "timezones")]
pub(crate) fn try_localize_datetime(
Expand Down
30 changes: 15 additions & 15 deletions py-polars/src/conversion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,21 +712,6 @@ impl FromPyObject<'_> for Wrap<ClosedWindow> {
}
}

impl FromPyObject<'_> for Wrap<NonExistent> {
fn extract(ob: &PyAny) -> PyResult<Self> {
let parsed = match ob.extract::<&str>()? {
"null" => NonExistent::Null,
"raise" => NonExistent::Raise,
v => {
return Err(PyValueError::new_err(format!(
"`non_existent` must be one of {{'null', 'raise'}}, got {v}",
)))
},
};
Ok(Wrap(parsed))
}
}

#[cfg(feature = "csv")]
impl FromPyObject<'_> for Wrap<CsvEncoding> {
fn extract(ob: &PyAny) -> PyResult<Self> {
Expand Down Expand Up @@ -812,6 +797,21 @@ impl FromPyObject<'_> for Wrap<ListToStructWidthStrategy> {
}
}

impl FromPyObject<'_> for Wrap<NonExistent> {
fn extract(ob: &PyAny) -> PyResult<Self> {
let parsed = match ob.extract::<&str>()? {
"null" => NonExistent::Null,
"raise" => NonExistent::Raise,
v => {
return Err(PyValueError::new_err(format!(
"`non_existent` must be one of {{'null', 'raise'}}, got {v}",
)))
},
};
Ok(Wrap(parsed))
}
}

impl FromPyObject<'_> for Wrap<NullBehavior> {
fn extract(ob: &PyAny) -> PyResult<Self> {
let parsed = match ob.extract::<&str>()? {
Expand Down

0 comments on commit 948aebc

Please sign in to comment.