# Segfault on DataFrames \`getindex\`

**URL:** <https://discourse.julialang.org/t/segfault-on-dataframes-getindex/20612>\
**Category:** General Usage\
**Created:** [February 9, 2019, 6:59pm UTC](https://discourse.julialang.org/t/segfault-on-dataframes-getindex/20612 "2019-02-09T18:59:46Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Post date:** [February 11, 2019, 10:27pm UTC](https://discourse.julialang.org/t/segfault-on-dataframes-getindex/20612/21 "2019-02-11T22:27:32Z")

</div>

Definately an `AbstractDataFrame`,  
I believe it is a `SubDataFrame` created by selecting 2 columns (`:n` and one other call it `:d`) from a larger dataframe. (There is a chance the the it was sliced from was itself a subdataframe, I’ld have to go looking.)

It has had a marginally unplesent life.  
Here is a bit more of its life.

```julia
    disallowmissing!(dropmissing!(mydataframe))

    # Cause `disallowmissing!` doesn't seem to change the column type away from Any on 0.6?
    mydataframe[:d] = Vector{Float64}(mydataframe[:d])

    stds = [std(df[:d]) for df in groupby(mydataframe, :n)]
    for (i, df) in enumerate(groupby(mydataframe, :n))
        for foo in (1,2)
                x = df[1, :n]
                # other operations on `x` and `foo` that do not touch any dataframes
                @show 1 # Add this to stop segufault.
         end
   end

```

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [February 11, 2019, 11:03pm UTC](https://discourse.julialang.org/t/segfault-on-dataframes-getindex/20612/22 "2019-02-11T23:03:56Z")

</div>

> [@oxinabox](#):
>
> ```julia
> disallowmissing!(dropmissing!(mydataframe))
> 
> # Cause `disallowmissing!` doesn't seem to change the column type away from Any on 0.6?
> mydataframe[:d] = Vector{Float64}(mydataframe[:d])
> 
> ```

At this stage it had to be a `DataFrame` as the first operation is unsupported for `SubDataFrame` and the second would not change `eltype` of column `:d` if `mydataframe` were a `SubDataFrame`.

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [February 11, 2019, 11:37pm UTC](https://discourse.julialang.org/t/segfault-on-dataframes-getindex/20612/23 "2019-02-11T23:37:39Z")

</div>

And actually, given your comment, it would be also interesting to know if these two variants work or fail:

```julia
for (i, df) in enumerate(groupby(DataFrame(mydataframe), :n))
        for foo in (1,2)
                x = df[1, :n]
                # other operations on `x` and `foo` that do not touch any dataframes
                @show 1 # Add this to stop segufault.
         end
end

```

and

```julia
for (i, df) in enumerate(groupby(DataFrame(eachcol(mydataframe, true)...), :n))
        for foo in (1,2)
                x = df[1, :n]
                # other operations on `x` and `foo` that do not touch any dataframes
                @show 1 # Add this to stop segufault.
         end
end

```

---

<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 12, 2019, 9:04am UTC](https://discourse.julialang.org/t/segfault-on-dataframes-getindex/20612/24 "2019-02-12T09:04:08Z")

</div>

To be clear, the question of the origin of the data frame is essential. If it’s really a `SubDataFrame` extracted from a previous `groupby` operation, then it’s likely that the bug has been fixed by [#1709](https://github.com/JuliaData/DataFrames.jl/pull/1709). That would explain why it’s gone in 0.17.1, and then everything would be fine. But as noted by @bkamins that’s not a `SubDataFrame` if you call `disallowmissing!` on it.

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [February 12, 2019, 9:13am UTC](https://discourse.julialang.org/t/segfault-on-dataframes-getindex/20612/25 "2019-02-12T09:13:30Z")

</div>

@nalimilan This is exactly what I am trying to rule out, that is why I suggested to test what happens if we freshly create a `DataFrame` (the two approaches differ that one does `copy` of old index and the other creates it freshly - which also might make a difference).

---

<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:** [March 17, 2020, 6:24pm UTC](https://discourse.julialang.org/t/segfault-on-dataframes-getindex/20612/26 "2020-03-17T18:24:48Z")

</div>

A post was split to a new topic: [Get on GroupedDataFrame](https://discourse.julialang.org/t/get-on-groupeddataframe/36108)

[Previous page](https://discourse.julialang.org/t/segfault-on-dataframes-getindex/20612.md?page=1)
