Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(checks): Sort columns.onset numerically #1871

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)