Skip to content

Commit

Permalink
fix(checks): Sort columns.onset numerically (#1871)
Browse files Browse the repository at this point in the history
* enh(expressions): Allow numeric or lexical sorting

* fix(checks): Sort columns.onset numerically

* enh(expressions): Test behavior of numerically sorting n/a
  • Loading branch information
effigies authored Jul 18, 2024
1 parent 1418ce8 commit 3a636a1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/schema/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ The following functions should be defined by an interpreter:
| `match(arg: str, pattern: str) -> bool` | `true` if `arg` matches the regular expression `pattern` (anywhere in string) | `match(extension, ".gz$")` | True if the file extension ends with `.gz` |
| `max(arg: array) -> number` | The largest non-`n/a` value in an array | `max(columns.onset)` | The time of the last onset in an events.tsv file |
| `min(arg: array) -> number` | The smallest non-`n/a` value in an array | `min(sidecar.SliceTiming) == 0` | A check that the onset of the first slice is 0s |
| `sorted(arg: array) -> array` | The sorted values of the input array | `sorted(sidecar.VolumeTiming) == sidecar.VolumeTiming` | True if `sidecar.VolumeTiming` is sorted |
| `sorted(arg: array, method: str) -> array` | The sorted values of the input array; defaults to type-determined sort. If method is "lexical", or "numeric" use lexical or numeric sort. | `sorted(sidecar.VolumeTiming) == sidecar.VolumeTiming` | True if `sidecar.VolumeTiming` is sorted |
| `substr(arg: str, start: int, end: int) -> str` | The portion of the input string spanning from start position to end position | `substr(path, 0, length(path) - 3)` | `path` with the last three characters dropped |
| `type(arg: Any) -> str` | The name of the type, including `"array"`, `"object"`, `"null"` | `type(datatypes)` | Returns `"array"` |

Expand Down
10 changes: 10 additions & 0 deletions src/schema/meta/expression_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@
result: null
- expression: sorted([3, 2, 1])
result: [1, 2, 3]
- expression: sorted([1, 2, 5, 10], "lexical")
result: [1, 10, 2, 5]
- expression: sorted(["1", "2", "5", "10"])
result: ["1", "10", "2", "5"]
- expression: sorted(["1", "2", "5", "10"], "numeric")
result: ["1", "2", "5", "10"]
- expression: sorted(["1", "2", "n/a"], "numeric")
result: ["1", "2", "n/a"]
- expression: sorted(["n/a", "2", "1"], "numeric")
result: ["n/a", "1", "2"]
- expression: allequal(sorted([3, 2, 1]), [1, 2, 3])
result: true
# Regression test. Javascript will sort lexically by default.
Expand Down
2 changes: 1 addition & 1 deletion src/schema/rules/checks/events.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ SortedOnsets:
- extension == ".tsv"
checks:
# n/a values will likely cause false alarms if encountered. Consider alternatives.
- allequal(sorted(columns.onset), columns.onset)
- allequal(sorted(columns.onset, "numeric"), columns.onset)

0 comments on commit 3a636a1

Please sign in to comment.