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

Why does @byrows! contain the bang (!) at the end of its name when it is not modifying the input argument? #140

Closed
hurak opened this issue Dec 26, 2019 · 4 comments

Comments

@hurak
Copy link

hurak commented Dec 26, 2019

Why does @byrows! contain the bang (!) at the end of its name when it is not modifying the input argument?

An example

First, define some DataFrame df

julia> df = DataFrame(x = 1:3, y = [2, 1, 2])
3×2 DataFrame
│ Row │ x     │ y     │
│     │ Int64 │ Int64 │
├─────┼───────┼───────┤
│ 112     │
│ 221     │
│ 332

Now do some modifications using @byrows!

@byrow! df if :x > :y; :x = :y *3 end
3×2 DataFrame
│ Row │ x     │ y     │
│     │ Int64 │ Int64 │
├─────┼───────┼───────┤
│ 112     │
│ 231     │
│ 362

and yet the original DataFrame df remains intact:

julia> df
3×2 DataFrame
│ Row │ x     │ y     │
│     │ Int64 │ Int64 │
├─────┼───────┼───────┤
│ 112     │
│ 221     │
│ 332
@henriquebecker91
Copy link
Contributor

Great question, I stumbled in this behavior again today. I think it is a bug, because the documentation uses as the first example of @byrow!:

@byrow! df if :A > :B; :A = :B * :C end

That makes no sense without the input argument mutation. Then, in the sequence, in the context of the special syntax for new columns, the documentation says:

Note that the returned AbstractDataFrame includes these new columns, but the original df is not affected.

As this was an exception of the behavior just for the case in which new columns are added.

@pdeffebach
Copy link
Collaborator

I think this is a bug as well, @bkamins do you agree?.

@henriquebecker91 or @hurak Would either mind opening a PR to deprecate this behavior?

That is, people will still be able to use @byrow! but they will get a warning and be told to use @byrow instead.

@henriquebecker91
Copy link
Contributor

Done: #154

@bkamins
Copy link
Member

bkamins commented Jul 10, 2020

Yes - @byrow is better I think.

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

5 participants