Skip to content

Commit

Permalink
Do not sort dimnames when no isless() method is defined
Browse files Browse the repository at this point in the history
Fixes #5.
  • Loading branch information
nalimilan committed Jan 7, 2016
1 parent 0e671b2 commit f086580
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/freqtable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ function freqtable(x::AbstractVector...;
for j in 1:length(k)
push!(s, k[j][i])
end
dimnames[i] = sort!(unique(s))

dimnames[i] = unique(s)
T = eltype(dimnames[i])
if method_exists(isless, (T, T))
sort!(dimnames[i])
end
end

a = zeros(counttype, ntuple(i -> length(dimnames[i]), n))
Expand Down Expand Up @@ -192,7 +197,12 @@ function freqtable(x::AbstractVector;
for j in 1:length(k)
push!(s, k[j])
end
dimnames = sort!(unique(s))

dimnames = unique(s)
T = eltype(dimnames)
if method_exists(isless, (T, T))
sort!(dimnames)
end

a = zeros(counttype, length(dimnames))
na = NamedArray(a, (dimnames,), ("Dim1",))
Expand Down
4 changes: 4 additions & 0 deletions test/freqtable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ iris[:LongSepal] = iris[:SepalLength] .> 5.0
@test freqtable(iris, :Species, :LongSepal,
subset=iris[:PetalLength] .< 4.0).array ==[28 22
3 8]

# Issue #5
@test freqtable([Set(1), Set(2)]).array == [1, 1]
@test freqtable([Set(1), Set(2)], [Set(1), Set(2)]).array == eye(2)

0 comments on commit f086580

Please sign in to comment.