Skip to content
This repository was archived by the owner on May 4, 2019. It is now read-only.

Commit

Permalink
Fix MethodError when calling groupby, unstack, etc (#274)
Browse files Browse the repository at this point in the history
* Fix MethodError when calling groupby, unstack, etc

* Fix PooledDataArray for types such that convert(typeof(d), unique(d)) does not exist.
Add 2 unit tests for issue #273

* More concise notation for the convert in PDAs
  • Loading branch information
LouisMagarshack authored and andreasnoack committed Jul 6, 2017
1 parent 5eb6b7d commit 77c2592
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/pooleddataarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ end
function PooledDataArray{T,R<:Integer,N}(d::AbstractArray{T, N},
m::AbstractArray{Bool, N},
r::Type{R} = DEFAULT_POOLED_REF_TYPE)
pool = convert(Array, unique(d[.!m]))
pool = convert(Vector{T}, unique(d[.!m]))
if method_exists(isless, (T, T))
sort!(pool)
end
Expand Down
11 changes: 11 additions & 0 deletions test/pooleddataarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,15 @@
end
z = PooledDataArray([1, 2], [1, 2, 3])
@test sort(unique(z)) == DataArray([1, 2])


# Issue #273
# Ensure that PooledDataArray works for arrays with non leaf type elements.
# Those two examples used to throw exceptions.
x = AbstractString["a"]
m = Bool[false]
r = UInt32
@test isa(PooledDataArray(x, m, r), DataArrays.PooledDataArray{AbstractString, UInt32, 1})
x = Integer[1]
@test isa(PooledDataArray(x, m, r), DataArrays.PooledDataArray{Integer, UInt32, 1})
end

0 comments on commit 77c2592

Please sign in to comment.