mirror of
https://github.com/nushell/nushell.git
synced 2025-06-12 21:16:51 +02:00
Add regex documentation/examples to polars col
(#15898)
# Description Include regular expression example and help documentation to `polars col` Co-authored-by: Jack Wright <jack.wright@nike.com>
This commit is contained in:
parent
4a9e2ac37b
commit
21d949207f
@ -8,7 +8,7 @@ use nu_protocol::{
|
|||||||
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, SyntaxShape, Type,
|
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, SyntaxShape, Type,
|
||||||
Value, record,
|
Value, record,
|
||||||
};
|
};
|
||||||
use polars::prelude::DataType;
|
use polars::{df, prelude::DataType};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ExprCol;
|
pub struct ExprCol;
|
||||||
@ -29,7 +29,7 @@ impl PluginCommand for ExprCol {
|
|||||||
.required(
|
.required(
|
||||||
"column name",
|
"column name",
|
||||||
SyntaxShape::String,
|
SyntaxShape::String,
|
||||||
"Name of column to be used. '*' can be used for all columns.",
|
"Name of column to be used. '*' can be used for all columns. Accepts regular expression input; regular expressions should start with ^ and end with $.",
|
||||||
)
|
)
|
||||||
.rest(
|
.rest(
|
||||||
"more columns",
|
"more columns",
|
||||||
@ -107,6 +107,21 @@ impl PluginCommand for ExprCol {
|
|||||||
.into_value(Span::test_data()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
Example {
|
||||||
|
description: "Select columns using a regular expression",
|
||||||
|
example: "[[ham hamburger foo bar]; [1 11 2 a] [2 22 1 b]] | polars into-df | polars select (polars col '^ham.*$') | polars collect",
|
||||||
|
result: Some(
|
||||||
|
NuDataFrame::new(
|
||||||
|
false,
|
||||||
|
df!(
|
||||||
|
"ham" => [1, 2],
|
||||||
|
"hamburger" => [11, 22],
|
||||||
|
)
|
||||||
|
.expect("should not fail to create dataframe"),
|
||||||
|
)
|
||||||
|
.into_value(Span::test_data()),
|
||||||
|
),
|
||||||
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user