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

filter() function edge case, possible bug. #16704

Closed
ericproffitt opened this issue Jun 1, 2016 · 2 comments
Closed

filter() function edge case, possible bug. #16704

ericproffitt opened this issue Jun 1, 2016 · 2 comments

Comments

@ericproffitt
Copy link

ericproffitt commented Jun 1, 2016

Consider the code:

filter(n -> true, collect(1:0))

this returns a 0-element array. However if I don't collect the iterator into an array:

filter(n -> true, 1:0)

I get the error

Error: TypeError: typeassert: expected AbstractArray{Bool, N}, got Array{Int64, 1} in filter at array.jl:923

It seems like this should also return a 0-element array, since if the iterator is non empty, e.g.

filter(n -> true, 1:2)

I get the two element array [1,2].

@ararslan
Copy link
Member

ararslan commented Jun 1, 2016

I can reproduce this on 0.4.5 but on 0.5 the error is slightly different: it says Array{Union{},1} instead of Array{Int64,1}.

@berndbohmeier
Copy link

berndbohmeier commented Jun 3, 2016

In array.jl the function filter is implemented using map
filter(f, As::AbstractArray) = As[map(f, As)::AbstractArray{Bool}]

but map does not change the elementtype of the AbstractArray if the AbstractArray is empty.

map(n-> true, 1:2) results in Array{Bool,1}
but
map(n-> true, 1:0) results in Array{Int64,1} , which causes the problem in filter

Is this the expected behaviour of map? Edit: seems to be related to #210, map infers the type from the first element, so it can not get the right type.

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

No branches or pull requests

3 participants