Make comparisons/sort-by more 'global' (#4500)

* Make comparisons/sort-by more 'global'

* Let custom values do their own comparisons
This commit is contained in:
JT
2022-02-16 14:30:37 -05:00
committed by GitHub
parent b64ac9eb7b
commit d620f76a21
7 changed files with 325 additions and 45 deletions

View File

@ -39,11 +39,11 @@ impl Command for DropDuplicates {
NuDataFrame::try_from_columns(vec![
Column::new(
"a".to_string(),
vec![Value::test_int(1), Value::test_int(3)],
vec![Value::test_int(3), Value::test_int(1)],
),
Column::new(
"b".to_string(),
vec![Value::test_int(2), Value::test_int(4)],
vec![Value::test_int(4), Value::test_int(2)],
),
])
.expect("simple df for test should not fail")

View File

@ -82,6 +82,7 @@ pub fn add_eager_decls(working_set: &mut StateWorkingSet) {
DataTypes,
DescribeDF,
DropDF,
DropDuplicates,
DropNulls,
Dummies,
FilterWith,

View File

@ -146,3 +146,16 @@ fn ls_sort_by_type_name_insensitive() {
let json_output = r#"[{"name": "C","type": "Dir"},{"name": "a.txt","type": "File"},{"name": "B.txt","type": "File"}]"#;
assert_eq!(actual.out, json_output);
}
#[test]
fn sort_different_types() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
[a, 1, b, 2, c, 3, [4, 5, 6], d, 4, [1, 2, 3]] | sort-by | to json --raw
"#
));
let json_output = r#"[1,2,3,4,"a","b","c","d",[1,2,3],[4,5,6]]"#;
assert_eq!(actual.out, json_output);
}