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

Commit

Permalink
Merge pull request #194 from JuliaStats/alyst/repeat_methods
Browse files Browse the repository at this point in the history
repeat() methods for DataArray and PooledDataArray
  • Loading branch information
nalimilan committed Jun 5, 2016
2 parents af1f8da + d6b8cbc commit d8999c7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/extras.jl
Expand Up @@ -62,3 +62,17 @@ function cut{S, T}(x::AbstractVector{S}, breaks::Vector{T})
end

cut(x::AbstractVector, ngroups::Integer) = cut(x, quantile(x, [1 : ngroups - 1] / ngroups))

function Base.repeat{T,N}(A::DataArray{T,N};
inner::Array{Int} = ones(Int, ndims(A)),
outer::Array{Int} = ones(Int, ndims(A)))
DataArray{T,N}(Compat.repeat(A.data; inner=inner, outer=outer),
bitpack(Compat.repeat(A.na; inner=inner, outer=outer)))

This comment has been minimized.

Copy link
@dmbates

dmbates Jun 7, 2016

Contributor

I don't think the bitpack call is necessary as Compat.repeat returns a BitArray. The use of bitpack causes a deprecation warning in v0.5-dev.

end

function Base.repeat{T,R,N}(A::PooledDataArray{T,R,N};
inner::Array{Int} = ones(Int, ndims(A)),
outer::Array{Int} = ones(Int, ndims(A)))
PooledDataArray(RefArray{R,N}(Compat.repeat(A.refs; inner=inner, outer=outer)),
A.pool)
end
14 changes: 14 additions & 0 deletions test/extras.jl
Expand Up @@ -35,4 +35,18 @@ module TestExtras
"(35,60]", "(25,35]", "(60,100]",
"(35,60]", "(35,60]", "(25,35]"])
@assert isequal(cats, pdv)

##########
## repeat
##########

@test isequal(repeat(@data [3.0, 2.0, NA]; inner = [2], outer = [1]),
@data [3.0, 3.0, 2.0, 2.0, NA, NA])
@test isequal(repeat(@pdata ["a", "b", NA]; inner = [2], outer = [1]),
@pdata ["a", "a", "b", "b", NA, NA])
@test isequal(repeat(@data [1 2; 3 NA]; inner = [1, 2], outer = [2, 1]),
@data [1 1 2 2; 3 3 NA NA; 1 1 2 2; 3 3 NA NA])
@test isequal(repeat(@pdata [:a :b NA]; inner = [2,1], outer = [1,3]),
@pdata [:a :b NA :a :b NA :a :b NA;
:a :b NA :a :b NA :a :b NA])
end

0 comments on commit d8999c7

Please sign in to comment.