Add support for per-column custom comparators#13973
Conversation
| protected compute(x: any, y: any): number { | ||
| if (isNaN(x)) { | ||
| return this.ascending_first ? -1 : 1 | ||
| } | ||
| if (isNaN(y)) { | ||
| return this.ascending_first ? 1 : -1 | ||
| } | ||
| return x==y ? 0 : x < y ? -1 : 1 | ||
| } |
There was a problem hiding this comment.
isNaN() can somewhat work in place of isNumber(), but it's finicky, and only as long as any type is involved on the type-level. Given the inputs to this method can be anything, I would change the types to unknown and add isNumber() guards to make sure isNaN() has actual numbers to work with.
There was a problem hiding this comment.
I made this change but it also limited the comparison in general to numeric types, I could have imagined sorting nans first or last relative to non-numeric types in case someone used nan as "missing". Currently returning 0 for non-numeric types, but perhaps an error is also an option?
|
@mattpap we are not currently using |
mosc9575
left a comment
There was a problem hiding this comment.
Some comments on the docstrings to make sure they won't be missed.
|
@bokeh/dev thoughts on what level of docs support this needs? Will definitely add basic reference guide materials. Some other possibilities:
@mattpap any guidance on BokehJS tests? Can you point me towards something analogous that I can use as a basis to emulate? |
|
I've added basic ref docs. Absent feedback about other docs or tests I am marking this |
Apparently not. I don't have any plans for data tables besides updating SlickGrid to a newer version (PR #13522). |
I would turn this sample code into an example under |
There's a single good test that can be a basis for this: bokeh/bokehjs/test/integration/tables.ts Lines 9 to 21 in 8c2833e Put the construction code in a function, configure with |
Co-authored-by: Mateusz Paprocki <mattpap@gmail.com>
Co-authored-by: Moritz Schreiber <68053396+mosc9575@users.noreply.github.com>
Co-authored-by: Mateusz Paprocki <mattpap@gmail.com>
dca102d to
4d03eec
Compare
I'll make an issue soon. It's probably something worth looking into at some point so that we can jettison our adhoc homegrown view |
4d03eec to
87ee9cb
Compare
Co-authored-by: Moritz Schreiber <68053396+mosc9575@users.noreply.github.com>
Co-authored-by: Mateusz Paprocki <mattpap@gmail.com>
* Add support for per-column custom comparators * Apply suggestions from code review Co-authored-by: Mateusz Paprocki <mattpap@gmail.com> * review comments * fix defaults tests * fix js tests * Apply suggestions from code review Co-authored-by: Moritz Schreiber <68053396+mosc9575@users.noreply.github.com> * add basic ref docs * Apply suggestions from code review Co-authored-by: Mateusz Paprocki <mattpap@gmail.com> * NanSorter -> NanCompare * add example * bokehjs integration test * update baselines * Apply suggestions from code review Co-authored-by: Moritz Schreiber <68053396+mosc9575@users.noreply.github.com> * Update bokehjs/test/integration/tables.ts Co-authored-by: Mateusz Paprocki <mattpap@gmail.com> * lint --------- Co-authored-by: Mateusz Paprocki <mattpap@gmail.com> Co-authored-by: Moritz Schreiber <68053396+mosc9575@users.noreply.github.com>
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
@bokeh/dev This would still needs tests, docs, and examples, but I wanted to get some early feedback on the approach, which seems to work. I am also sure the TypeScript will needs improvements, and I am also not sure how if at all the current "default" sorter code needs to be considered (i.e. whatever it was trying to do with nans already seem to not be desired, can it just be jettisoned?)
Here is a test script based on the OP:
With results for:
Ascending
Descending
