mirror of
https://github.com/nushell/nushell.git
synced 2025-01-11 16:58:41 +01:00
Removed the polars dtypes command (#12577)
# Description The polars dtype command is largerly redundant since the introduction of the schema command. The schema command also has the added benefit that it's output can be used as a parameter to other schema commands: ```nushell [[a b]; [5 6] [5 7]] | polars into-df -s ($df | polars schema ``` # User-Facing Changes `polars dtypes` has been removed. Users should use `polars schema` instead. Co-authored-by: Jack Wright <jack.wright@disqo.com>
This commit is contained in:
parent
55edef5dda
commit
9fb59a6f43
@ -1,111 +0,0 @@
|
|||||||
use crate::PolarsPlugin;
|
|
||||||
|
|
||||||
use super::super::values::{Column, CustomValueSupport, NuDataFrame};
|
|
||||||
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
|
|
||||||
use nu_protocol::{
|
|
||||||
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Type, Value,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct DataTypes;
|
|
||||||
|
|
||||||
impl PluginCommand for DataTypes {
|
|
||||||
type Plugin = PolarsPlugin;
|
|
||||||
|
|
||||||
fn name(&self) -> &str {
|
|
||||||
"polars dtypes"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
|
||||||
"Show dataframe data types."
|
|
||||||
}
|
|
||||||
|
|
||||||
fn signature(&self) -> Signature {
|
|
||||||
Signature::build(self.name())
|
|
||||||
.input_output_type(
|
|
||||||
Type::Custom("dataframe".into()),
|
|
||||||
Type::Custom("dataframe".into()),
|
|
||||||
)
|
|
||||||
.category(Category::Custom("dataframe".into()))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
|
||||||
vec![Example {
|
|
||||||
description: "Dataframe dtypes",
|
|
||||||
example: "[[a b]; [1 2] [3 4]] | polars into-df | polars dtypes",
|
|
||||||
result: Some(
|
|
||||||
NuDataFrame::try_from_columns(
|
|
||||||
vec![
|
|
||||||
Column::new(
|
|
||||||
"column".to_string(),
|
|
||||||
vec![Value::test_string("a"), Value::test_string("b")],
|
|
||||||
),
|
|
||||||
Column::new(
|
|
||||||
"dtype".to_string(),
|
|
||||||
vec![Value::test_string("i64"), Value::test_string("i64")],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.expect("simple df for test should not fail")
|
|
||||||
.into_value(Span::test_data()),
|
|
||||||
),
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
|
|
||||||
fn run(
|
|
||||||
&self,
|
|
||||||
plugin: &Self::Plugin,
|
|
||||||
engine: &EngineInterface,
|
|
||||||
call: &EvaluatedCall,
|
|
||||||
input: PipelineData,
|
|
||||||
) -> Result<PipelineData, LabeledError> {
|
|
||||||
command(plugin, engine, call, input).map_err(LabeledError::from)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn command(
|
|
||||||
plugin: &PolarsPlugin,
|
|
||||||
engine: &EngineInterface,
|
|
||||||
call: &EvaluatedCall,
|
|
||||||
input: PipelineData,
|
|
||||||
) -> Result<PipelineData, ShellError> {
|
|
||||||
let df = NuDataFrame::try_from_pipeline_coerce(plugin, input, call.head)?;
|
|
||||||
|
|
||||||
let mut dtypes: Vec<Value> = Vec::new();
|
|
||||||
let names: Vec<Value> = df
|
|
||||||
.as_ref()
|
|
||||||
.get_column_names()
|
|
||||||
.iter()
|
|
||||||
.map(|v| {
|
|
||||||
let dtype = df
|
|
||||||
.as_ref()
|
|
||||||
.column(v)
|
|
||||||
.expect("using name from list of names from dataframe")
|
|
||||||
.dtype();
|
|
||||||
|
|
||||||
let dtype_str = dtype.to_string();
|
|
||||||
|
|
||||||
dtypes.push(Value::string(dtype_str, call.head));
|
|
||||||
|
|
||||||
Value::string(*v, call.head)
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let names_col = Column::new("column".to_string(), names);
|
|
||||||
let dtypes_col = Column::new("dtype".to_string(), dtypes);
|
|
||||||
|
|
||||||
let df = NuDataFrame::try_from_columns(vec![names_col, dtypes_col], None)?;
|
|
||||||
df.to_pipeline_data(plugin, engine, call.head)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod test {
|
|
||||||
use super::*;
|
|
||||||
use crate::test::test_polars_plugin_command;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_examples() -> Result<(), ShellError> {
|
|
||||||
test_polars_plugin_command(&DataTypes)
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,7 +4,6 @@ mod columns;
|
|||||||
mod drop;
|
mod drop;
|
||||||
mod drop_duplicates;
|
mod drop_duplicates;
|
||||||
mod drop_nulls;
|
mod drop_nulls;
|
||||||
mod dtypes;
|
|
||||||
mod dummies;
|
mod dummies;
|
||||||
mod filter_with;
|
mod filter_with;
|
||||||
mod first;
|
mod first;
|
||||||
@ -41,7 +40,6 @@ pub use columns::ColumnsDF;
|
|||||||
pub use drop::DropDF;
|
pub use drop::DropDF;
|
||||||
pub use drop_duplicates::DropDuplicates;
|
pub use drop_duplicates::DropDuplicates;
|
||||||
pub use drop_nulls::DropNulls;
|
pub use drop_nulls::DropNulls;
|
||||||
pub use dtypes::DataTypes;
|
|
||||||
pub use dummies::Dummies;
|
pub use dummies::Dummies;
|
||||||
pub use filter_with::FilterWith;
|
pub use filter_with::FilterWith;
|
||||||
pub use first::FirstDF;
|
pub use first::FirstDF;
|
||||||
@ -73,7 +71,6 @@ pub(crate) fn eager_commands() -> Vec<Box<dyn PluginCommand<Plugin = PolarsPlugi
|
|||||||
Box::new(AppendDF),
|
Box::new(AppendDF),
|
||||||
Box::new(CastDF),
|
Box::new(CastDF),
|
||||||
Box::new(ColumnsDF),
|
Box::new(ColumnsDF),
|
||||||
Box::new(DataTypes),
|
|
||||||
Box::new(DropDF),
|
Box::new(DropDF),
|
||||||
Box::new(DropDuplicates),
|
Box::new(DropDuplicates),
|
||||||
Box::new(DropNulls),
|
Box::new(DropNulls),
|
||||||
|
Loading…
Reference in New Issue
Block a user