# Length(skipmissing( )) not implemented

**URL:** https://discourse.julialang.org/t/length-skipmissing-not-implemented/65943
**Category:** Performance
**Created:** [August 6, 2021, 1:40pm UTC](https://discourse.julialang.org/t/length-skipmissing-not-implemented/65943 "2021-08-06T13:40:35Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![tomtom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomtom/32/5106_2.png) [@tomtom](https://discourse.julialang.org/u/tomtom)
#### Post date: [August 6, 2021, 1:40pm UTC](https://discourse.julialang.org/t/length-skipmissing-not-implemented/65943/1 "2021-08-06T13:40:35Z")

</div>

```julia
julia> x = [2.0, missing, 3.0];

julia> length(x)
3

julia> length(skipmissing(x))
ERROR: MethodError: no method matching length(::Base.SkipMissing{Vector{Union{Missing, Float64}}})

julia> count(a -> true, skipmissing(x))
2

```

it would be nice if `length` is implemented for `SkipMissing`. Using `count` in this case is less readable and counter intuitive.

---

<div class="post-metadata">

### Author: ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)
#### Post date: [August 6, 2021, 1:42pm UTC](https://discourse.julialang.org/t/length-skipmissing-not-implemented/65943/2 "2021-08-06T13:42:49Z")

</div>

There is an issue for this [here](https://github.com/JuliaLang/julia/issues/37014).

The problem is that `length` will always be `O(n)` for `SkipMissing`. It would be very slow, which is against the design of `skipmissing` in the first place.

---

<div class="post-metadata">

### Author: ![tomtom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomtom/32/5106_2.png) [@tomtom](https://discourse.julialang.org/u/tomtom)
#### Post date: [August 6, 2021, 1:46pm UTC](https://discourse.julialang.org/t/length-skipmissing-not-implemented/65943/3 "2021-08-06T13:46:04Z")

</div>

thanks.

but the situation is quite strange: if O(n) is the best we can possibly get, why hesitate to do so? After all, O(n) should be considered as “very good” for most algorithms…

now, using `count` is still O(n) (and with some overhead in the anonymous function). We just cannot avoid it…

---

<div class="post-metadata">

### Author: ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)
#### Post date: [August 6, 2021, 1:49pm UTC](https://discourse.julialang.org/t/length-skipmissing-not-implemented/65943/4 "2021-08-06T13:49:23Z")

</div>

I don’t think O(n) is very good for something like `length`, which is `O(1)` for vectors. The consequence of supporting, out of the box, `length` is that a lot of people will complain that `length(skipmissing(x))` is slow, and they would be right, when thinking about other `length` calls.

---

<div class="post-metadata">

### Author: ![tomtom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomtom/32/5106_2.png) [@tomtom](https://discourse.julialang.org/u/tomtom)
#### Post date: [August 6, 2021, 1:51pm UTC](https://discourse.julialang.org/t/length-skipmissing-not-implemented/65943/5 "2021-08-06T13:51:12Z")

</div>

… but the point is there is **no way** to achieve O(1) for `length(skipmissing())`, in my understanding at least.

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [August 6, 2021, 1:55pm UTC](https://discourse.julialang.org/t/length-skipmissing-not-implemented/65943/6 "2021-08-06T13:55:21Z")

</div>

you want users to be aware they are doing this, where other wise they may be calling `length()` over and over like they would normally do.

---

<div class="post-metadata">

### Author: ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)
#### Post date: [August 6, 2021, 1:59pm UTC](https://discourse.julialang.org/t/length-skipmissing-not-implemented/65943/7 "2021-08-06T13:59:20Z")

</div>

`skipmissing` is designed to be a very lightweight and fast iterator which skips missing values. It comes with a guarantee “every function in Base which supports `SkipMissing` will be fast”. That unfortunately means it won’t support all common functions.

---

<div class="post-metadata">

### Author: ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)
#### Post date: [August 6, 2021, 4:24pm UTC](https://discourse.julialang.org/t/length-skipmissing-not-implemented/65943/8 "2021-08-06T16:24:48Z")

</div>

Even more readable:

```julia
count(!ismissing, x)

```
