mlr sparsify (#1498)

* mlr sparsify

* regression-test cases

* typofix

* Remove mods due to processor-architecture change
This commit is contained in:
John Kerl 2024-02-18 10:56:26 -05:00 committed by GitHub
parent cd6d42736f
commit f5eaf290cf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
30 changed files with 424 additions and 19 deletions

View file

@ -988,6 +988,18 @@ Options:
-r Recursively sort subobjects/submaps, e.g. for JSON input.
-h|--help Show this message.
================================================================
sparsify
Usage: mlr sparsify [options]
Unsets fields for which the key is the empty string (or, optionally, another
specified value). Only makes sense with output format not being CSV or TSV.
Options:
-s {filler string} What values to remove. Defaults to the empty string.
-f {a,b,c} Specify field names to be operated on; any other fields won't be
modified. The default is to modify all fields.
-h|--help Show this message.
Example: if input is a=1,b=,c=3 then output is a=1,c=3.
================================================================
split
Usage: mlr split [options] {filename}

View file

@ -0,0 +1 @@
mlr --c2j --from test/input/sparsify-input.csv sparsify

View file

View file

@ -0,0 +1,17 @@
[
{
"a": 1,
"b": 2,
"c": 3
},
{
"a": 4,
"b": 5
},
{},
{
"a": 7,
"b": 8,
"c": 9
}
]

View file

@ -0,0 +1 @@
mlr --c2j --from test/input/sparsify-input.csv sparsify -f a

View file

View file

@ -0,0 +1,21 @@
[
{
"a": 1,
"b": 2,
"c": 3
},
{
"a": 4,
"b": 5,
"c": ""
},
{
"b": "",
"c": ""
},
{
"a": 7,
"b": 8,
"c": 9
}
]

View file

@ -0,0 +1 @@
mlr --c2j --from test/input/sparsify-input.csv sparsify -f b

View file

View file

@ -0,0 +1,21 @@
[
{
"a": 1,
"b": 2,
"c": 3
},
{
"a": 4,
"b": 5,
"c": ""
},
{
"a": "",
"c": ""
},
{
"a": 7,
"b": 8,
"c": 9
}
]

View file

@ -0,0 +1 @@
mlr --c2j --from test/input/sparsify-input.csv sparsify -f b,c

View file

View file

@ -0,0 +1,19 @@
[
{
"a": 1,
"b": 2,
"c": 3
},
{
"a": 4,
"b": 5
},
{
"a": ""
},
{
"a": 7,
"b": 8,
"c": 9
}
]

View file

@ -0,0 +1 @@
mlr --c2j --from test/input/sparsify-input.csv sparsify -s 1

View file

View file

@ -0,0 +1,21 @@
[
{
"b": 2,
"c": 3
},
{
"a": 4,
"b": 5,
"c": ""
},
{
"a": "",
"b": "",
"c": ""
},
{
"a": 7,
"b": 8,
"c": 9
}
]

View file

@ -0,0 +1 @@
mlr --c2j --from test/input/sparsify-input.csv sparsify -f a -s 1

View file

View file

@ -0,0 +1,21 @@
[
{
"b": 2,
"c": 3
},
{
"a": 4,
"b": 5,
"c": ""
},
{
"a": "",
"b": "",
"c": ""
},
{
"a": 7,
"b": 8,
"c": 9
}
]

View file

@ -0,0 +1 @@
mlr --c2j --from test/input/sparsify-input.csv sparsify -f b -s 1

View file

View file

@ -0,0 +1,22 @@
[
{
"a": 1,
"b": 2,
"c": 3
},
{
"a": 4,
"b": 5,
"c": ""
},
{
"a": "",
"b": "",
"c": ""
},
{
"a": 7,
"b": 8,
"c": 9
}
]

View file

@ -0,0 +1 @@
mlr --c2j --from test/input/sparsify-input.csv sparsify -f b,c -s 1

View file

View file

@ -0,0 +1,22 @@
[
{
"a": 1,
"b": 2,
"c": 3
},
{
"a": 4,
"b": 5,
"c": ""
},
{
"a": "",
"b": "",
"c": ""
},
{
"a": 7,
"b": 8,
"c": 9
}
]

View file

@ -0,0 +1,5 @@
a,b,c
1,2,3
4,5,
,,
7,8,9
1 a b c
2 1 2 3
3 4 5
4
5 7 8 9