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

Filtering of eachrow(df) not working in 1.4.0 #3191

Closed
dalum opened this issue Oct 5, 2022 · 2 comments · Fixed by #3192
Closed

Filtering of eachrow(df) not working in 1.4.0 #3191

dalum opened this issue Oct 5, 2022 · 2 comments · Fixed by #3192
Labels
Milestone

Comments

@dalum
Copy link

dalum commented Oct 5, 2022

On 1.3.6:

julia> df = DataFrame(:a => [1, 2, 3, 4])
4×1 DataFrame
 Row │ a     
     │ Int64 
─────┼───────
   1 │     1
   2 │     2
   3 │     3
   4 │     4

julia> rows = filter(row -> row[:a] > 2, eachrow(df))
2-element Vector{DataFrameRow}:
 DataFrameRow
 Row │ a     
     │ Int64 
─────┼───────
   3 │     3
 DataFrameRow
 Row │ a     
     │ Int64 
─────┼───────
   4 │     4

On 1.4.0:

julia> df = DataFrame(:a => [1, 2, 3, 4])
rows 4×1 DataFrame
 Row │ a     
     │ Int64 
─────┼───────
   1 │     1
   2 │     2
   3 │     3
   4 │     4

julia> rows = filter(row -> row[:a] > 2, eachrow(df))
0×1 DataFrameRows

I couldn't see anything in the release notes about this. Is this new behaviour expected?

@bkamins bkamins added the bug label Oct 5, 2022
@bkamins bkamins added this to the patch milestone Oct 5, 2022
@bkamins
Copy link
Member

bkamins commented Oct 5, 2022

This is a bug.

@bkamins
Copy link
Member

bkamins commented Oct 5, 2022

The change is mentioned in Performance section of NEWS.md:

Make one-dimensional multi-element indexing of DataFrameRows return DataFrameRows (#3037)

It is fixed in #3192. The bug is that getindex aliased passed selector vector in some cases (and filter in Base for some reason later empties this vector).

The change I describe is that now:

julia> df = DataFrame(:a => [1, 2, 3, 4])
4×1 DataFrame
 Row │ a
     │ Int64
─────┼───────
   1 │     1
   2 │     2
   3 │     3
   4 │     4

julia> eachrow(df)[2:3]
2×1 DataFrameRows
 Row │ a
     │ Int64
─────┼───────
   1 │     2
   2 │     3

returns DataFrameRows (not a Vector of DataFrameRow) as this will be significantly faster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants