Skip to content

Commit

Permalink
Modify df! macro to allow for a trailing comma (#1764)
Browse files Browse the repository at this point in the history
  • Loading branch information
1aguna committed Nov 14, 2021
1 parent 3855a4a commit e4acfba
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion polars/polars-core/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ macro_rules! static_zip {

#[macro_export]
macro_rules! df {
($($col_name:expr => $slice:expr), +) => {
($($col_name:expr => $slice:expr), + $(,)?) => {
{
DataFrame::new(vec![$(Series::new($col_name, $slice),)+])
}
Expand Down Expand Up @@ -912,4 +912,22 @@ mod test {
b.chunk_id().collect::<Vec<_>>()
);
}

#[test]
fn test_df_macro_trailing_commas() -> Result<()> {
let a = df! {
"a" => &["a one", "a two"],
"b" => &["b one", "b two"],
"c" => &[1, 2]
}?;

let b = df! {
"a" => &["a one", "a two"],
"b" => &["b one", "b two"],
"c" => &[1, 2],
}?;

assert!(a.frame_equal(&b));
Ok(())
}
}

0 comments on commit e4acfba

Please sign in to comment.