Sorry for the mistakes of my example, thanks for pointing out the mistake of the trait. After correcting it, my example works.
But I don’t know why my following case has the problem:
module features_engineering
using DataFrames
function map_atom_info(df::DataFrame, structures::DataFrame,atom_idx::Int)
df = join(df,structures,on = [(:molecule_name,:molecule_name),(Symbol("atom_index_$(atom_idx)"), :atom_index)],kind = :outer)
delete!(df,"atom_idx")
rename!(df, Dict(:atom =>Symbol("atom_$atom_idx"),
:x => :Symbol("x_$atom_idx"),
:y => Symbol("y_$atom_idx"),
:z => Symbol("z_$atom_idx")))
return df
end
function distance_type_feat(train::DataFrame,test::DataFrame,structures::DataFrame)
train = map_atom_info(train,structures, 0)
train = map_atom_info(train,structures, 1)
test = map_atom_info(test,structures, 0)
test = map_atom_info(test,structures, 1)
train_p_0 = train[[:x_0,:y_0,:z_0]]
train_p_1 = train[[:x_1, :y_1, :z_1]]
test_p_0 = test[[:x_0, :y_0, :z_0]]
test_p_1 = test[[:x_1, :y_1, :z_1]]
train[:dist] = norm(train_p_0 - train_p_1)
test[:dist] = norm(test_p_0 - test_p_1)
train[:dist_x] = (train[:x_0] - train[:x_1]) ^ 2
test[:dist_x] = (test[:x_0] - test[:x_1]) ^ 2
train[:dist_y] = (train[:y_0] - train[:y_1]) ^ 2
test[:dist_y] = (test[:y_0] - test[:y_1]) ^ 2
train[:dist_z] = (train[:z_0] - train[:z_1]) ^ 2
test[:dist_z] = (test[:z_0] - test[:z_1]) ^ 2
function substring_(x::String,i::Int)
if i==1
return string(x[1])
elseif i==2
return x[2:end]
else
return "NA"
end
end
train[:type_0] = substring_.(train[:type],1)
test[:type_0] = substring_.(test[:type],1)
train[:type_1] = substring_.(train[:type],2)
test[:type_1] = substring_.(test[:type],2)
return train,test
end
end
MethodError: no method matching join(::DataFrame, ::Tuple{Symbol,Symbol}; on=(:molecule_name, :molecule_name), kind=:outer)
Closest candidates are:
join(::Any, ::Any) at strings/io.jl:277 got unsupported keyword arguments “on”, “kind”
join(::Any, ::Any, !Matched::Any) at strings/io.jl:278 got unsupported keyword arguments “on”, “kind”
join(!Matched::IO, ::Any) at strings/io.jl:269 got unsupported keyword arguments “on”, “kind”
…
map_atom_info(::DataFrame, ::DataFrame, ::Int64) at PMP_20190708.jl:17
distance_type_feat(::DataFrame, ::DataFrame, ::DataFrame) at PMP_20190708.jl:27
top-level scope at none:0