-
Notifications
You must be signed in to change notification settings - Fork 54
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
updates for 0.6 #73
updates for 0.6 #73
Changes from 1 commit
6bbcfbc
5cfdd1e
6453883
72c98fb
cd95bd0
abcfb6b
d0d32c1
502cb6e
a52d908
5968b6b
028ff68
cf55db6
083f157
23b106a
f23196b
f9281b4
103582e
5904300
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,12 +28,11 @@ byrow_replace(x) = x | |
|
||
function byrow_find_newcols(e::Expr, newcol_decl) | ||
if e.head == :macrocall && e.args[1] == Symbol("@newcol") | ||
ea = | ||
if VERSION < v"0.7-" | ||
e.args[2] | ||
else | ||
e.args[3] | ||
end | ||
if VERSION < v"0.7-" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to be more exact with the version cutoff used. What changed in Base such that the number of arguments in the expression increased? If you can find the PR that introduced that change, you can use contrib/commit-name.sh in the Julia repo to get the exact version that corresponds to that change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also since this is in a function (but in this case the conditional is less easily separable), the condition should have an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably JuliaLang/julia@3c3ced4? That's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I think it was this: JuliaLang/julia#21746 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would be 0.7.0-DEV.357 then. |
||
ea = e.args[2] | ||
else | ||
ea = e.args[3] | ||
end | ||
# expression to assign a new column to df | ||
return (nothing, Any[Expr(:kw, ea.args[1], Expr(:call, ea.args[2], :_N))]) | ||
else | ||
|
@@ -79,8 +78,8 @@ as in `@with`. Note that the scope within `@byrow!` is a hard scope. | |
with eltype `Int`. Note that the returned `AbstractDataFrame` includes these new | ||
columns, but the original `d` is not affected. This feature makes it easier to | ||
use `byrow!` for data transformations. `_N` is introduced to represent the | ||
length of the dataframe, `_D` represents the dataframe including added columns, | ||
and `row` represents the current row. | ||
length of the dataframe, `_D` represents the `dataframe` including added columns, | ||
and `row` represents the index of the current row. | ||
|
||
### Arguments | ||
|
||
|
@@ -99,11 +98,20 @@ julia> using DataFrames, DataFramesMeta | |
julia> df = DataFrame(A = 1:3, B = [2, 1, 2]); | ||
|
||
julia> let x = 0 | ||
@byrow!(df, if :A + :B == 3; x += 1 end) # This doesn't work without the let | ||
@byrow! df begin | ||
if :A + :B == 3 | ||
x += 1 | ||
end | ||
end # This doesn't work without the let | ||
x | ||
end | ||
2 | ||
|
||
julia> @byrow! df if :A > :B; :A = 0 end | ||
julia> @byrow! df begin | ||
if :A > :B | ||
:A = 0 | ||
end | ||
end | ||
3×2 DataFrames.DataFrame | ||
│ Row │ A │ B │ | ||
├─────┼───┼───┤ | ||
|
@@ -112,9 +120,9 @@ julia> @byrow! df if :A > :B; :A = 0 end | |
│ 3 │ 0 │ 2 │ | ||
|
||
julia> df2 = @byrow! df begin | ||
@newcol colX::Array{Float64} | ||
:colX = :B == 2 ? pi * :A : :B | ||
end | ||
@newcol colX::Array{Float64} | ||
:colX = :B == 2 ? pi * :A : :B | ||
end | ||
3×3 DataFrames.DataFrame | ||
│ Row │ A │ B │ colX │ | ||
├─────┼───┼───┼─────────┤ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,8 @@ row() = nothing | |
|
||
""" | ||
CompositeDataFrame(columns::Vector{Any}, cnames::Vector{Symbol}; inmodule = DataFramesMeta) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrap lines at 92 chars. |
||
CompositeDataFrame(columns::Vector{Any}, cnames::Vector{Symbol}, typename::Symbol; inmodule = DataFramesMeta) | ||
CompositeDataFrame(columns::Vector{Any}, cnames::Vector{Symbol}, typename::Symbol; | ||
inmodule = DataFramesMeta) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be aligned with |
||
CompositeDataFrame(; inmodule = DataFramesMeta, kwargs...) | ||
CompositeDataFrame(typename::Symbol; inmodule = DataFramesMeta, kwargs...) | ||
|
||
|
@@ -57,8 +58,8 @@ This uses `eval` to create a new type within the module specified by the | |
* `typename` : the optional name of the type created | ||
* `kwargs` : the key gives the column names, and the value is the column contents | ||
* `inmodule = DataFramesMeta` : a keyword argument to specify what module you | ||
want to define the type in. Consider passing `current_module()` or | ||
`@__MODULE__` depending on your julia version. | ||
want to define the type in. Consider passing `current_module()` | ||
(`VERSION < v"0.7-") or `@__MODULE__` depending on your julia version. | ||
|
||
### Examples | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to move the conditional outside of the function definition, i.e.
Otherwise the version check is performed every time the function is called.