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

error message for indexing with BitArray #38689

Merged
merged 5 commits into from
Dec 9, 2020
Merged

error message for indexing with BitArray #38689

merged 5 commits into from
Dec 9, 2020

Conversation

JeffFessler
Copy link
Contributor

@JeffFessler JeffFessler commented Dec 3, 2020

Closes #38685 by making the error message for (e.g.) ones(2,3)[trues(4,5)] more informative.

This is a WIP because I don't know how to test locally, so let's see what the CI says.

Will this change require a line in the release notes?
Seems small enough to me to be below the threshold of worth mentioning, but up to y'all...

@JeffFessler JeffFessler marked this pull request as draft December 3, 2020 20:21
@mbauman
Copy link
Sponsor Member

mbauman commented Dec 3, 2020

This is just changing the printing of an error message so it can be improved without warning :)

But I see I directed you to the wrong place. We don't want to add a branch here — rather, we want to change show_index(io, ::LogicalIndex) here:

show_index(io::IO, x::LogicalIndex) = show_index(io, x.mask)

@JeffFessler
Copy link
Contributor Author

Thanks for the feedback. I've updated it to modify show_index now.
Again, not tested so hopefully CI works...

@mbauman
Copy link
Sponsor Member

mbauman commented Dec 4, 2020

To test it locally, you can just do:

julia> @eval Base show_index(io::IO, x::LogicalIndex) = summary(io, x.mask)
show_index (generic function with 5 methods)

julia> rand(4)[rand(Bool, 5)]
ERROR: BoundsError: attempt to access 4-element Vector{Float64} at index [5-element Vector{Bool}]
Stacktrace:
    ...

julia> rand(1, 4)[:, rand(Bool, 5)]
ERROR: BoundsError: attempt to access 1×4 Matrix{Float64} at index [1:1, 5-element Vector{Bool}]
Stacktrace:
    ...

julia> rand(1, 4)[rand(Bool, 1, 5)]
ERROR: BoundsError: attempt to access 1×4 Matrix{Float64} at index [1×5 Matrix{Bool}]
Stacktrace:
    ...

@mbauman mbauman added the domain:error messages Better, more actionable error messages label Dec 4, 2020
@JeffFessler
Copy link
Contributor Author

JeffFessler commented Dec 4, 2020

Oh, I understand that level of testing of the tiny function change I made, but I also added a test to the test suite and I don't know how to locally check the test suite for a fork of julia that I can't compile. For a package I just run ] test MyPackage of course, but I don't know how to test all (or part) of julia Base in a local fork. Probably I need to RTFM :) Sure enough an error in the test was causing the CI to fail, so I've revised the test based on the CI output and try again!

@JeffFessler JeffFessler marked this pull request as ready for review December 5, 2020 18:34
@JeffFessler
Copy link
Contributor Author

@mbauman, 5 commits later it finally passes the tests :)

Copy link
Member

@dkarrasch dkarrasch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are passing. So if you're satisfied with the result, @JeffFessler, I think we can merge.

@mbauman mbauman merged commit a1106b8 into JuliaLang:master Dec 9, 2020
@JeffFessler JeffFessler deleted the errorshowbool branch December 10, 2020 17:14
ElOceanografo pushed a commit to ElOceanografo/julia that referenced this pull request May 4, 2021
* error message for indexing with BitArray

* modify show_index instead

* use BitMatrix in error message

* update error msg

* BitVector !?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:error messages Better, more actionable error messages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

throw BoundsError could be more descriptive for Bool array indexing
3 participants