mirror of
https://github.com/nushell/nushell.git
synced 2025-08-10 06:48:17 +02:00
Dataframe with real index (#5892)
* remove extra print * dataframe with real index * corrected dataframe tests * clippy error * clippy error
This commit is contained in:
@ -34,15 +34,20 @@ impl Command for ToNu {
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
let cols = vec!["a".into(), "b".into()];
|
||||
let cols = vec!["index".into(), "a".into(), "b".into()];
|
||||
let rec_1 = Value::Record {
|
||||
cols: cols.clone(),
|
||||
vals: vec![Value::test_int(1), Value::test_int(2)],
|
||||
vals: vec![Value::test_int(0), Value::test_int(1), Value::test_int(2)],
|
||||
span: Span::test_data(),
|
||||
};
|
||||
let rec_2 = Value::Record {
|
||||
cols: cols.clone(),
|
||||
vals: vec![Value::test_int(1), Value::test_int(3), Value::test_int(4)],
|
||||
span: Span::test_data(),
|
||||
};
|
||||
let rec_3 = Value::Record {
|
||||
cols,
|
||||
vals: vec![Value::test_int(3), Value::test_int(4)],
|
||||
vals: vec![Value::test_int(2), Value::test_int(3), Value::test_int(4)],
|
||||
span: Span::test_data(),
|
||||
};
|
||||
|
||||
@ -51,7 +56,7 @@ impl Command for ToNu {
|
||||
description: "Shows head rows from dataframe",
|
||||
example: "[[a b]; [1 2] [3 4]] | into df | into nu",
|
||||
result: Some(Value::List {
|
||||
vals: vec![rec_1, rec_2.clone()],
|
||||
vals: vec![rec_1, rec_2],
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
},
|
||||
@ -59,7 +64,7 @@ impl Command for ToNu {
|
||||
description: "Shows tail rows from dataframe",
|
||||
example: "[[a b]; [1 2] [5 6] [3 4]] | into df | into nu -t -n 1",
|
||||
result: Some(Value::List {
|
||||
vals: vec![rec_2],
|
||||
vals: vec![rec_3],
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
},
|
||||
|
@ -555,6 +555,12 @@ pub fn add_separator(values: &mut Vec<Value>, df: &DataFrame, span: Span) {
|
||||
let mut cols = vec![];
|
||||
let mut vals = vec![];
|
||||
|
||||
cols.push("index".to_string());
|
||||
vals.push(Value::String {
|
||||
val: "...".into(),
|
||||
span,
|
||||
});
|
||||
|
||||
for name in df.get_column_names() {
|
||||
cols.push(name.to_string());
|
||||
vals.push(Value::String {
|
||||
|
@ -400,10 +400,16 @@ impl NuDataFrame {
|
||||
|
||||
let values = (0..size)
|
||||
.into_iter()
|
||||
.map(|_| {
|
||||
.map(|i| {
|
||||
let mut cols = vec![];
|
||||
let mut vals = vec![];
|
||||
|
||||
cols.push("index".into());
|
||||
vals.push(Value::Int {
|
||||
val: (i + from_row) as i64,
|
||||
span,
|
||||
});
|
||||
|
||||
for (name, col) in &mut iterators {
|
||||
cols.push(name.clone());
|
||||
|
||||
|
Reference in New Issue
Block a user