Skip to content

Commit

Permalink
ENH: Display TabularSet using PrettyTables.
Browse files Browse the repository at this point in the history
  • Loading branch information
epatters committed Oct 28, 2021
1 parent 2eb8dc3 commit cb6cf12
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/categorical_algebra/FinSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using DataStructures: OrderedDict, IntDisjointSets, union!, find_root!
using Reexport
import StaticArrays
using StaticArrays: StaticVector, SVector, SizedVector, similar_type
import Tables
import Tables, PrettyTables

@reexport using ..Sets
using ...GAT, ...Theories, ...CSetDataStructures, ...Graphs
Expand Down Expand Up @@ -86,6 +86,16 @@ FinSet(nt::NamedTuple) = TabularSet(nt)
Base.iterate(set::TabularSet, args...) = iterate(Tables.rows(set.table), args...)
Base.length(set::TabularSet) = Tables.rowcount(set.table)

Base.show(io::IO, set::TabularSet) = print(io, "TabularSet($(set.table))")

function Base.show(io::IO, ::MIME"text/plain", set::TabularSet{T}) where T
print(io, "$(length(set))-element TabularSet{$T}")
if !get(io, :compact, false)
println(io, ":")
PrettyTables.pretty_table(io, set.table, nosubheader=true)
end
end

# Discrete categories
#--------------------

Expand Down
2 changes: 2 additions & 0 deletions test/categorical_algebra/FinSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ set = FinSet(Set(1:2:5))
set = FinSet((x=[1,3,5], y=['a','b','c']))
@test length(set) == 3
@test map(NamedTuple, set) == [(x=1, y='a'), (x=3, y='b'), (x=5, y='c')]
@test startswith(sshow(set), "TabularSet(")
@test startswith(sprint(show, MIME("text/plain"), set), "3-element TabularSet")

# Discrete categories
#####################
Expand Down

0 comments on commit cb6cf12

Please sign in to comment.