Dataframe with real index (#5892)

* remove extra print

* dataframe with real index

* corrected dataframe tests

* clippy error

* clippy error
This commit is contained in:
Fernando Herrera
2022-06-26 17:32:18 -05:00
committed by GitHub
parent d3e84daa49
commit c0901ef707
4 changed files with 43 additions and 7 deletions

View File

@ -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(),
}),
},

View File

@ -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 {

View File

@ -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());