Skip to content

Commit

Permalink
Merge ccec23e into 136fea9
Browse files Browse the repository at this point in the history
  • Loading branch information
Pietro Vertechi committed Nov 26, 2018
2 parents 136fea9 + ccec23e commit 606b344
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
julia 0.7
NamedArrays 0.9.1
CategoricalArrays 0.3.0
DataFrames 0.11.0
Tables
2 changes: 1 addition & 1 deletion src/FreqTables.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module FreqTables
using CategoricalArrays
using DataFrames
using Tables
using NamedArrays

include("freqtable.jl")
Expand Down
6 changes: 4 additions & 2 deletions src/freqtable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ freqtable(x::AbstractCategoricalVector...; skipmissing::Bool = false,
subset::Union{Nothing, AbstractVector{Int}, AbstractVector{Bool}} = nothing) =
_freqtable(x, skipmissing, weights, subset)

function freqtable(d::AbstractDataFrame, x::Symbol...; args...)
a = freqtable([d[y] for y in x]...; args...)
function freqtable(d, x::Symbol...; args...)
Tables.istable(d) || throw(ArgumentError("data must be a table"))
cols = Tables.columns(d)
a = freqtable((getproperty(cols, y) for y in x)...; args...)
setdimnames!(a, x)
a
end
Expand Down
1 change: 1 addition & 0 deletions test/REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
CSV 0.2.0
DataFrames 0.11.0
5 changes: 4 additions & 1 deletion test/freqtable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ for docat in [false, true]
3 8]
@test names(tab[1:2, :]) == [["setosa", "versicolor"], [false, true]]

iris_nt = (Species = iris[:Species], LongSepal = iris[:LongSepal])
@test freqtable(iris, :Species, :LongSepal) == freqtable(iris_nt, :Species, :LongSepal)

@test_throws ArgumentError freqtable(iris)
@test_throws ArgumentError freqtable(nothing, :Species, :LongSepal)
end

# Issue #5
Expand All @@ -186,4 +190,3 @@ intft = freqtable(df, :A, :B)

@test_throws BoundsError intft[101,"x"]
@test intft[Name(101),"x"] == 1

0 comments on commit 606b344

Please sign in to comment.