mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 09:55:42 +02:00
refactor: change column names from 'Column*' to 'column*' (#4556)
This commit is contained in:
@ -119,7 +119,7 @@ fn extract_headers(value: &Value, config: &Config) -> Result<Vec<String>, ShellE
|
||||
.map(|(idx, value)| {
|
||||
let col = value.into_string("", config);
|
||||
if col.is_empty() {
|
||||
format!("Column{}", idx)
|
||||
format!("column{}", idx)
|
||||
} else {
|
||||
col
|
||||
}
|
||||
|
@ -37,12 +37,12 @@ impl Command for Rotate {
|
||||
result: Some(Value::List {
|
||||
vals: vec![
|
||||
Value::Record {
|
||||
cols: vec!["Column0".to_string(), "Column1".to_string()],
|
||||
cols: vec!["column0".to_string(), "column1".to_string()],
|
||||
vals: vec![Value::test_int(1), Value::test_string("a")],
|
||||
span: Span::test_data(),
|
||||
},
|
||||
Value::Record {
|
||||
cols: vec!["Column0".to_string(), "Column1".to_string()],
|
||||
cols: vec!["column0".to_string(), "column1".to_string()],
|
||||
vals: vec![Value::test_int(2), Value::test_string("b")],
|
||||
span: Span::test_data(),
|
||||
},
|
||||
@ -57,10 +57,10 @@ impl Command for Rotate {
|
||||
vals: vec![
|
||||
Value::Record {
|
||||
cols: vec![
|
||||
"Column0".to_string(),
|
||||
"Column1".to_string(),
|
||||
"Column2".to_string(),
|
||||
"Column3".to_string(),
|
||||
"column0".to_string(),
|
||||
"column1".to_string(),
|
||||
"column2".to_string(),
|
||||
"column3".to_string(),
|
||||
],
|
||||
vals: vec![
|
||||
Value::test_int(5),
|
||||
@ -72,10 +72,10 @@ impl Command for Rotate {
|
||||
},
|
||||
Value::Record {
|
||||
cols: vec![
|
||||
"Column0".to_string(),
|
||||
"Column1".to_string(),
|
||||
"Column2".to_string(),
|
||||
"Column3".to_string(),
|
||||
"column0".to_string(),
|
||||
"column1".to_string(),
|
||||
"column2".to_string(),
|
||||
"column3".to_string(),
|
||||
],
|
||||
vals: vec![
|
||||
Value::test_int(6),
|
||||
@ -114,12 +114,12 @@ impl Command for Rotate {
|
||||
result: Some(Value::List {
|
||||
vals: vec![
|
||||
Value::Record {
|
||||
cols: vec!["Column0".to_string(), "Column1".to_string()],
|
||||
cols: vec!["column0".to_string(), "column1".to_string()],
|
||||
vals: vec![Value::test_string("b"), Value::test_int(2)],
|
||||
span: Span::test_data(),
|
||||
},
|
||||
Value::Record {
|
||||
cols: vec!["Column0".to_string(), "Column1".to_string()],
|
||||
cols: vec!["column0".to_string(), "column1".to_string()],
|
||||
vals: vec![Value::test_string("a"), Value::test_int(1)],
|
||||
span: Span::test_data(),
|
||||
},
|
||||
@ -134,10 +134,10 @@ impl Command for Rotate {
|
||||
vals: vec![
|
||||
Value::Record {
|
||||
cols: vec![
|
||||
"Column0".to_string(),
|
||||
"Column1".to_string(),
|
||||
"Column2".to_string(),
|
||||
"Column3".to_string(),
|
||||
"column0".to_string(),
|
||||
"column1".to_string(),
|
||||
"column2".to_string(),
|
||||
"column3".to_string(),
|
||||
],
|
||||
vals: vec![
|
||||
Value::test_string("b"),
|
||||
@ -149,10 +149,10 @@ impl Command for Rotate {
|
||||
},
|
||||
Value::Record {
|
||||
cols: vec![
|
||||
"Column0".to_string(),
|
||||
"Column1".to_string(),
|
||||
"Column2".to_string(),
|
||||
"Column3".to_string(),
|
||||
"column0".to_string(),
|
||||
"column1".to_string(),
|
||||
"column2".to_string(),
|
||||
"column3".to_string(),
|
||||
],
|
||||
vals: vec![
|
||||
Value::test_string("a"),
|
||||
@ -260,11 +260,11 @@ pub fn rotate(
|
||||
*total_rows -= 1;
|
||||
}
|
||||
|
||||
// holder for the new column names, particularly if none are provided by the user we create names as Column0, Column1, etc.
|
||||
// holder for the new column names, particularly if none are provided by the user we create names as column0, column1, etc.
|
||||
let mut new_column_names = {
|
||||
let mut res = vec![];
|
||||
for idx in 0..(*total_rows + 1) {
|
||||
res.push(format!("Column{}", idx));
|
||||
res.push(format!("column{}", idx));
|
||||
}
|
||||
res.to_vec()
|
||||
};
|
||||
|
@ -63,12 +63,12 @@ impl Command for Transpose {
|
||||
result: Some(Value::List {
|
||||
vals: vec![
|
||||
Value::Record {
|
||||
cols: vec!["Column0".to_string(), "Column1".to_string()],
|
||||
cols: vec!["column0".to_string(), "column1".to_string()],
|
||||
vals: vec![Value::test_string("c1"), Value::test_int(1)],
|
||||
span,
|
||||
},
|
||||
Value::Record {
|
||||
cols: vec!["Column0".to_string(), "Column1".to_string()],
|
||||
cols: vec!["column0".to_string(), "column1".to_string()],
|
||||
vals: vec![Value::test_string("c2"), Value::test_int(2)],
|
||||
span,
|
||||
},
|
||||
@ -184,7 +184,7 @@ pub fn transpose(
|
||||
if let Some(name) = args.rest.get(i) {
|
||||
headers.push(name.item.clone())
|
||||
} else {
|
||||
headers.push(format!("Column{}", i));
|
||||
headers.push(format!("column{}", i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ fn from_delimited_string_to_value(
|
||||
|
||||
let headers = if noheaders {
|
||||
(1..=reader.headers()?.len())
|
||||
.map(|i| format!("Column{}", i))
|
||||
.map(|i| format!("column{}", i))
|
||||
.collect::<Vec<String>>()
|
||||
} else {
|
||||
reader.headers()?.iter().map(String::from).collect()
|
||||
|
@ -146,7 +146,7 @@ fn from_ods(
|
||||
_ => Value::nothing(head),
|
||||
};
|
||||
|
||||
row_output.insert(format!("Column{}", i), value);
|
||||
row_output.insert(format!("column{}", i), value);
|
||||
}
|
||||
|
||||
let (cols, vals) =
|
||||
|
@ -49,7 +49,7 @@ impl Command for FromSsv {
|
||||
1 2' | from ssv -n"#,
|
||||
description: "Converts ssv formatted string to table but not treating the first row as column names",
|
||||
result: Some(
|
||||
Value::List { vals: vec![Value::Record { cols: vec!["Column1".to_string(), "Column2".to_string()], vals: vec![Value::String { val: "FOO".to_string(), span: Span::test_data() }, Value::String { val: "BAR".to_string(), span: Span::test_data() }], span: Span::test_data() }, Value::Record { cols: vec!["Column1".to_string(), "Column2".to_string()], vals: vec![Value::String { val: "1".to_string(), span: Span::test_data() }, Value::String { val: "2".to_string(), span: Span::test_data() }], span: Span::test_data() }], span: Span::test_data() }),
|
||||
Value::List { vals: vec![Value::Record { cols: vec!["column1".to_string(), "column2".to_string()], vals: vec![Value::String { val: "FOO".to_string(), span: Span::test_data() }, Value::String { val: "BAR".to_string(), span: Span::test_data() }], span: Span::test_data() }, Value::Record { cols: vec!["column1".to_string(), "column2".to_string()], vals: vec![Value::String { val: "1".to_string(), span: Span::test_data() }, Value::String { val: "2".to_string(), span: Span::test_data() }], span: Span::test_data() }], span: Span::test_data() }),
|
||||
}]
|
||||
}
|
||||
|
||||
@ -150,7 +150,7 @@ fn parse_aligned_columns<'a>(
|
||||
let headers: Vec<(String, usize)> = indices
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, position)| (format!("Column{}", i + 1), *position))
|
||||
.map(|(i, position)| (format!("column{}", i + 1), *position))
|
||||
.collect();
|
||||
|
||||
construct(ls.iter().map(|s| s.to_owned()), headers)
|
||||
@ -196,7 +196,7 @@ fn parse_separated_columns<'a>(
|
||||
let num_columns = ls.iter().map(|r| r.len()).max().unwrap_or(0);
|
||||
|
||||
let headers = (1..=num_columns)
|
||||
.map(|i| format!("Column{}", i))
|
||||
.map(|i| format!("column{}", i))
|
||||
.collect::<Vec<String>>();
|
||||
collect(headers, ls.into_iter(), separator)
|
||||
};
|
||||
@ -337,9 +337,9 @@ mod tests {
|
||||
assert_eq!(
|
||||
result,
|
||||
vec![
|
||||
vec![owned("Column1", "a"), owned("Column2", "b")],
|
||||
vec![owned("Column1", "1"), owned("Column2", "2")],
|
||||
vec![owned("Column1", "3"), owned("Column2", "4")]
|
||||
vec![owned("column1", "a"), owned("column2", "b")],
|
||||
vec![owned("column1", "1"), owned("column2", "2")],
|
||||
vec![owned("column1", "3"), owned("column2", "4")]
|
||||
]
|
||||
);
|
||||
}
|
||||
@ -451,25 +451,25 @@ mod tests {
|
||||
result,
|
||||
vec![
|
||||
vec![
|
||||
owned("Column1", "a multi-word value"),
|
||||
owned("Column2", "b"),
|
||||
owned("Column3", ""),
|
||||
owned("Column4", "d"),
|
||||
owned("Column5", "")
|
||||
owned("column1", "a multi-word value"),
|
||||
owned("column2", "b"),
|
||||
owned("column3", ""),
|
||||
owned("column4", "d"),
|
||||
owned("column5", "")
|
||||
],
|
||||
vec![
|
||||
owned("Column1", "1"),
|
||||
owned("Column2", ""),
|
||||
owned("Column3", "3-3"),
|
||||
owned("Column4", "4"),
|
||||
owned("Column5", "")
|
||||
owned("column1", "1"),
|
||||
owned("column2", ""),
|
||||
owned("column3", "3-3"),
|
||||
owned("column4", "4"),
|
||||
owned("column5", "")
|
||||
],
|
||||
vec![
|
||||
owned("Column1", ""),
|
||||
owned("Column2", ""),
|
||||
owned("Column3", ""),
|
||||
owned("Column4", ""),
|
||||
owned("Column5", "last")
|
||||
owned("column1", ""),
|
||||
owned("column2", ""),
|
||||
owned("column3", ""),
|
||||
owned("column4", ""),
|
||||
owned("column5", "last")
|
||||
],
|
||||
]
|
||||
);
|
||||
|
@ -146,7 +146,7 @@ fn from_xlsx(
|
||||
_ => Value::nothing(head),
|
||||
};
|
||||
|
||||
row_output.insert(format!("Column{}", i), value);
|
||||
row_output.insert(format!("column{}", i), value);
|
||||
}
|
||||
|
||||
let (cols, vals) =
|
||||
|
@ -54,9 +54,9 @@ impl Command for DetectColumns {
|
||||
result: Some(Value::List {
|
||||
vals: vec![Value::Record {
|
||||
cols: vec![
|
||||
"Column0".to_string(),
|
||||
"Column1".to_string(),
|
||||
"Column2".to_string(),
|
||||
"column0".to_string(),
|
||||
"column1".to_string(),
|
||||
"column2".to_string(),
|
||||
],
|
||||
vals: vec![
|
||||
Value::test_string("a"),
|
||||
@ -105,7 +105,7 @@ fn detect_columns(
|
||||
|
||||
if noheader {
|
||||
for header in headers.iter_mut().enumerate() {
|
||||
header.1.item = format!("Column{}", header.0);
|
||||
header.1.item = format!("column{}", header.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,9 +51,9 @@ impl Command for SubCommand {
|
||||
result: Some(Value::List {
|
||||
vals: vec![Value::Record {
|
||||
cols: vec![
|
||||
"Column1".to_string(),
|
||||
"Column2".to_string(),
|
||||
"Column3".to_string(),
|
||||
"column1".to_string(),
|
||||
"column2".to_string(),
|
||||
"column3".to_string(),
|
||||
],
|
||||
vals: vec![
|
||||
Value::test_string("a"),
|
||||
@ -71,9 +71,9 @@ impl Command for SubCommand {
|
||||
result: Some(Value::List {
|
||||
vals: vec![Value::Record {
|
||||
cols: vec![
|
||||
"Column1".to_string(),
|
||||
"Column2".to_string(),
|
||||
"Column3".to_string(),
|
||||
"column1".to_string(),
|
||||
"column2".to_string(),
|
||||
"column3".to_string(),
|
||||
],
|
||||
vals: vec![
|
||||
Value::test_string("a"),
|
||||
@ -131,7 +131,7 @@ fn split_column_helper(
|
||||
if positional.is_empty() {
|
||||
let mut gen_columns = vec![];
|
||||
for i in 0..split_result.len() {
|
||||
gen_columns.push(format!("Column{}", i + 1));
|
||||
gen_columns.push(format!("column{}", i + 1));
|
||||
}
|
||||
|
||||
for (&k, v) in split_result.iter().zip(&gen_columns) {
|
||||
|
Reference in New Issue
Block a user