mirror of
https://github.com/nushell/nushell.git
synced 2025-04-04 06:30:45 +02:00
filesize conversion (#5770)
This commit is contained in:
parent
44979f3051
commit
de554f8e5f
crates
@ -34,10 +34,6 @@ impl Column {
|
|||||||
pub fn name(&self) -> &str {
|
pub fn name(&self) -> &str {
|
||||||
self.name.as_str()
|
self.name.as_str()
|
||||||
}
|
}
|
||||||
|
|
||||||
//pub fn iter(&self) -> impl Iterator<Item = &Value> {
|
|
||||||
// self.values.iter()
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntoIterator for Column {
|
impl IntoIterator for Column {
|
||||||
@ -72,6 +68,7 @@ pub enum InputType {
|
|||||||
Object,
|
Object,
|
||||||
Date,
|
Date,
|
||||||
Duration,
|
Duration,
|
||||||
|
Filesize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -616,6 +613,9 @@ pub fn insert_value(
|
|||||||
Value::Duration { .. } => {
|
Value::Duration { .. } => {
|
||||||
col_val.column_type = Some(InputType::Duration);
|
col_val.column_type = Some(InputType::Duration);
|
||||||
}
|
}
|
||||||
|
Value::Filesize { .. } => {
|
||||||
|
col_val.column_type = Some(InputType::Filesize);
|
||||||
|
}
|
||||||
_ => col_val.column_type = Some(InputType::Object),
|
_ => col_val.column_type = Some(InputType::Object),
|
||||||
}
|
}
|
||||||
col_val.values.push(value);
|
col_val.values.push(value);
|
||||||
@ -628,6 +628,7 @@ pub fn insert_value(
|
|||||||
| (Value::String { .. }, Value::String { .. })
|
| (Value::String { .. }, Value::String { .. })
|
||||||
| (Value::Bool { .. }, Value::Bool { .. })
|
| (Value::Bool { .. }, Value::Bool { .. })
|
||||||
| (Value::Date { .. }, Value::Date { .. })
|
| (Value::Date { .. }, Value::Date { .. })
|
||||||
|
| (Value::Filesize { .. }, Value::Filesize { .. })
|
||||||
| (Value::Duration { .. }, Value::Duration { .. }) => col_val.values.push(value),
|
| (Value::Duration { .. }, Value::Duration { .. }) => col_val.values.push(value),
|
||||||
_ => {
|
_ => {
|
||||||
col_val.column_type = Some(InputType::Object);
|
col_val.column_type = Some(InputType::Object);
|
||||||
@ -659,6 +660,12 @@ pub fn from_parsed_columns(column_values: ColumnMap) -> Result<NuDataFrame, Shel
|
|||||||
let series = Series::new(&name, series_values?);
|
let series = Series::new(&name, series_values?);
|
||||||
df_series.push(series)
|
df_series.push(series)
|
||||||
}
|
}
|
||||||
|
InputType::Filesize => {
|
||||||
|
let series_values: Result<Vec<_>, _> =
|
||||||
|
column.values.iter().map(|v| v.as_i64()).collect();
|
||||||
|
let series = Series::new(&name, series_values?);
|
||||||
|
df_series.push(series)
|
||||||
|
}
|
||||||
InputType::String => {
|
InputType::String => {
|
||||||
let series_values: Result<Vec<_>, _> =
|
let series_values: Result<Vec<_>, _> =
|
||||||
column.values.iter().map(|v| v.as_string()).collect();
|
column.values.iter().map(|v| v.as_string()).collect();
|
||||||
@ -698,17 +705,10 @@ pub fn from_parsed_columns(column_values: ColumnMap) -> Result<NuDataFrame, Shel
|
|||||||
df_series.push(res.into_series())
|
df_series.push(res.into_series())
|
||||||
}
|
}
|
||||||
InputType::Duration => {
|
InputType::Duration => {
|
||||||
let it = column.values.iter().map(|v| {
|
let series_values: Result<Vec<_>, _> =
|
||||||
if let Value::Duration { val, .. } = &v {
|
column.values.iter().map(|v| v.as_i64()).collect();
|
||||||
Some(*val)
|
let series = Series::new(&name, series_values?);
|
||||||
} else {
|
df_series.push(series)
|
||||||
None
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let res = ChunkedArray::<Int64Type>::from_iter_options(&name, it);
|
|
||||||
|
|
||||||
df_series.push(res.into_series())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@ impl Value {
|
|||||||
pub fn as_i64(&self) -> Result<i64, ShellError> {
|
pub fn as_i64(&self) -> Result<i64, ShellError> {
|
||||||
match self {
|
match self {
|
||||||
Value::Int { val, .. } => Ok(*val),
|
Value::Int { val, .. } => Ok(*val),
|
||||||
|
Value::Filesize { val, .. } => Ok(*val),
|
||||||
|
Value::Duration { val, .. } => Ok(*val),
|
||||||
x => Err(ShellError::CantConvert(
|
x => Err(ShellError::CantConvert(
|
||||||
"i64".into(),
|
"i64".into(),
|
||||||
x.get_type().to_string(),
|
x.get_type().to_string(),
|
||||||
|
Loading…
Reference in New Issue
Block a user