Skip to content
This repository was archived by the owner on Mar 11, 2022. It is now read-only.

Commit 3e93581

Browse files
authored
Improve show method of VecColumnTable with PrettyTables (#25)
1 parent 3556631 commit 3e93581

File tree

6 files changed

+28
-8
lines changed

6 files changed

+28
-8
lines changed

.github/workflows/CI-latest.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,6 @@ jobs:
4040
${{ runner.os }}-test-
4141
${{ runner.os }}-
4242
- uses: julia-actions/julia-buildpkg@v1
43+
- name: Install latest dependencies
44+
run: julia --project=. -e "using Pkg; Pkg.add(PackageSpec(name=\""DataFrames\"", rev=\""main\"")); Pkg.instantiate()"
4345
- uses: julia-actions/julia-runtest@v1

.github/workflows/CI-stable.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ jobs:
4242
${{ runner.os }}-test-
4343
${{ runner.os }}-
4444
- uses: julia-actions/julia-buildpkg@v1
45+
- name: Install latest dependencies
46+
run: julia --project=. -e "using Pkg; Pkg.add(PackageSpec(name=\""DataFrames\"", rev=\""main\"")); Pkg.instantiate()"
4547
- uses: julia-actions/julia-runtest@v1
4648
- uses: julia-actions/julia-processcoverage@v1
4749
- uses: codecov/codecov-action@v1

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1313
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
1414
Missings = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28"
1515
PooledArrays = "2dfb63ee-cc39-5dd5-95bd-886bf059d720"
16+
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
1617
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1718
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
1819
StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
@@ -28,6 +29,7 @@ DataFrames = "0.22"
2829
MacroTools = "0.5"
2930
Missings = "0.4"
3031
PooledArrays = "1.2"
32+
PrettyTables = "0.12"
3133
Reexport = "0.2, 1"
3234
StatsBase = "0.33"
3335
StatsFuns = "0.9"

src/DiffinDiffsBase.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ using LinearAlgebra: Diagonal
1111
using MacroTools: @capture, isexpr, postwalk
1212
using Missings: allowmissing, disallowmissing
1313
using PooledArrays: _label
14+
using PrettyTables: pretty_table
1415
using Reexport
1516
using StatsBase: CoefTable, Weights, stderror, uweights
1617
using StatsFuns: tdistccdf, tdistinvcdf

src/tables.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,12 @@ Base.show(io::IO, cols::VecColumnTable) = print(io, nrow(cols), '×', ncol(cols)
117117

118118
function Base.show(io::IO, ::MIME"text/plain", cols::VecColumnTable)
119119
show(io, cols)
120-
if ncol(cols) > 0
121-
print(io, ":\n")
122-
names = _names(cols)
123-
types = map(c->eltype(c), _columns(cols))
124-
Base.print_matrix(io, hcat(names, types))
120+
if ncol(cols) > 0 && nrow(cols) > 0
121+
println(io, ':')
122+
pretty_table(IOContext(io, :limit=>true, :displaysize=>(15, 80)),
123+
cols, vlines=1:1, hlines=1:1,
124+
show_row_number=true, show_omitted_cell_summary=false,
125+
newline_at_end=false, vcrop_mode=:middle)
125126
end
126127
end
127128

test/tables.jl

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
@test size(cols) == (0, 1)
1919
@test length(cols) == 1
2020
@test isempty(cols)
21+
@test sprint(show, MIME("text/plain"), cols) == "0×1 VecColumnTable"
2122

2223
cols = VecColumnTable((wave=hrs.wave,))
2324
@test size(cols) == (3280, 1)
@@ -74,11 +75,22 @@
7475
@test cols == deepcopy(cols)
7576

7677
@test sprint(show, cols) == "3280×2 VecColumnTable"
77-
w = VERSION < v"1.6.0" ? " " : ""
7878
@test sprint(show, MIME("text/plain"), cols) == """
7979
3280×2 VecColumnTable:
80-
:wave Int64$w
81-
:oop_spend Float64"""
80+
Row │ wave oop_spend
81+
│ Int64 Float64
82+
──────┼──────────────────
83+
1 │ 10 6532.91
84+
2 │ 8 1326.93
85+
3 │ 11 1050.33
86+
4 │ 9 979.418
87+
5 │ 7 5498.68
88+
⋮ │ ⋮ ⋮
89+
3276 │ 11 3020.78
90+
3277 │ 8 2632.0
91+
3278 │ 9 657.34
92+
3279 │ 10 782.795
93+
3280 │ 7 4182.39"""
8294

8395
@test summary(cols) == "3280×2 VecColumnTable"
8496
summary(stdout, cols)

0 commit comments

Comments
 (0)