Sorting things out#2003
Merged
Merged
Conversation
Member
Author
|
I removed the sorting information from the docs. We can add it back with Quarto using code so it won't be wrong again: using Ribasim
using StructArrays: StructVector
using Legolas: AbstractRecord
"""
Get a string describing the sorting of a table type.
julia> sort_info(Ribasim.BasinTimeV1)
"Sorted by: node_id, time."
"""
function sort_info(table_type::Type{<:AbstractRecord})::String
# create an empty table to get the sort by function
table = StructVector{table_type}(undef, 0)
# extract the column names from the getproperty calls in the expression
by = Ribasim.sort_by(table)
codeinfo = Base.uncompressed_ast(only(methods(by)))
is_getproperty(ex) = ex isa Expr && ex.args[1].name == :getproperty
cols = [ex.args[3].value for ex in codeinfo.code if is_getproperty(ex)]
return "Sorted by: $(join(cols, ", "))."
end
using Test
@test sort_info(Ribasim.BasinStaticV1) == "Sorted by: node_id."
@test sort_info(Ribasim.BasinTimeV1) == "Sorted by: time, node_id."There are just a few places tables that don't have a Julia schema like Basin / area and Terminal that do have sorting in Python. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1976.
Fixes most of #601.