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

ShiftedArray's lag causes an AssertionError when used with groupby and transform #146

Closed
robsmith11 opened this issue Apr 21, 2020 · 3 comments

Comments

@robsmith11
Copy link

See the example below:

julia> using ShiftedArrays                                                   

julia> df = DataFrame(x=rand(10), y=rand(1:3, 10))
10×2 DataFrame
│ Row │ x        │ y     │
│     │ Float64  │ Int64 │
├─────┼──────────┼───────┤
│ 1   │ 0.606215 │ 3     │
│ 2   │ 0.128396 │ 1     │
│ 3   │ 0.194318 │ 3     │
│ 4   │ 0.139702 │ 1     │
│ 5   │ 0.766211 │ 3     │
│ 6   │ 0.806462 │ 2     │
│ 7   │ 0.162772 │ 3     │
│ 8   │ 0.863007 │ 1     │
│ 9   │ 0.269158 │ 3     │
│ 10  │ 0.105715 │ 3     │

julia> @linq df |> groupby(:y) |> transform(prevx=lag(:x))
ERROR: AssertionError: newtype_first === nothing
Stacktrace:
 [1] _transform!(::Array{Missing,1}, ::ShiftedArray{Float64,Missing,1,SubArray{Float64,1,Array{Float64,1},Tuple{Array{Int64,1}},false}}, ::Int64, ::GroupedDataFrame{DataFrame}, ::var"#251#252", ::Array{Int64,1}, ::Array{Int64,1}) at /home/me/.julia/packages/DataFramesMeta/c88dH/src/DataFramesMeta.jl:427
 [2] transform(::GroupedDataFrame{DataFrame}; kwargs::Base.Iterators.Pairs{Symbol,var"#251#252",Tuple{Symbol},NamedTuple{(:prevx,),Tuple{var"#251#252"}}
}) at /home/me/.julia/packages/DataFramesMeta/c88dH/src/DataFramesMeta.jl:0
 [3] top-level scope at /home/me/.julia/packages/DataFramesMeta/c88dH/src/DataFramesMeta.jl:473

However, lag works with both by and transform when called separately:


julia> @linq df |> by(:y, prevx=lag(:x))
10×2 DataFrame
│ Row │ y     │ prevx    │
│     │ Int64 │ Float64⍰ │
├─────┼───────┼──────────┤
│ 1   │ 3     │ missing  │
│ 2   │ 3     │ 0.606215 │
│ 3   │ 3     │ 0.194318 │
│ 4   │ 3     │ 0.766211 │
│ 5   │ 3     │ 0.162772 │
│ 6   │ 3     │ 0.269158 │
│ 7   │ 1     │ missing  │
│ 8   │ 1     │ 0.128396 │
│ 9   │ 1     │ 0.139702 │
│ 10  │ 2     │ missing  │

julia> @linq df |> transform(prevx=lag(:x))
10×3 DataFrame
│ Row │ x        │ y     │ prevx    │
│     │ Float64  │ Int64 │ Float64⍰ │
├─────┼──────────┼───────┼──────────┤
│ 1   │ 0.606215 │ 3     │ missing  │
│ 2   │ 0.128396 │ 1     │ 0.606215 │
│ 3   │ 0.194318 │ 3     │ 0.128396 │
│ 4   │ 0.139702 │ 1     │ 0.194318 │
│ 5   │ 0.766211 │ 3     │ 0.139702 │
│ 6   │ 0.806462 │ 2     │ 0.766211 │
│ 7   │ 0.162772 │ 3     │ 0.806462 │
│ 8   │ 0.863007 │ 1     │ 0.162772 │
│ 9   │ 0.269158 │ 3     │ 0.863007 │
│ 10  │ 0.105715 │ 3     │ 0.269158 │
@bkamins
Copy link
Member

bkamins commented Apr 21, 2020

@pdeffebach
Copy link
Collaborator

Fixed by #163

@bkamins
Copy link
Member

bkamins commented Sep 22, 2020

closing - right?

@bkamins bkamins closed this as completed Sep 22, 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