Skip to content

Commit

Permalink
[Rust] Add DataFrame::pop (#1918)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibENPC committed Nov 28, 2021
1 parent d430889 commit c063007
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions polars/polars-core/src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,26 @@ impl DataFrame {
Ok(df)
}

/// Removes the last `Series` from the `DataFrame` and returns it, or [`None`] if it is empty.
///
/// # Example
///
/// ```rust
/// # use polars_core::prelude::*;
/// let s1 = Series::new("Ocean", &["Atlantic", "Indian"]);
/// let s2 = Series::new("Area (km²)", &[106_460_000, 70_560_000]);
/// let mut df = DataFrame::new(vec![s1.clone(), s2.clone()])?;
///
/// assert_eq!(df.pop(), Some(s2));
/// assert_eq!(df.pop(), Some(s1));
/// assert_eq!(df.pop(), None);
/// assert!(df.is_empty());
/// # Ok::<(), PolarsError>(())
/// ```
pub fn pop(&mut self) -> Option<Series> {
self.columns.pop()
}

/// Add a new column at index 0 that counts the rows.
///
/// # Example
Expand Down

0 comments on commit c063007

Please sign in to comment.