diff --git a/Project.toml b/Project.toml index d99eec4..de3010f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ScientificTypes" uuid = "321657f4-b219-11e9-178b-2701a2544e81" authors = ["Anthony D. Blaom "] -version = "3.1.1" +version = "3.1.2" [deps] CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597" @@ -18,7 +18,7 @@ Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" CategoricalArrays = "0.8, 0.9, 0.10, 1" ColorTypes = "0.9, 0.10, 0.11, 0.12" Distributions = "0.25.1" -PrettyTables = "1, 2" +PrettyTables = "3" Reexport = "1.2" ScientificTypesBase = "3.0" StatisticalTraits = "3.0" diff --git a/src/schema.jl b/src/schema.jl index 11f96c0..9a3fd20 100644 --- a/src/schema.jl +++ b/src/schema.jl @@ -244,10 +244,11 @@ function _rows_schema(rows, sch::Tables.Schema{nothing, nothing}) end function Base.show(io::IO, ::MIME"text/plain", s::Schema) - data = Tables.matrix(s) - header = (["names", "scitypes", "types"],) - pretty_table(io, data, header=header; - header_crayon=Crayon(bold=false), - alignment=:l) -end + # for getting rid of bold in table headings: + style = PrettyTables.TextTableStyle( + first_line_column_label = PrettyTables.crayon"black", + ) + column_labels = [["names", "scitypes", "types"],] + pretty_table(io, s; column_labels, style, alignment=:l) +end diff --git a/test/schema.jl b/test/schema.jl index 40c4b2b..e96153a 100644 --- a/test/schema.jl +++ b/test/schema.jl @@ -33,17 +33,21 @@ # Schema show df = DataFrame(x=[1.0,2.0,3.0], y=["a","b","c"]) - s = schema(df) - io = IOBuffer() - show(io, MIME("text/plain"), ScientificTypes.schema(df)) - @test String(take!(io)) == "┌───────┬────────────┬─────────┐\n│ names │ scitypes │ types │\n├───────┼────────────┼─────────┤\n│ x │ Continuous │ Float64 │\n│ y │ Textual │ String │\n└───────┴────────────┴─────────┘\n" + s = ScientificTypes.schema(df) + str = sprint(show, MIME("text/plain"), s) + @test str == "┌───────┬────────────┬─────────┐\n"* + "│ names │ scitypes │ types │\n"* + "├───────┼────────────┼─────────┤\n"* + "│ x │ Continuous │ Float64 │\n"* + "│ y │ Textual │ String │\n"* + "└───────┴────────────┴─────────┘\n" end struct MySchemalessTable{U, V} x::Vector{U} y::Vector{V} end - + Tables.istable(::MySchemalessTable) = true Tables.columnaccess(::Type{<:MySchemalessTable}) = true Tables.columns(t::MySchemalessTable) = t @@ -63,7 +67,7 @@ struct ExtremelyWideTable{U, V} a::Vector{U} b::Vector{V} end - + Tables.istable(::ExtremelyWideTable) = true Tables.columnaccess(::Type{<:ExtremelyWideTable}) = true Tables.columns(t::ExtremelyWideTable) = t @@ -105,13 +109,13 @@ end # schema of non-tabular objects @test_throws ArgumentError schema([:x, :y]) - + # PR #61 "schema check for `Tables.DictColumn`" X1 = Dict(:a=>rand(5), :b=>rand(Int, 5)) s1 = schema(X1) @test s1.scitypes == (Continuous, Count) @test s1.types == (Float64, Int64) - + # issue 47 (schema for objects, `X` with, `Tables.schema(X) == nothing`) X2 = MySchemalessTable(rand(3), rand(Int, 3)) s2 = schema(X2) @@ -132,8 +136,8 @@ end @test ST._rows_schema( Tables.rows(X3), Tables.schema(X3) ) == ST.Schema(Tables.columnnames(X3), (Continuous, Count), (Float64, Int)) - - # test schema for column oreinted tables with number of columns + + # test schema for column oreinted tables with number of columns # exceeding COLS_SPECIALIZATION_THRESHOLD. nt = NamedTuple{ Tuple(Symbol("x$i") for i in Base.OneTo(ST.COLS_SPECIALIZATION_THRESHOLD + 1)) @@ -154,7 +158,6 @@ end Tables.columnnames(nt), NTuple{ST.COLS_SPECIALIZATION_THRESHOLD + 1, Continuous}, NTuple{ST.COLS_SPECIALIZATION_THRESHOLD + 1, Float64} - ) + ) end -