Skip to content

Commit

Permalink
v1.0 update (#15)
Browse files Browse the repository at this point in the history
Update to 1.0
  • Loading branch information
jacobadenbaum authored Sep 4, 2018
1 parent be1bf6e commit 3254fc0
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 49 deletions.
11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ os:
- linux
- osx
julia:
- 0.6
- 0.7
- 1.0
- nightly
notifications:
email: false
Expand All @@ -30,8 +31,8 @@ matrix:
# - julia -e 'Pkg.clone(pwd()); Pkg.build("Tables"); Pkg.test("Tables"; coverage=true)'
after_success:
# push coverage results to Coveralls
- julia -e 'cd(Pkg.dir("TexTables")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
- julia -e 'using Pkg; cd(Pkg.dir("TexTables")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
# push coverage results to Codecov
- julia -e 'cd(Pkg.dir("TexTables")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
- julia -e 'Pkg.add("Documenter"); Pkg.add("RDatasets")'
- julia -e 'cd(Pkg.dir("TexTables")); include(joinpath("docs", "make.jl"))'
- julia -e 'using Pkg; cd(Pkg.dir("TexTables")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
- julia -e 'using Pkg; Pkg.add("Documenter"); Pkg.add("RDatasets")'
- julia -e 'using Pkg; cd(Pkg.dir("TexTables")); include(joinpath("docs", "make.jl"))'
7 changes: 4 additions & 3 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
julia 0.6
Formatting
julia 0.7 2
Formatting 0.3.3
Parameters
DataStructures
DataFrames
StatsBase
StatsModels
GLM
GLM 1.0
Distributions
Compat
10 changes: 6 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.7/julia-0.7-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.7/julia-0.7-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/1.0/julia-1.0.0-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/1.0/julia-1.0.0-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

Expand Down Expand Up @@ -40,8 +42,8 @@ install:
build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo();
- C:\projects\julia\bin\julia -e "using Pkg;
Pkg.clone(pwd(), \"TexTables\"); Pkg.build(\"TexTables\")"

test_script:
- C:\projects\julia\bin\julia -e "Pkg.test(\"TexTables\")"
- C:\projects\julia\bin\julia -e "using Pkg; Pkg.test(\"TexTables\")"
22 changes: 19 additions & 3 deletions src/CompositeTable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ end
hcat(tables::Vararg{TexTable}) = reduce(hcat, tables)
vcat(tables::Vararg{TexTable}) = reduce(vcat, tables)

function hvcat(rows::Tuple{Vararg{Int}}, as::Vararg{TexTable})
nbr = length(rows) # number of block rows
rs = Array{Any,1}(undef, nbr)
a = 1
for i = 1:nbr
rs[i] = hcat(as[a:a-1+rows[i]]...)
a += rows[i]
end
vcat(rs...)
end

# Make vcat and hcat work for all TexTables
vcat(t1::TexTable, t2::TexTable) = vcat(convert.(IndexedTable,
(t1, t2))...)
Expand Down Expand Up @@ -265,6 +276,11 @@ function convert(::Type{IndexedTable{N, M}}, t::IndexedTable{N0, M0}) where
return t
end

function promote_rule(::Type{T1}, ::Type{T2}) where
{T1 <: IndexedTable, T2 <: TexTable}
return IndexedTable
end

################################################################################
#################### General Indexing ##########################################
################################################################################
Expand All @@ -287,7 +303,7 @@ function insert_index!(index::Index{N}, idx::TableIndex{N}) where N
# If it does, then we don't have to do anything except check that the
# strings are right
if idx.name[N] in N_names
loc = find(N_names .== idx.name[N])[1]
loc = findall(N_names .== idx.name[N])[1]

# Here's the new index
new_idx = update_index(idx, tuple(idx.idx[1:N-1]..., loc))
Expand Down Expand Up @@ -407,12 +423,12 @@ function loc(t::IndexedTable{N,M}, ridx::Indexable{N},
end

function locate(index::Vector{TableIndex{N}}, idx::TableIndex{N}) where N
return find(index .== idx)
return findall(index .== Ref(idx))
end

function locate(index::Vector{TableIndex{N}}, idx) where N
length(idx) == N || throw(ArgumentError("$idx does not have dimension $N"))
return find(index) do x
return findall(index) do x
for i=1:N
match_index(x, idx[i], i) || return false
end
Expand Down
13 changes: 7 additions & 6 deletions src/FormattedNumbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ macro fmt(ex)
@assert(length(ex.args) == 2, msg)
@assert(ex.args[1] isa Symbol, msg)
@assert(isa(ex.args[2], String), msg)
@assert(ex.args[1] in [:Real, :Int, :Bool, :AbstractString], msg)
@assert(ex.args[1] in [:Real, :Int, :Bool, :AbstractString, :Missing], msg)

ex1 = ex.args[1]
ex2 = ex.args[2]
Expand All @@ -39,15 +39,16 @@ end
@fmt Int = "{:,n}"
@fmt Bool = "{:}"
@fmt AbstractString = "{:}"
@fmt Missing = ""

const _fmt_spec_gG = r"[gG]"
const _fmt_spec_g = r"[g]"
const _fmt_spec_G = r"[G]"

function fixed_or_scientific(val, format)
if ismatch(_fmt_spec_gG, format)
if occursin(_fmt_spec_gG, format)
if val isa Integer
return replace(format, _fmt_spec_gG, "n")
return replace(format, _fmt_spec_gG => "n")
else
mag = log(abs(val))/log(10)
if (-Inf < mag <= -3) | (mag >= 5)
Expand All @@ -56,10 +57,10 @@ function fixed_or_scientific(val, format)
r = "f"
end

if ismatch(_fmt_spec_g, format)
return replace(format, _fmt_spec_g, lowercase(r))
if occursin(_fmt_spec_g, format)
return replace(format, _fmt_spec_g => lowercase(r))
else
return replace(format, _fmt_spec_G, uppercase(r))
return replace(format, _fmt_spec_G => uppercase(r))
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions src/Printing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ function get_lengths(printer::TablePrinter{N,M},
# Start out with the assumption that we just need enough space for
# the column contents
k = length(t.columns)
lengths = col_length.(printer, t.columns)
lengths = col_length.(Ref(printer), t.columns)

# Initialize a Block-Width Schema
bw_schema = Dict()
Expand All @@ -245,7 +245,7 @@ function get_lengths(printer::TablePrinter{N,M},

# Figure out the block width, accounting for the extra
# space from the separators and the padding
block_width = sum(lengths[(1:block_size) + col_pos])
block_width = sum(lengths[(1:block_size) .+ col_pos])
block_width+= (block_size-1)*(2*pad + length(sep))

# If the block is not big enough for the formatted name,
Expand All @@ -255,7 +255,7 @@ function get_lengths(printer::TablePrinter{N,M},
if difference > 0
extra_space = div(difference, block_size)
remainder = rem(difference, block_size)
for j = (1:block_size) + col_pos
for j = (1:block_size) .+ col_pos
lengths[j] += extra_space
if j <= remainder & u == 1
lengths[j] += 1
Expand Down Expand Up @@ -290,7 +290,7 @@ end
function format_name(printer::TablePrinter{N,M}, level::Int,
block_size::Int, name)::String where {N,M}
# ASCII tables just print the centered name
printer.params.table_type == :ascii && return name
printer.params.table_type == :ascii && return string(name)

# LaTeX tables need to print the name in a multi-column environment
# except at the lowest level
Expand Down
4 changes: 2 additions & 2 deletions src/StatsModelsInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ for (block, fname) in zip([:1,:2,:3], [:setcoef!, :setmeta!, :setstats!])
```
$fname(t::$RegCol, key, val[, se]; level=1, name="")
$fname(t::$RegCol, key=>val; level=1, name="")
$fname(t::$RegCol, kv::Associative)
$fname(t::$RegCol, kv::AbstractDict)
```
Inserts into `t` a key/value pair (possibly with a standard error) within
the block. Like the `TableCol` constructor, the pairs can be passed as
Expand Down Expand Up @@ -84,7 +84,7 @@ for (block, fname) in zip([:1,:2,:3], [:setcoef!, :setmeta!, :setstats!])
end
end

@eval function ($fname)(t::RegCol, ps::Associative; level=1, name="")
@eval function ($fname)(t::RegCol, ps::AbstractDict; level=1, name="")
($fname)(t, ps...)
end
end
Expand Down
15 changes: 6 additions & 9 deletions src/TableCol.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ end
#################### Constructors ######################################
########################################################################

function TableCol(header::Printable, kv::Associative)
function TableCol(header::Printable, kv::AbstractDict)
pairs = collect(TableIndex(i, key)=>FormattedNumber(value)
for (i, (key, value)) in enumerate(kv))
TableCol(header,
OrderedDict{TableIndex{1}, FormattedNumber}(pairs))
end

function TableCol(header, kv::Associative, kp::Associative)
function TableCol(header, kv::AbstractDict, kp::AbstractDict)
TableCol(header,
OrderedDict{TableIndex{1}, FormattedNumber}(
TableIndex(i, key)=>(key in keys(kp)) ?
Expand Down Expand Up @@ -150,13 +150,10 @@ end

function get_vals(col::TableCol, x::TableIndex, backup="")
if x in keys(col.data)
val, seval, star = get_vals(col.data[x])
return get_vals(col.data[x])
else
val = backup
seval = ""
star = ""
return backup, "", ""
end
return val, seval, star
end

# This is an inefficient backup getindex method to maintain string
Expand All @@ -178,9 +175,9 @@ function getindex(col::TableCol, key::Printable)
end

function name_lookup(col::TableCol{N,M}, x::Symbol) where {N,M}
index = keys(col.data)
index = keys(col.data) |> collect
names = get_name(index, N)
return find(names .== x)
return findall(y->y==x, names)
end

function getindex(col::TableCol, x::TableIndex)
Expand Down
4 changes: 2 additions & 2 deletions src/TexTables.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
__precompile__()
module TexTables

# package code goes here
Expand All @@ -11,6 +10,7 @@ using StatsBase
using Distributions
using GLM: LinearModel
using Parameters
using Compat

export FormattedNumber, FNum, FNumSE, @fmt, TableCol, star!
export TableCol, Table, TexTable, get_vals
Expand All @@ -21,7 +21,7 @@ export setcoef!, setmeta!, setstats!, RegCol
# Import from base to extend
import Base.getindex, Base.setindex!, Base.push!
import Base: isless, ==
import Base: getindex, size, hcat, vcat, convert, promote_rule
import Base: getindex, size, hcat, vcat, hvcat, convert, promote_rule
import Base: show, size, print

export summarize, summarize_by, tabulate
Expand Down
4 changes: 3 additions & 1 deletion test/composite_tables.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Baseline check
srand(1234)
using Random

Random.seed!(1234)
x = randn(10)
y = [Symbol(:key, i) for i=1:10]
t1 = TableCol("test", y, x)
Expand Down
5 changes: 2 additions & 3 deletions test/examples.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using RDatasets, TexTables, DataStructures, DataFrames
using StatsModels, GLM
using TexTables, DataStructures, DataFrames
using StatsModels, GLM, RDatasets

@testset "Linear Model Examples No Stars" begin
# Check that this code runs without errors
Expand Down Expand Up @@ -137,7 +137,6 @@ end
# that all the join_methods are non-mutating)
compare_file(24, to_ascii(group1, star=true))
compare_file(25, to_tex(group1, star=true))

end

@testset "Summary Tables" begin
Expand Down
1 change: 0 additions & 1 deletion test/formatted_numbers.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

@testset "Check Constructor" begin

@testset "No SE" begin
Expand Down
4 changes: 2 additions & 2 deletions test/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ gv = get_vals
@testset "IndexedTable Indexing" begin

# Construct some random tables
srand(1234)
Random.seed!(1234)
x = randn(10)
y = [Symbol(:key, i) for i=1:10]
t1 = TableCol("test", y, x)
Expand Down Expand Up @@ -143,7 +143,7 @@ gv = get_vals

@testset "IndexedTable Indexing" begin
# Baseline check
srand(1234)
Random.seed!(1234)
x = randn(10)
y = [Symbol(:key, i) for i=1:10]
t1 = TableCol("test", y, x) |> IndexedTable
Expand Down
4 changes: 2 additions & 2 deletions test/printing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import TexTables: get_level, generate_schema, check_table_type,

@testset "Extracting Index Levels" begin
# Standard Composite Tables
srand(1234)
Random.seed!(1234)
x = randn(10)
y = [Symbol(:key, i) for i=1:10]
t1 = TableCol("test", y, x)
Expand Down Expand Up @@ -42,7 +42,7 @@ end

@testset "Index Schemas" begin
# Standard Composite Tables
srand(1234)
Random.seed!(1234)
x = randn(10)
y = [Symbol(:key, i) for i=1:10]
t1 = TableCol("test", y, x)
Expand Down
1 change: 0 additions & 1 deletion test/quicktools.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import TexTables: tuplefy

@testset "tuplefy" begin
Expand Down
6 changes: 5 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using TexTables
import TexTables: TableIndex, TableDict
using DataStructures
using Base.Test
using DataFrames
using Test
using Random
using LinearAlgebra
using Statistics

include("helper.jl")

Expand Down

0 comments on commit 3254fc0

Please sign in to comment.