diff --git a/crates/nu_plugin_polars/src/dataframe/eager/dtypes.rs b/crates/nu_plugin_polars/src/dataframe/eager/dtypes.rs deleted file mode 100644 index a45eb47749..0000000000 --- a/crates/nu_plugin_polars/src/dataframe/eager/dtypes.rs +++ /dev/null @@ -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 { - 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 { - command(plugin, engine, call, input).map_err(LabeledError::from) - } -} - -fn command( - plugin: &PolarsPlugin, - engine: &EngineInterface, - call: &EvaluatedCall, - input: PipelineData, -) -> Result { - let df = NuDataFrame::try_from_pipeline_coerce(plugin, input, call.head)?; - - let mut dtypes: Vec = Vec::new(); - let names: Vec = 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) - } -} diff --git a/crates/nu_plugin_polars/src/dataframe/eager/mod.rs b/crates/nu_plugin_polars/src/dataframe/eager/mod.rs index 33df6e5281..44dc6b7646 100644 --- a/crates/nu_plugin_polars/src/dataframe/eager/mod.rs +++ b/crates/nu_plugin_polars/src/dataframe/eager/mod.rs @@ -4,7 +4,6 @@ mod columns; mod drop; mod drop_duplicates; mod drop_nulls; -mod dtypes; mod dummies; mod filter_with; mod first; @@ -41,7 +40,6 @@ pub use columns::ColumnsDF; pub use drop::DropDF; pub use drop_duplicates::DropDuplicates; pub use drop_nulls::DropNulls; -pub use dtypes::DataTypes; pub use dummies::Dummies; pub use filter_with::FilterWith; pub use first::FirstDF; @@ -73,7 +71,6 @@ pub(crate) fn eager_commands() -> Vec