Skip to content

Commit

Permalink
Added const empty initializer to DataFrame (#4187)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDan64 committed Jul 30, 2022
1 parent a20367b commit 20123fb
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion polars/polars-core/src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,18 @@ impl DataFrame {
})
}

/// Creates an empty `DataFrame` usable in a compile time context (such as static initializers).
///
/// # Example
///
/// ```rust
/// use polars_core::prelude::DataFrame;
/// static EMPTY: DataFrame = DataFrame::empty();
/// ```
pub const fn empty() -> Self {
DataFrame::new_no_checks(Vec::new())
}

/// Removes the last `Series` from the `DataFrame` and returns it, or [`None`] if it is empty.
///
/// # Example
Expand Down Expand Up @@ -383,7 +395,7 @@ impl DataFrame {
/// # Panic
/// It is the callers responsibility to uphold the contract of all `Series`
/// having an equal length, if not this may panic down the line.
pub fn new_no_checks(columns: Vec<Series>) -> DataFrame {
pub const fn new_no_checks(columns: Vec<Series>) -> DataFrame {
DataFrame { columns }
}

Expand Down

0 comments on commit 20123fb

Please sign in to comment.