Skip to content

add generic fallback for haskey#42679

Merged
vtjnash merged 1 commit intomasterfrom
sds/haskey_fallback
Oct 18, 2021
Merged

add generic fallback for haskey#42679
vtjnash merged 1 commit intomasterfrom
sds/haskey_fallback

Conversation

@simeonschaub
Copy link
Copy Markdown
Member

I know this was discussed a while ago, but there was never a PR. I think this is reasonable enough to add.

@simeonschaub simeonschaub added the needs news A NEWS entry is required for this change label Oct 18, 2021
@vtjnash vtjnash merged commit ecc0398 into master Oct 18, 2021
@vtjnash vtjnash deleted the sds/haskey_fallback branch October 18, 2021 16:04
@vtjnash vtjnash removed the needs news A NEWS entry is required for this change label Oct 18, 2021
@bkamins
Copy link
Copy Markdown
Member

bkamins commented Oct 19, 2021

As usual such change turns out to break DataFrames.jl tests which assumed this method is not defined 😄. I will fix it in the package.

@bkamins
Copy link
Copy Markdown
Member

bkamins commented Oct 19, 2021

For a reference - we defined in using haskey. Not sure if such things also happen in other packages.

@bkamins
Copy link
Copy Markdown
Member

bkamins commented Oct 19, 2021

Also is this intended:

julia> haskey((1,2,3), 1)
true

julia> haskey((1,2,3), 1.0)
true

julia> haskey((a=1,b=2,c=3), 1)
true

julia> haskey((a=1,b=2,c=3), 1.0)
false

?

@bkamins
Copy link
Copy Markdown
Member

bkamins commented Oct 19, 2021

and:

julia> haskey([1,2,3], 1.0)
true

julia> [1,2,3][1.0]
ERROR: ArgumentError: invalid index: 1.0 of type Float64

@nalimilan
Copy link
Copy Markdown
Member

Is this change really a good idea? What's the rationale? I'm afraid it's going to create some confusion as @bkamins shows.

@vtjnash
Copy link
Copy Markdown
Member

vtjnash commented Oct 19, 2021

That is a bit of a tricky case, when some types (e.g. arrays) define a different value-equivalence class than the usual convert definitions

@bkamins
Copy link
Copy Markdown
Member

bkamins commented Oct 19, 2021

when some types

I agree, however, my concern was that these "some types" are fundamental types that are most commonly used in practice.

The alternative would be to make sure that we define proper haskey methods for all types defined in Julia Base and make sure they work consistently.

@aplavin
Copy link
Copy Markdown
Contributor

aplavin commented Dec 12, 2021

In addition to @bkamins examples, is this also expected?

julia> haskey([1, 2, 3], CartesianIndex(2))
false

julia> [1, 2, 3][CartesianIndex(2)]
2

simeonschaub added a commit that referenced this pull request Jan 20, 2022
simeonschaub added a commit that referenced this pull request Jan 20, 2022
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Feb 22, 2022
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Feb 22, 2022
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Mar 8, 2022
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Mar 8, 2022
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

Successfully merging this pull request may close these issues.

5 participants