# How to coerce scitype union to continuous?

**URL:** <https://discourse.julialang.org/t/how-to-coerce-scitype-union-to-continuous/90379>\
**Category:** Machine Learning\
**Tags:** mlj\
**Created:** [November 17, 2022, 3:11am UTC](https://discourse.julialang.org/t/how-to-coerce-scitype-union-to-continuous/90379 "2022-11-17T03:11:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucasmsoares96](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lucasmsoares96/32/38743_2.png) [@lucasmsoares96](https://discourse.julialang.org/u/lucasmsoares96)\
**Post date:** [November 17, 2022, 3:11am UTC](https://discourse.julialang.org/t/how-to-coerce-scitype-union-to-continuous/90379/1 "2022-11-17T03:11:47Z")

</div>

All columns in my DataFrame have the sci type Union{Continuous, Count} and I’m having trouble coercing them to Continuous. I tried the following two ways

```julia
coerce(X, Count=>Continuous) 
X |> eachcol .|> a -> coerce(a, Continuous)

```

the first one doesn’t work and the second returns an error.

```julia
`float` not defined on abstractly-typed arrays; please convert to a more specific type

```

What is the correct way to do this?

---

<div class="post-metadata">

**Author:** ![ablaom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ablaom/32/4889_2.png) [@ablaom](https://discourse.julialang.org/u/ablaom)\
**Post date:** [November 17, 2022, 8:51pm UTC](https://discourse.julialang.org/t/how-to-coerce-scitype-union-to-continuous/90379/2 "2022-11-17T20:51:38Z")

</div>

Interesting case. I don’t think ScientificTypes currently handles this directly. It’s a bit weird as it looks like you have mixed eltype where you would ordinarily expect promotion to have occurred. You’ll need to force promotion manually first. Here’s the idea:

```julia
julia> v = Union{Int,Float64}[1, 2.3, 4, 4.5]
4-element Vector{Union{Float64, Int64}}:
 1
 2.3
 4
 4.5

julia> scitype(v)
AbstractVector{Union{Continuous, Count}} (alias for AbstractArray{Union{Continuous, Count}, 1})

julia> coerce([v...], Continuous)
4-element Vector{Float64}:
 1.0
 2.3
 4.0
 4.5

```

So maybe you do

```julia
X |> eachcol .|> a -> coerce([a...], Continuous)

```
