# Type inference of tables /w missing cells

**URL:** <https://discourse.julialang.org/t/type-inference-of-tables-w-missing-cells/20769>\
**Category:** Internals & Design\
**Tags:** inference, type, suggestions, tuple\
**Created:** [February 13, 2019, 10:21pm UTC](https://discourse.julialang.org/t/type-inference-of-tables-w-missing-cells/20769 "2019-02-13T22:21:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cce](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cce/32/460_2.png) [@cce](https://discourse.julialang.org/u/cce)\
**Post date:** [February 13, 2019, 10:21pm UTC](https://discourse.julialang.org/t/type-inference-of-tables-w-missing-cells/20769/1 "2019-02-13T22:21:59Z")

</div>

This is a feature suggestion. I’m modeling database tables as a `Vector` of `NamedTuple`. I’m wondering if Julia could more smartly infer the type of these structures when values are `missing`. For starters, I note that Julia is already great at inferring vectors that have `missing` values; it finds elements of type `Union{Missing, T}`. Further, Julia is very good at inferring types of vectors of tuples and even vectors of named tuples, so long as they don’t have `missing` values.

```julia
julia> typeof([3, missing])
Array{Union{Missing, Int64},1}

julia> typeof([("A", 3), ("B", 4)])
Array{Tuple{String,Int64},1}

julia> typeof([(k="A", v=3), (k="B", v=4)])
Array{NamedTuple{(:k, :v),Tuple{String,Int64}},1}

```

The combination, a vector of tuples /w missing values, falls short.

```julia
julia> typeof([("A", 3), ("B", missing)])
Array{Tuple{String,Any},1}

julia> typeof([(k="A", v=3), (k="B", v=missing)])
Array{NamedTuple{(:k, :v),T} where T<:Tuple,1}

```

What I’d love to see instead…

```julia
# a future version of Julia
julia> typeof([("A", 3), ("B", missing)])
Array{Tuple{String,Union{Missing, Int64}},1}

julia> typeof([(k="A", v=3), (k="B", v=missing)])
Array{NamedTuple{(:k, :v),Tuple{String,Union{Missing, Int64}},1}

```

Is this at all related to [https://github.com/JuliaLang/julia/issues/24614](https://github.com/JuliaLang/julia/issues/24614)  
or [https://github.com/JuliaLang/julia/issues/25925](https://github.com/JuliaLang/julia/issues/25925)?

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [February 15, 2019, 2:49pm UTC](https://discourse.julialang.org/t/type-inference-of-tables-w-missing-cells/20769/2 "2019-02-15T14:49:10Z")

</div>

Cross-ref:  
[https://github.com/JuliaLang/julia/issues/31077](https://github.com/JuliaLang/julia/issues/31077)

For reference, inference isn’t involved at all in the examples posted above. Everything is determined by `promote_type`.

---

<div class="post-metadata">

**Author:** ![thautwarm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thautwarm/32/37760_2.png) [@thautwarm](https://discourse.julialang.org/u/thautwarm)\
**Post date:** [February 16, 2019, 7:50pm UTC](https://discourse.julialang.org/t/type-inference-of-tables-w-missing-cells/20769/3 "2019-02-16T19:50:43Z")

</div>

I have an implementation of deterministic typed tables when the initialization of tables are well typed.

> <https://github.com/thautwarm/MLStyle-Playground/blob/ccb661d4de52c6ddef5d980e245580b79ba3d6b2/MQuery/MQuery.Impl.jl#L28>

However, something like `[("A", 3), ("B", missing)]` shouldn’t be treated as `Array{Tuple{String,Union{Missing, Int64}},1}`, and I think `Array{Tuple{String,Any},1}` is better in general domains. In fact, without manual annotations, there’re so many prospectively expected types for `[("A", 3), ("B", missing)]`.

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [February 17, 2019, 10:23am UTC](https://discourse.julialang.org/t/type-inference-of-tables-w-missing-cells/20769/4 "2019-02-17T10:23:06Z")

</div>

> [@thautwarm](#):
>
> In fact, without manual annotations, there’re so many prospectively expected types for `[("A", 3), ("B", missing)]` .

What do you mean? The only possible types for elements in that array are `Tuple{String,Int}` and `Tuple{String,Missing}`.

---

<div class="post-metadata">

**Author:** ![bramtayl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bramtayl/32/3614_2.png) [@bramtayl](https://discourse.julialang.org/u/bramtayl)\
**Post date:** [February 17, 2019, 2:32pm UTC](https://discourse.julialang.org/t/type-inference-of-tables-w-missing-cells/20769/5 "2019-02-17T14:32:42Z")

</div>

If you use LightQuery, you can keep the underlying data stored column-wise as a named tuple of vectors, but use `rows` to lazily view the data as `rows`.

```julia
(
    k = ["A", "B"],
    v = [3, missing]
) |>
    rows

```
