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

Fill existing arrays with scalars #1057

Merged
merged 1 commit into from
Sep 20, 2016

Conversation

TotalVerb
Copy link
Contributor

Closes #1053 (replacing it). Fixes #1051. Closes (maybe?) #1054, pending possible further discussion.

This implements @nalimilan and @andreasnoack's idea of filling arrays with scalars instead of creating new ones.

@@ -368,7 +380,7 @@ end
function Base.setindex!(df::DataFrame,
v::Any,
col_ind::ColumnIndex)
insert_single_column!(df, upgrade_scalar(df, v), col_ind)
fill_single_column!(df, v, col_ind)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't setindex! for the column type handle this, e.g. something like

df[:col_ind] = v

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is setindex! for the column type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you're right in that the fill_single_column! function is just setindex!. I suppose it would be easier just to inline this function.

Copy link
Member

@andreasnoack andreasnoack Sep 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. What I meant was to use setindex for the DataVector/NullableVector which would probably be something like

df[:col_ind][:] = v

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Unfortunately df[:col_ind] .= v does not work (even on v0.6) due to broadcast! being a little particular with what data types it considers "vectors", such as String. Also, I recall there was a discussion about setindex!(A, v, Colon()) still being slower than fill!(A, v), though I don't know if this issue has been addressed by now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like JuliaLang/julia#16310 has closed the performance difference, although that means it still exists on v0.4. I think keeping fill! might be better for now.

Copy link
Contributor Author

@TotalVerb TotalVerb Sep 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've inlined the fill_single_column! function now into setindex!.

@andreasnoack
Copy link
Member

Great. Seems much simpler. Don't the tests fit into index.jl?

@TotalVerb
Copy link
Contributor Author

There used to be a few more tests for vector setindex! aliasing, but that's not fixed here (needs a more copying solution like #1054). I can put this one in index.jl.

@TotalVerb
Copy link
Contributor Author

OK, test merged into index.jl now.

function Base.setindex!(df::DataFrame, v, col_ind::ColumnIndex)
if haskey(index(df), col_ind)
j = index(df)[col_ind]
fill!(df.columns[j], v)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't fill!(df[col_ind], v) work here?

Copy link
Contributor Author

@TotalVerb TotalVerb Sep 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@dmbates
Copy link
Contributor

dmbates commented Sep 20, 2016

Is this ready to be merged now?

@nalimilan nalimilan merged commit 2931693 into JuliaData:master Sep 20, 2016
maximerischard pushed a commit to maximerischard/DataFrames.jl that referenced this pull request Sep 28, 2016
ararslan pushed a commit that referenced this pull request Oct 7, 2016
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

Successfully merging this pull request may close these issues.

5 participants