Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ScientificTypes"
uuid = "321657f4-b219-11e9-178b-2701a2544e81"
authors = ["Anthony D. Blaom <[email protected]>"]
version = "3.1.1"
version = "3.1.2"

[deps]
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
Expand All @@ -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"
Expand Down
13 changes: 7 additions & 6 deletions src/schema.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 15 additions & 12 deletions test/schema.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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))
Expand All @@ -154,7 +158,6 @@ end
Tables.columnnames(nt),
NTuple{ST.COLS_SPECIALIZATION_THRESHOLD + 1, Continuous},
NTuple{ST.COLS_SPECIALIZATION_THRESHOLD + 1, Float64}
)
)

end

Loading