19
19
to_css_size (s:: AbstractString ) = s
20
20
to_css_size (s:: Real ) = " $(s) px"
21
21
22
- function showtable (table; dark = false , height = :auto , width = " 100%" )
23
- if ! Tables. istable (typeof (table))
24
- throw (ArgumentError (" Argument is not a table." ))
25
- end
22
+ struct IteratorAndFirst{F, T}
23
+ first:: F
24
+ source:: T
25
+ IteratorAndFirst (x) = new (iterate (x), x)
26
+ end
27
+ Base. IteratorSize (:: Type{IteratorAndFirst{F, T}} ) where {F, T} = Base. IteratorSize (T)
28
+ Base. length (x:: IteratorAndFirst ) = length (x. source)
29
+ Base. IteratorEltype (:: Type{IteratorAndFirst{F, T}} ) where {F, T} = Base. IteratorEltype (T)
30
+ Base. eltype (x:: IteratorAndFirst ) = eltype (x. source)
31
+ Base. iterate (x:: IteratorAndFirst ) = x. first
32
+ function Base. iterate (x:: IteratorAndFirst , st)
33
+ st === nothing && return nothing
34
+ return iterate (x. source)
35
+ end
26
36
27
- tablelength = Base. IteratorSize (table) == Base. HasLength () ? length (Tables. rows (table)) : nothing
37
+ function showtable (table; dark = false , height = :auto , width = " 100%" )
38
+ rows = Table. rows (table)
39
+ tablelength = Base. IteratorSize (rows) == Base. HasLength () ? length (rows) : nothing
28
40
29
41
if height === :auto
30
42
height = 500
@@ -34,14 +46,21 @@ function showtable(table; dark = false, height = :auto, width = "100%")
34
46
end
35
47
end
36
48
37
- rows = Tables. rows (table)
38
- schema = Tables. schema (table)
49
+ schema = Tables. schema (rows)
39
50
if schema === nothing
51
+ st = iterate (rows)
52
+ rows = IteratorAndFirst (st, rows)
53
+ names = Symbol[]
40
54
types = []
41
- for (i, c) in enumerate (Tables. eachcolumn (first (rows)))
42
- push! (types, typeof (c))
55
+ if st != = nothing
56
+ row = st[1 ]
57
+ for nm in propertynames (row)
58
+ push! (names, nm)
59
+ push! (types, typeof (getproperty (row, nm)))
60
+ end
61
+ else
62
+ # no schema and no rows
43
63
end
44
- names = collect (propertynames (first (rows)))
45
64
else
46
65
names = schema. names
47
66
types = schema. types
0 commit comments