Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-systematic "New columns must have the same length as old columns" error #46

Closed
nalimilan opened this issue Mar 27, 2016 · 2 comments

Comments

@nalimilan
Copy link
Member

Creating a column with only one value is only an error if it's the first column:

julia> df = DataFrame(A=1:3)
3x1 DataFrames.DataFrame
│ Row │ A │
┝━━━━━┿━━━┥
│ 11 │
│ 22 │
│ 33 │

julia> @select(df, B=1, :A)
ERROR: New columns must have the same length as old columns
 in insert_single_column!(::DataFrames.DataFrame, ::DataArrays.DataArray{Int64,1}, ::Symbol) at /home/milan/.julia/DataFrames/src/dataframe/dataframe.jl:309
 in setindex!(::DataFrames.DataFrame, ::DataArrays.DataArray{Int64,1}, ::Symbol) at /home/milan/.julia/DataFrames/src/dataframe/dataframe.jl:368
 in #select#17(::Array{Any,1}, ::Any, ::DataFrames.DataFrame) at /home/milan/.julia/DataFramesMeta/src/DataFramesMeta.jl:450
 [inlined code] from ./boot.jl:307
 in (::###8232#20{DataFrames.DataFrame})(::DataArrays.DataArray{Int64,1}) at /home/milan/.julia/DataFramesMeta/src/DataFramesMeta.jl:55
 in eval(::Module, ::Any) at ./boot.jl:243

julia> @select(df, :A, B=1)
3x2 DataFrames.DataFrame
│ Row │ A │ B │
┝━━━━━┿━━━┿━━━┥
│ 111 │
│ 221 │
│ 331

Would it make sense to always recycle the columns so that the new data frame has the same number of columns as the original? Other constructs could be recommended for aggregation operations.

@tshort
Copy link
Contributor

tshort commented Mar 27, 2016

I agree that this should recycle. The following PR in DataFrames was meant to address this issue:

JuliaData/DataFrames.jl#882

@tshort
Copy link
Contributor

tshort commented Mar 27, 2016

That PR was on hold because I decided we probably shouldn't recycle except for the case where the value to be put in the new column is a single value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants