Dataframes.jl: Improvement of rename!

Created on 24 Apr 2019  路  7Comments  路  Source: JuliaData/DataFrames.jl

rename!(f::Function, df) is not really convenient as f normally has to convert column names to string, operate on a string and convert it back to Symbol.

Two ideas:

  1. (more radical) maybe we should change rename! to assume that f takes a string a returns a string and Symbol unwrapping/wrapping happens automatically
  2. (less radical) maybe we can add a kwarg to rename! that would allow the user to choose if f is from string to string or from Symbol to Symbol

All 7 comments

At least we could allow returning a string in addition to a symbol. Not sure about converting the argument to string before passing it, as it would be inconsistent with the fact that we use symbols everywhere.

Actually in this case the change could be quite small and non breaking - we can simply cast whatever is returned by f to Symbol (or restrict casting only to AbstractString).

Would also be great to be able to do pairs of Int=>Symbol so that one can rename columns by index rather than name. I'm often in a situation where I need to rename the first column of a bunch of tables where I don't necessarily know the name. So something like rename(df, 1=>:a) and rename(df, [1=>:a, 2=>:b])

Now we allow string or Symbol as "oldcol", do we still want to add integers?

Why not, if somebody wants to implement that...

I have opened https://github.com/JuliaData/DataFrames.jl/pull/2030 for this (as the docstrings for rename and rename! needed decoupling and a clean-up anyway).

all is done here. closing.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bbrunaud picture bbrunaud  路  3Comments

davidanthoff picture davidanthoff  路  4Comments

bkamins picture bkamins  路  8Comments

rofinn picture rofinn  路  3Comments

pdeffebach picture pdeffebach  路  8Comments