diff --git a/src/schema/README.md b/src/schema/README.md index 14290337c1..68be4f2a9b 100644 --- a/src/schema/README.md +++ b/src/schema/README.md @@ -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"` | diff --git a/src/schema/meta/expression_tests.yaml b/src/schema/meta/expression_tests.yaml index 8ab60a28d4..0d5d54a1f2 100644 --- a/src/schema/meta/expression_tests.yaml +++ b/src/schema/meta/expression_tests.yaml @@ -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. diff --git a/src/schema/rules/checks/events.yaml b/src/schema/rules/checks/events.yaml index 234b9d078d..1f0f57a123 100644 --- a/src/schema/rules/checks/events.yaml +++ b/src/schema/rules/checks/events.yaml @@ -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)