mirror of
https://github.com/nushell/nushell
synced 2024-11-14 00:47:09 +00:00
Dataframe support for small int types (#10828)
Turned features to allow signed and unsigned 8 and 16 bit types. --------- Co-authored-by: Jack Wright <jack.wright@disqo.com>
This commit is contained in:
parent
78b4472b32
commit
c6016d7659
2 changed files with 24 additions and 53 deletions
|
@ -38,6 +38,10 @@ features = [
|
||||||
"dtype-categorical",
|
"dtype-categorical",
|
||||||
"dtype-datetime",
|
"dtype-datetime",
|
||||||
"dtype-struct",
|
"dtype-struct",
|
||||||
|
"dtype-i8",
|
||||||
|
"dtype-i16",
|
||||||
|
"dtype-u8",
|
||||||
|
"dtype-u16",
|
||||||
"dynamic_group_by",
|
"dynamic_group_by",
|
||||||
"ipc",
|
"ipc",
|
||||||
"is_in",
|
"is_in",
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use super::super::values::{Column, NuDataFrame};
|
use super::super::values::NuDataFrame;
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
|
Category, Example, PipelineData, ShellError, Signature, Span, Type,
|
||||||
};
|
};
|
||||||
use polars::prelude::DataFrameOps;
|
use polars::{prelude::*, series::Series};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Dummies;
|
pub struct Dummies;
|
||||||
|
@ -34,24 +34,15 @@ impl Command for Dummies {
|
||||||
description: "Create new dataframe with dummy variables from a dataframe",
|
description: "Create new dataframe with dummy variables from a dataframe",
|
||||||
example: "[[a b]; [1 2] [3 4]] | dfr into-df | dfr dummies",
|
example: "[[a b]; [1 2] [3 4]] | dfr into-df | dfr dummies",
|
||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![
|
NuDataFrame::try_from_series(
|
||||||
Column::new(
|
vec![
|
||||||
"a_1".to_string(),
|
Series::new("a_1", &[1_u8, 0]),
|
||||||
vec![Value::test_int(1), Value::test_int(0)],
|
Series::new("a_3", &[0_u8, 1]),
|
||||||
),
|
Series::new("b_2", &[1_u8, 0]),
|
||||||
Column::new(
|
Series::new("b_4", &[0_u8, 1]),
|
||||||
"a_3".to_string(),
|
],
|
||||||
vec![Value::test_int(0), Value::test_int(1)],
|
Span::test_data(),
|
||||||
),
|
)
|
||||||
Column::new(
|
|
||||||
"b_2".to_string(),
|
|
||||||
vec![Value::test_int(1), Value::test_int(0)],
|
|
||||||
),
|
|
||||||
Column::new(
|
|
||||||
"b_4".to_string(),
|
|
||||||
vec![Value::test_int(0), Value::test_int(1)],
|
|
||||||
),
|
|
||||||
])
|
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::test_data()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
|
@ -60,38 +51,14 @@ impl Command for Dummies {
|
||||||
description: "Create new dataframe with dummy variables from a series",
|
description: "Create new dataframe with dummy variables from a series",
|
||||||
example: "[1 2 2 3 3] | dfr into-df | dfr dummies",
|
example: "[1 2 2 3 3] | dfr into-df | dfr dummies",
|
||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![
|
NuDataFrame::try_from_series(
|
||||||
Column::new(
|
vec![
|
||||||
"0_1".to_string(),
|
Series::new("0_1", &[1_u8, 0, 0, 0, 0]),
|
||||||
vec![
|
Series::new("0_2", &[0_u8, 1, 1, 0, 0]),
|
||||||
Value::test_int(1),
|
Series::new("0_3", &[0_u8, 0, 0, 1, 1]),
|
||||||
Value::test_int(0),
|
],
|
||||||
Value::test_int(0),
|
Span::test_data(),
|
||||||
Value::test_int(0),
|
)
|
||||||
Value::test_int(0),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
Column::new(
|
|
||||||
"0_2".to_string(),
|
|
||||||
vec![
|
|
||||||
Value::test_int(0),
|
|
||||||
Value::test_int(1),
|
|
||||||
Value::test_int(1),
|
|
||||||
Value::test_int(0),
|
|
||||||
Value::test_int(0),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
Column::new(
|
|
||||||
"0_3".to_string(),
|
|
||||||
vec![
|
|
||||||
Value::test_int(0),
|
|
||||||
Value::test_int(0),
|
|
||||||
Value::test_int(0),
|
|
||||||
Value::test_int(1),
|
|
||||||
Value::test_int(1),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
])
|
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::test_data()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in a new issue