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

Commit 5b4bb42

Browse files
committed
Use setindex! to implement append!
1 parent f2a403a commit 5b4bb42

File tree

3 files changed

+7
-101
lines changed

3 files changed

+7
-101
lines changed

src/dataarray.jl

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -164,48 +164,6 @@ function Base.resize!{T}(da::DataArray{T,1}, n::Int)
164164
da
165165
end
166166

167-
#' @description
168-
#'
169-
#' Append the elements of items to the end of d.
170-
#'
171-
#' @param da::DataArray{T,1} The DataArray to append elements to.
172-
#' @param items::DataArray{T,1} Elements to append to da.
173-
#'
174-
#' @returns: out::DataArray{T,1} The modified data array.
175-
#'
176-
#' @examples
177-
#'
178-
#' x = @data [1, 2, 3]
179-
#' y = @data [4, 5, 6]
180-
#' append!(x, y)
181-
function Base.append!{T}(da::DataArray{T,1}, items::DataArray{T,1})
182-
append!(da.data, items.data)
183-
append!(da.na, items.na)
184-
da
185-
end
186-
187-
#' @description
188-
#'
189-
#' Append the elements of items to the end of d.
190-
#'
191-
#' @param da::DataArray{T,1} The DataArray to append elements to.
192-
#' @param items::AbstractArray{T,1} Elements to append to da.
193-
#'
194-
#' @returns: out::DataArray{T,1} The modified data array.
195-
#'
196-
#' @examples
197-
#'
198-
#' x = @data [1, 2, 3]
199-
#' y = [4, 5, 6]
200-
#' append!(x, y)
201-
function Base.append!{T}(da::DataArray{T,1}, items::AbstractArray{T,1})
202-
append!(da.data, items)
203-
oldn = length(da.na)
204-
resize!(da.na, oldn + length(items))
205-
da.na[oldn+1:end] = false
206-
da
207-
end
208-
209167
#' @description
210168
#'
211169
#' Create a new DataArray{T} that is similar to an existing DataArray.

src/datavector.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ end
161161

162162
Base.deleteat!(pdv::PooledDataVector, inds) = (deleteat!(pdv.refs, inds); pdv)
163163

164+
function Base.append!(da::AbstractDataVector, items::AbstractVector)
165+
oldn = length(da)
166+
resize!(da, oldn+length(items))
167+
da[oldn+1:end] = items
168+
da
169+
end
170+
164171
# Pad a vector with NA's
165172

166173
function padNA(dv::AbstractDataVector,

src/pooleddataarray.jl

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -167,65 +167,6 @@ function Base.resize!{T,R}(pda::PooledDataArray{T,R,1}, n::Int)
167167
pda
168168
end
169169

170-
function Base.append!{T,R1,R2}(x::PooledDataArray{T,R1,1}, y::PooledDataArray{T,R2,1})
171-
pool = myunique(vcat(x.pool, y.pool))
172-
xn, yn = length(x), length(y)
173-
resize!(x.refs, xn + yn)
174-
175-
xtidx::Array{R1} = findat(pool, x.pool)
176-
for i in 1:xn
177-
if x.refs[i] != 0
178-
x.refs[i] = xtidx[x.refs[i]]
179-
end
180-
end
181-
182-
ytidx::Array{R1} = findat(pool, y.pool)
183-
for i in 1:yn
184-
x.refs[xn + i] = y.refs[i] == 0 ? 0 : ytidx[y.refs[i]]
185-
end
186-
187-
x.pool = pool
188-
return x
189-
end
190-
191-
192-
function Base.append!{T,R}(x::PooledDataArray{T,R,1}, y::AbstractArray{T,1})
193-
poolref = Dict{T, R}()
194-
for i in 1:length(x.pool)
195-
poolref[x.pool[i]] = i
196-
end
197-
for v in y
198-
if !isna(v) && !haskey(poolref, v)
199-
poolref[v] = length(poolref) + 1
200-
end
201-
end
202-
203-
pool = Array(T, length(poolref))
204-
for (v, i) in poolref
205-
pool[i] = v
206-
end
207-
208-
xn, yn = length(x), length(y)
209-
resize!(x.refs, xn + yn)
210-
211-
xtidx::Array{R} = findat(pool, x.pool)
212-
for i in 1:xn
213-
if x.refs[i] != 0
214-
x.refs[i] = xtidx[x.refs[i]]
215-
end
216-
end
217-
218-
for i in 1:yn
219-
if !isna(y[i])
220-
x.refs[i+xn] = poolref[y[i]]
221-
end
222-
end
223-
x.pool = pool
224-
return x
225-
end
226-
227-
228-
229170
##############################################################################
230171
##
231172
## Predicates, including the new isna()

0 commit comments

Comments
 (0)