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

Support setproperty as well to modify columns in place #11

Closed
piever opened this issue Sep 2, 2018 · 4 comments
Closed

Support setproperty as well to modify columns in place #11

piever opened this issue Sep 2, 2018 · 4 comments

Comments

@piever
Copy link

piever commented Sep 2, 2018

In the same way as Tables implements getproperty for a "lazy row" of a NamedTuple of vectors here, I wonder whether it should also implement setproperty!. This is a nice bonus of using a lazy row rather than a NamedTuple for iteration: we can get DataFramesMeta's @byrow! for free. For example:

foreach(rows(df)) do row
  row[:c] = row[:a] + row[:b]
end
@quinnj
Copy link
Member

quinnj commented Sep 5, 2018

Certainly something worth considering; it would definitely have to be optional, since a number of sources couldn't support this (CSV row-iterator, SQLite table row-iterator, etc.), but for those that could, it would certainly be handy.

@quinnj
Copy link
Member

quinnj commented Feb 2, 2019

I don't think there's anything Tables.jl-specific here; if a custom Row type wants to support setproperty!, then there's nothing stopping them from doing so and documenting that it works. It isn't something the Tables.jl interface needs (or wants) to enforce though (NamedTuples already couldnt' support this).

@quinnj quinnj closed this as completed Feb 2, 2019
@piever
Copy link
Author

piever commented Feb 2, 2019

Maybe one thing that could be done on the Tables side is to add a setproperty! method to the default fallback for row iteration of a columnstable (where each row is a ColumnsRow). Say:

function Base.setproperty!(c::ColumnsRow, nm::Symbol, x)
    getproperty(getfield(c, 1), nm)[getfield(c, 2)] = x
end

In this way it would be clear that all column based storage can have a setproperty! method on rows (and they would, by default, if they don't implement a "non-fallback" row access).

@nalimilan nalimilan reopened this Feb 4, 2019
@quinnj
Copy link
Member

quinnj commented Feb 8, 2020

With #131 merged, I'd like to commit to a simple, generic Tables.jl interface that is mainly about table transfer and consumption. I've proposed in another issue that it seems to make sense to get together and define a stricter interface that would support in-place and mutating operations.

@quinnj quinnj closed this as completed Feb 8, 2020
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