Skip to content

Commit 086ee0b

Browse files
authored
Merge pull request #207 from JuliaAI/pretty-tables-3.1
Bump compat, PrettyTables="3.0"
2 parents 8d55a20 + ccb3f09 commit 086ee0b

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ScientificTypes"
22
uuid = "321657f4-b219-11e9-178b-2701a2544e81"
33
authors = ["Anthony D. Blaom <[email protected]>"]
4-
version = "3.1.1"
4+
version = "3.1.2"
55

66
[deps]
77
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
@@ -18,7 +18,7 @@ Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
1818
CategoricalArrays = "0.8, 0.9, 0.10, 1"
1919
ColorTypes = "0.9, 0.10, 0.11, 0.12"
2020
Distributions = "0.25.1"
21-
PrettyTables = "1, 2"
21+
PrettyTables = "3"
2222
Reexport = "1.2"
2323
ScientificTypesBase = "3.0"
2424
StatisticalTraits = "3.0"

src/schema.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,11 @@ 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)
252-
end
247+
# for getting rid of bold in table headings:
248+
style = PrettyTables.TextTableStyle(
249+
first_line_column_label = PrettyTables.crayon"black",
250+
)
253251

252+
column_labels = [["names", "scitypes", "types"],]
253+
pretty_table(io, s; column_labels, style, alignment=:l)
254+
end

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)