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

Should InvertedIndices call to_indices on all elements in an array of skipped indices? #31

Open
bkamins opened this issue Jun 4, 2022 · 3 comments · May be fixed by #41
Open

Should InvertedIndices call to_indices on all elements in an array of skipped indices? #31

bkamins opened this issue Jun 4, 2022 · 3 comments · May be fixed by #41
Labels

Comments

@bkamins
Copy link
Member

bkamins commented Jun 4, 2022

We have the following super bad behavior:

julia> [1, 2, 3, 4][Not(Not([1.5]))]
1-element Vector{Int64}:
 2

julia> [1, 2, 3, 4][Not(Not([1.5]))]
1-element Vector{Int64}:
 0

julia> [1, 2, 3, 4][Not(Not([1.5]))]
1-element Vector{Int64}:
 4294967297

which is a consequence of the fact that:

to_index(I::AbstractArray) = I

in Base.

@mbauman - do you think we should fix it in InvertedIndices.jl or this should be fixed in Base?

CC @nalimilan

@bkamins bkamins added the bug label Jun 4, 2022
@bkamins
Copy link
Member Author

bkamins commented Jun 5, 2022

Another issue with Not:

julia> x = [1, 2, 3]
3-element Vector{Int64}:
 1
 2
 3

julia> x[Not(Integer[true, 2])]
1-element Vector{Int64}:
 3

and this should error

@mbauman mbauman linked a pull request Dec 3, 2024 that will close this issue
mbauman added a commit that referenced this issue Dec 11, 2024
* ensure that iterate generates `length(I)` values
* ensure that iterate always makes it to the end of all skips

addresses the most egregious bad behaviors in #7 and #31
@mbauman mbauman changed the title Consequence of bug in to_index in Base Should InvertedIndices call to_indices on all elements in an array of skipped indices? Dec 11, 2024
mbauman added a commit that referenced this issue Dec 11, 2024
* ensure that iterate generates `length(I)` values
* ensure that iterate always makes it to the end of all skips

addresses the most egregious bad behaviors in #7 and #31
@mbauman
Copy link
Collaborator

mbauman commented Dec 11, 2024

Fundamentally, the challenge here is that to_indices assumes that an array of N indices will generate N scalar getindex calls (or some cartesian product thereof). And if they're not the canonical index types, those scalar getindex calls will happily call to_indices once again.

But what can we do if we're skipping those elements? More fundamentally, how do we prove that a skipped index would otherwise be a valid index — and which one is it? Should we pre-emptively map to_indices over all arrays of skipped indices? Maybe only if they'd change? Or should we try to do it lazily (that's #41; it's pretty ugly)?

I am slightly curious how DataFrames is avoiding the troubles that #7 displays.

mbauman added a commit that referenced this issue Dec 11, 2024
* ensure that iterate generates `length(I)` values
* ensure that iterate always makes it to the end of all skips

addresses the most egregious bad behaviors in #7 and #31
@bkamins
Copy link
Member Author

bkamins commented Dec 12, 2024

DataFrames.jl provides a custom implementation of Not for column selection.

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