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

Adding an equivalent of in consistent with isequal #37157

Open
nalimilan opened this issue Aug 22, 2020 · 2 comments
Open

Adding an equivalent of in consistent with isequal #37157

nalimilan opened this issue Aug 22, 2020 · 2 comments
Labels
collections Data structures holding multiple items, e.g. sets design Design of APIs or of the language itself speculative Whether the change will be implemented is speculative

Comments

@nalimilan
Copy link
Member

For CategoricalArrays's recode function, we bumped into the need for an equivalent of in which would always be consistent with isequal (rather than sometimes following == as it does for AbstractArray notably). This is in order to allow things like recode(array, [1, missing, NaN] => 0) (equivalent to replace(array, 1 => 0, missing => 0, NaN => 0)).

Currently, this works by special-casing an AbstractArray LHS to use isequal, but it was requested that this should work with other collections, such as intervals (JuliaData/CategoricalArrays.jl#290). Both Intervals.jl and IntervalSets.jl define in to be consistent with == (like AbstractArray), i.e. missing in 0..1 returns missing, so we cannot just use in. Yet we don't want packages to depend on each other.

It looks like we need a new function/method to complement in that would consistently use isequal (maybe waiting for a deeper change in Julia 2.0). How does adding such a function sound? I imagine that could be in(isequal, a, b), or a completely new function.

This issue was previously touched by discussion at #34744.

@nalimilan nalimilan added speculative Whether the change will be implemented is speculative design Design of APIs or of the language itself collections Data structures holding multiple items, e.g. sets labels Aug 22, 2020
@bkamins
Copy link
Member

bkamins commented Sep 22, 2021

Per the discussion on Slack, using isequal consistently for all in checks would make more sense in the future.

@milankl
Copy link

milankl commented Sep 2, 2024

I find this

julia> NaN in [1, 2, NaN, 3]
false

counterintuitive and @oscardssmith questions whether really isequal should be used instead of == for in?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
collections Data structures holding multiple items, e.g. sets design Design of APIs or of the language itself speculative Whether the change will be implemented is speculative
Projects
None yet
Development

No branches or pull requests

3 participants