# Bug with Union type in Query.jl?

**URL:** https://discourse.julialang.org/t/bug-with-union-type-in-query-jl/23865
**Category:** Data
**Created:** [May 5, 2019, 10:13am UTC](https://discourse.julialang.org/t/bug-with-union-type-in-query-jl/23865 "2019-05-05T10:13:16Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![glwc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/glwc/32/8317_2.png) [@glwc](https://discourse.julialang.org/u/glwc)
#### Post date: [May 5, 2019, 10:13am UTC](https://discourse.julialang.org/t/bug-with-union-type-in-query-jl/23865/1 "2019-05-05T10:13:16Z")

</div>

I’d appreciate help to understand the following. The particular code here with a problem is using a `@select` expression to extract the second number embedded in a string in DataFrame column elements which have the type of `Union{String, Missing}`, but I expect the difficulty will probably arise with other variations (eg. I can confirm this fails with `@where` statements of similar form):

```julia
c1=Union{String, Missing}["a4 - 1.0","b5 - 2.0","c6 - 3.0"]

df2 = DataFrame(Frame=c1)

# Gives error (see below)
df3 = @from i in df2 begin
      @select {time=parse(Float64,string(match(r"[^\d]*[\d.]+[^\d]+([\d.]+)",i.Frame)[1])) } # This is an error
      @collect DataFrame
end

# Good if I add extra string() conversion
df4 = @from i in df2 begin
      @select {time=parse(Float64,string(match(r"[^\d]*[\d.]+[^\d]+([\d.]+)",string(i.Frame))[1])) }
      @collect DataFrame
end

```

However the `@select` transformation expression above that gives an error works fine in “regular” Julia use

```julia
println("Extract 2nd digit: $(parse(Float64,string(match(r"[^\d]*[\d.]+[^\d]+([\d.]+)",c1[1])[1] ))))")

```

Is this a bug?

Many thanks,  
GC

PS. The error thrown is:

```julia
LoadError: ArgumentError: unable to construct DataFrame from QueryOperators.EnumerableMap{Union{},QueryOperators.EnumerableIterable{NamedTuple{(:Frame, :Step),Tuple{DataValues.DataValue{String},DataValues.DataValue{String}}},Tables.DataValueRowIterator{NamedTuple{(:Frame, :Step),Tuple{DataValues.DataValue{String},DataValues.DataValue{String}}},Tables.RowIterator{NamedTuple{(:Frame, :Step),Tuple{Array{Union{Missing, String},1},Array{Union{Missing, String},1}}}}}},getfield(Main, Symbol("##269#270"))}
in expression starting at C:\Users\tcd\Dropbox (Personal)\Prof\TCD\Comm\Manuscript-19\Glass mech\Thin film yield\Analysis\queryPlay2.jl:32
#DataFrame#366(::Bool, ::Type, ::QueryOperators.EnumerableMap{Union{},QueryOperators.EnumerableIterable{NamedTuple{(:Frame, :Step),Tuple{DataValues.DataValue{String},DataValues.DataValue{String}}},Tables.DataValueRowIterator{NamedTuple{(:Frame, :Step),Tuple{DataValues.DataValue{String},DataValues.DataValue{String}}},Tables.RowIterator{NamedTuple{(:Frame, :Step),Tuple{Array{Union{Missing, String},1},Array{Union{Missing, String},1}}}}}},getfield(Main, Symbol("##269#270"))}) at tables.jl:35
DataFrame(::QueryOperators.EnumerableMap{Union{},QueryOperators.EnumerableIterable{NamedTuple{(:Frame, :Step),Tuple{DataValues.DataValue{String},DataValues.DataValue{String}}},Tables.DataValueRowIterator{NamedTuple{(:Frame, :Step),Tuple{DataValues.DataValue{String},DataValues.DataValue{String}}},Tables.RowIterator{NamedTuple{(:Frame, :Step),Tuple{Array{Union{Missing, String},1},Array{Union{Missing, String},1}}}}}},getfield(Main, Symbol("##269#270"))}) at tables.jl:20
top-level scope at none:0

```

---

<div class="post-metadata">

### Author: ![hckr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hckr/32/4836_2.png) [@hckr](https://discourse.julialang.org/u/hckr)
#### Post date: [May 5, 2019, 11:04am UTC](https://discourse.julialang.org/t/bug-with-union-type-in-query-jl/23865/2 "2019-05-05T11:04:33Z")

</div>

I think this is about `missing` values are represented with `DataValue` in `Query.jl`. You may unpack `DataValue` to access stored variable via `get(x)` or `x[]`. The following should work.

```julia
df3 = @from i in df2 begin
             @select {time=parse(Float64, match(r"[^\d]*[\d.]+[^\d]+([\d.]+)", i.Frame[])[1]) }
             @collect DataFrame
       end

```

---

<div class="post-metadata">

### Author: ![glwc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/glwc/32/8317_2.png) [@glwc](https://discourse.julialang.org/u/glwc)
#### Post date: [May 5, 2019, 1:10pm UTC](https://discourse.julialang.org/t/bug-with-union-type-in-query-jl/23865/3 "2019-05-05T13:10:05Z")

</div>

Thanks @hckr, that worked and is right in the docs, which I somehow didn’t catch.
