dysonance / Temporal.jl

Time series implementation for the Julia language focused on efficiency and flexibility
Other
101 stars 27 forks source link

rename columns name using a (or several) Pair of Symbol or a Function (Symbol -> Symbol) #22

Closed femtotrader closed 6 years ago

femtotrader commented 6 years ago

Hello,

A rename! function which rename several columns name using a Dict of Symbols or a column name using 2 Symbols (from_name, to_name) or a Pair of Symbol could probably be an interesting feature to have

See https://github.com/dysonance/Temporal.jl/issues/20#issuecomment-356232253

Kind regards

PS :

Such a rename! function could be implemented like this:

function rename!(data::TS, d::Dict{Symbol, Symbol})
    flag = false
    for (i, field) in enumerate(data.fields)
        if field in keys(d)
            data.fields[i] = d[field]
            flag = true
        end
    end
    flag
end

rename! could also accept Pair{Symbol, Symbol} or 2 symbols as parameter

function rename!(data::TS, from_name::Symbol, to_name::Symbol)
    rename!(data, Dict(from_name=>to_name))
end

function rename!(data::TS, p::Pair{Symbol, Symbol})
    rename!(data, Dict(p))
end
femtotrader commented 6 years ago
function rename!(f::Base.Callable, data::TS)

end

where f is a function

might also be implemented

see https://github.com/dysonance/Temporal.jl/issues/23

femtotrader commented 6 years ago

Supporting multiple Pair{Symbol,Symbol} instead of Dict{Symbol, Symbol} is an other possible approach.

rename!(data, :Open => :Open2, :Close => :Close2)

It seems to be the kind of API Julia base replace function should be going.

If replacement is in a Dict it can be done using

rename!(data, Dict(:Open => :Open2, :Close => :Close2)...)