Skip to content

Commit 2ea054d

Browse files
committed
missing: restrict length(::SkipMissing) to only AbstractArray
`length(::SkipMissing)`, as defined, can actually change the length of some objects (like stateful iterators [1]). Thus, restrict the method to work only on `AbstractArray`. [1] `length(::SkipMissing)` changing the length of a `Stateful` iterator. ``` julia> itr = Iterators.Stateful([missing, 1, missing]) Base.Iterators.Stateful{Vector{Union{Missing, Int64}}, Union{Nothing, Tuple{Union{Missing, Int64}, Int64}}}(Union{Missing, Int64}[missing, 1, missing], (missing, 2), 0) julia> count(!ismissing, skipmissing(itr).x) # proposed definition of length 1 julia> count(!ismissing, skipmissing(itr).x) 0 ```
1 parent f2cc861 commit 2ea054d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

base/missing.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ IteratorSize(::Type{<:SkipMissing}) = SizeUnknown()
246246
IteratorEltype(::Type{SkipMissing{T}}) where {T} = IteratorEltype(T)
247247
eltype(::Type{SkipMissing{T}}) where {T} = nonmissingtype(eltype(T))
248248

249-
length(s::SkipMissing) = count(!ismissing, s.x)
249+
length(s::SkipMissing{T}) where T <: AbstractArray = count(!ismissing, s.x)
250250

251251
function iterate(itr::SkipMissing, state...)
252252
y = iterate(itr.x, state...)

0 commit comments

Comments
 (0)