Skip to content

Commit c07ab6e

Browse files
committed
.= is only allowed for existing columns with df.col and df[!, col]
1 parent e140904 commit c07ab6e

File tree

8 files changed

+252
-160
lines changed

8 files changed

+252
-160
lines changed

src/other/broadcasting.jl

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -170,38 +170,19 @@ function Base.dotview(df::AbstractDataFrame, ::Colon, cols::ColumnIndex)
170170
end
171171

172172
# df[!, cols] .= ...
173-
function Base.dotview(df::AbstractDataFrame, ::typeof(!), cols)
174-
if !(cols isa ColumnIndex)
175-
return ColReplaceDataFrame(df, convert(Vector{Int}, index(df)[cols]))
176-
end
177-
if haskey(index(df), cols)
178-
_drop_all_nonnote_metadata!(parent(df))
179-
return view(df, :, cols)
180-
end
181-
if cols isa SymbolOrString
182-
if columnindex(df, cols) == 0 && !is_column_insertion_allowed(df)
183-
throw(ArgumentError("creating new columns in a SubDataFrame that subsets " *
184-
"columns of its parent data frame is disallowed"))
185-
end
186-
elseif !(1 <= cols <= ncol(df))
187-
throw(ArgumentError("creating new columns using an integer index is disallowed"))
188-
end
189-
return LazyNewColDataFrame(df, cols isa AbstractString ? Symbol(cols) : cols)
173+
function Base.dotview(df::AbstractDataFrame, ::typeof(!), cols::Any)
174+
return ColReplaceDataFrame(df, convert(Vector{Int}, index(df)[cols]))
175+
end
176+
function Base.dotview(df::AbstractDataFrame, ::typeof(!), cols::ColumnIndex)
177+
_drop_all_nonnote_metadata!(parent(df))
178+
return df[!, cols]
190179
end
191180

192181
if isdefined(Base, :dotgetproperty) # Introduced in Julia 1.7
193182
# df.col .= ...
194183
function Base.dotgetproperty(df::AbstractDataFrame, col::SymbolOrString)
195-
if haskey(index(df), col)
196-
_drop_all_nonnote_metadata!(parent(df))
197-
return df[!, col]
198-
end
199-
200-
if columnindex(df, col) == 0 && !is_column_insertion_allowed(df)
201-
throw(ArgumentError("creating new columns in a SubDataFrame that subsets " *
202-
"columns of its parent data frame is disallowed"))
203-
end
204-
return LazyNewColDataFrame(df, Symbol(col))
184+
_drop_all_nonnote_metadata!(parent(df))
185+
return df[!, col]
205186
end
206187
end
207188

0 commit comments

Comments
 (0)