Skip to content

Commit d19e97b

Browse files
committed
adapt show(::Schema) to new PrettyTables API
1 parent 793a2eb commit d19e97b

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/schema.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,7 @@ function _rows_schema(rows, sch::Tables.Schema{nothing, nothing})
244244
end
245245

246246
function Base.show(io::IO, ::MIME"text/plain", s::Schema)
247-
data = Tables.matrix(s)
248-
header = (["names", "scitypes", "types"],)
249-
pretty_table(io, data, header=header;
250-
header_crayon=Crayon(bold=false),
251-
alignment=:l)
247+
# data = Tables.matrix(s)
248+
column_labels = [["names", "scitypes", "types"],]
249+
pretty_table(io, s; column_labels, alignment=:l)
252250
end
253-

test/schema.jl

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,21 @@
3333

3434
# Schema show
3535
df = DataFrame(x=[1.0,2.0,3.0], y=["a","b","c"])
36-
s = schema(df)
37-
io = IOBuffer()
38-
show(io, MIME("text/plain"), ScientificTypes.schema(df))
39-
@test String(take!(io)) == "┌───────┬────────────┬─────────┐\n│ names │ scitypes │ types │\n├───────┼────────────┼─────────┤\n│ x │ Continuous │ Float64 │\n│ y │ Textual │ String │\n└───────┴────────────┴─────────┘\n"
36+
s = ScientificTypes.schema(df)
37+
str = sprint(show, MIME("text/plain"), s)
38+
@test str == "┌───────┬────────────┬─────────┐\n"*
39+
"│ names │ scitypes │ types │\n"*
40+
"├───────┼────────────┼─────────┤\n"*
41+
"│ x │ Continuous │ Float64 │\n"*
42+
"│ y │ Textual │ String │\n"*
43+
"└───────┴────────────┴─────────┘\n"
4044
end
4145

4246
struct MySchemalessTable{U, V}
4347
x::Vector{U}
4448
y::Vector{V}
4549
end
46-
50+
4751
Tables.istable(::MySchemalessTable) = true
4852
Tables.columnaccess(::Type{<:MySchemalessTable}) = true
4953
Tables.columns(t::MySchemalessTable) = t
@@ -63,7 +67,7 @@ struct ExtremelyWideTable{U, V}
6367
a::Vector{U}
6468
b::Vector{V}
6569
end
66-
70+
6771
Tables.istable(::ExtremelyWideTable) = true
6872
Tables.columnaccess(::Type{<:ExtremelyWideTable}) = true
6973
Tables.columns(t::ExtremelyWideTable) = t
@@ -105,13 +109,13 @@ end
105109

106110
# schema of non-tabular objects
107111
@test_throws ArgumentError schema([:x, :y])
108-
112+
109113
# PR #61 "schema check for `Tables.DictColumn`"
110114
X1 = Dict(:a=>rand(5), :b=>rand(Int, 5))
111115
s1 = schema(X1)
112116
@test s1.scitypes == (Continuous, Count)
113117
@test s1.types == (Float64, Int64)
114-
118+
115119
# issue 47 (schema for objects, `X` with, `Tables.schema(X) == nothing`)
116120
X2 = MySchemalessTable(rand(3), rand(Int, 3))
117121
s2 = schema(X2)
@@ -132,8 +136,8 @@ end
132136
@test ST._rows_schema(
133137
Tables.rows(X3), Tables.schema(X3)
134138
) == ST.Schema(Tables.columnnames(X3), (Continuous, Count), (Float64, Int))
135-
136-
# test schema for column oreinted tables with number of columns
139+
140+
# test schema for column oreinted tables with number of columns
137141
# exceeding COLS_SPECIALIZATION_THRESHOLD.
138142
nt = NamedTuple{
139143
Tuple(Symbol("x$i") for i in Base.OneTo(ST.COLS_SPECIALIZATION_THRESHOLD + 1))
@@ -154,7 +158,6 @@ end
154158
Tables.columnnames(nt),
155159
NTuple{ST.COLS_SPECIALIZATION_THRESHOLD + 1, Continuous},
156160
NTuple{ST.COLS_SPECIALIZATION_THRESHOLD + 1, Float64}
157-
)
161+
)
158162

159163
end
160-

0 commit comments

Comments
 (0)