-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Allow Base.filter
to work with all iterators
#31188
Comments
One issue here is that |
So I guess in that proposal |
That would make sense to me. filter(f, s::SkipMissing) = filter(x->!ismissing(x) && f(x), s.x) then let |
An alternative is that people could just change their filter commands to have This could just be a documentation / tutorial problem. |
I was looking at implementing what I said above verbatim, but I realized that that definition leaves you with a container without any missing values but with an element type that allows missing. That seems suboptimal and is inconsistent with the result of This is difficult to do generically, since ideally you'd want to be able to use |
Supporting |
Implemented in #31235. |
One possible rationale for supporting |
We can't support |
As I noted it could make sense to also support |
Ah right, sorry. It might make sense to have that as a separate issue, since it's very specific (and a difficult situation to find yourself in, since presumably a broadcast will materialize before |
Broadcasted would materialize an array while |
Yes that's in the context of #31088. |
I just ran into this trying to filter a filter(x->x[2] > 0.5, zip(rand(10), rand(10))) Is the main objection to having map(sum, zip(rand(10), rand(10))) This returns a |
Sure, but that's not the same operation.
The problem is defining what an "iterator" is. For example, one can iterate a tuple, but I'd be surprised if e.g. |
But why would it return an array? Just like |
|
This issue is motivated by this discussion on discourse.
My example of when this is a problem is when you are working with a subset of data that, by chance, does not contain missing values. When you work with the full data, you now have missing values and have to use
skipmissing
at various places in your code. Now all yourfilter
commands are broken.A heavy and breaking change would be to make
Base.filter
work on any iterator, and not just arrays. Other alternatives include pointing more people towardsIterators.filter
for general use, or special-casingskipmissing
so acollect
call is included somewhere.The text was updated successfully, but these errors were encountered: