Skip to content

Commit

Permalink
Fill existing arrays with scalars (#1057)
Browse files Browse the repository at this point in the history
  • Loading branch information
TotalVerb authored and nalimilan committed Sep 20, 2016
1 parent d4ad15b commit 2931693
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/dataframe/dataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,13 @@ function Base.setindex!(df::DataFrame,
end

# df[SingleColumnIndex] = Single Item (EXPANDS TO NROW(DF) if NCOL(DF) > 0)
function Base.setindex!(df::DataFrame,
v::Any,
col_ind::ColumnIndex)
insert_single_column!(df, upgrade_scalar(df, v), col_ind)
function Base.setindex!(df::DataFrame, v, col_ind::ColumnIndex)
if haskey(index(df), col_ind)
fill!(df[col_ind], v)
else
insert_single_column!(df, upgrade_scalar(df, v), col_ind)
end
return df
end

# df[MultiColumnIndex] = DataFrame
Expand Down Expand Up @@ -397,7 +400,7 @@ function Base.setindex!{T <: ColumnIndex}(df::DataFrame,
col_inds::AbstractVector{T})
dv = upgrade_vector(v)
for col_ind in col_inds
insert_single_column!(df, dv, col_ind)
df[col_ind] = dv
end
return df
end
Expand All @@ -411,9 +414,8 @@ end
function Base.setindex!{T <: ColumnIndex}(df::DataFrame,
val::Any,
col_inds::AbstractVector{T})
dv = upgrade_scalar(df, val)
for col_ind in col_inds
insert_single_column!(df, dv, col_ind)
df[col_ind] = val
end
return df
end
Expand Down
8 changes: 8 additions & 0 deletions test/index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,12 @@ for name in names(i)
i2[name] # Issue #715
end

#= Aliasing & Mutation =#

# columns should not alias if scalar broadcasted
df = DataFrame(A=[0],B=[0])
df[1:end] = 0.0
df[1,:A] = 1.0
@test df[1,:B] === 0

end

0 comments on commit 2931693

Please sign in to comment.