Skip to content

Commit

Permalink
Merge pull request #673 from johansigfrids/dontassignna
Browse files Browse the repository at this point in the history
Don't unneecessarily assing NA when constructing empty DataFrames
  • Loading branch information
johnmyleswhite committed Aug 15, 2014
2 parents 2ef2223 + 376af10 commit a0645a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
7 changes: 0 additions & 7 deletions src/dataframe/dataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ function DataFrame(column_eltypes::Vector, cnames::Vector, nrows::Integer)
columns = Array(Any, p)
for j in 1:p
columns[j] = DataArray(column_eltypes[j], nrows)
for i in 1:nrows
columns[j][i] = NA
end
end
return DataFrame(columns, Index(cnames))
end
Expand All @@ -150,9 +147,6 @@ function DataFrame(column_eltypes::Vector, nrows::Integer)
cnames = gennames(p)
for j in 1:p
columns[j] = DataArray(column_eltypes[j], nrows)
for i in 1:nrows
columns[j][i] = NA
end
end
return DataFrame(columns, Index(cnames))
end
Expand Down Expand Up @@ -1092,4 +1086,3 @@ function Base.push!(df::DataFrame, iterable::Any)
i=i+1
end
end

9 changes: 9 additions & 0 deletions test/dataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,29 @@ module TestDataFrame
@test typeof(df[:, 1]) == DataVector{Int}
@test typeof(df[:, 2]) == DataVector{Int}
@test typeof(df[:, 3]) == DataVector{Int}
@test allna(df[:, 1])
@test allna(df[:, 2])
@test allna(df[:, 3])

df = DataFrame({Int, Float64, ASCIIString}, 100)
@test size(df, 1) == 100
@test size(df, 2) == 3
@test typeof(df[:, 1]) == DataVector{Int}
@test typeof(df[:, 2]) == DataVector{Float64}
@test typeof(df[:, 3]) == DataVector{ASCIIString}
@test allna(df[:, 1])
@test allna(df[:, 2])
@test allna(df[:, 3])

df = DataFrame({Int, Float64, ASCIIString}, [:A, :B, :C], 100)
@test size(df, 1) == 100
@test size(df, 2) == 3
@test typeof(df[:, 1]) == DataVector{Int}
@test typeof(df[:, 2]) == DataVector{Float64}
@test typeof(df[:, 3]) == DataVector{ASCIIString}
@test allna(df[:, 1])
@test allna(df[:, 2])
@test allna(df[:, 3])

df = convert(DataFrame, zeros(10, 5))
@test size(df, 1) == 10
Expand Down

0 comments on commit a0645a8

Please sign in to comment.