# Another UndefRefError: access to undefined reference

**URL:** <https://discourse.julialang.org/t/another-undefreferror-access-to-undefined-reference/126039>\
**Category:** Data\
**Created:** [February 18, 2025, 5:50pm UTC](https://discourse.julialang.org/t/another-undefreferror-access-to-undefined-reference/126039 "2025-02-18T17:50:17Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![steveo314](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steveo314/32/205248_2.png) [@steveo314](https://discourse.julialang.org/u/steveo314)\
**Post date:** [February 18, 2025, 5:50pm UTC](https://discourse.julialang.org/t/another-undefreferror-access-to-undefined-reference/126039/1 "2025-02-18T17:50:17Z")

</div>

Is there any way to check a Dataframe to see why this error would be returned when running a function on a DF? The error message is too vague. I got this error when running:

```julia
unique!(df,[col1,col2,col3])

```

I’ve only have only received this error on 1 dataset and I clean out missing values beforehand and don’t use undef.

**StackTrace**

```julia
ERROR: UndefRefError: access to undefined reference

Stacktrace:

[1] getindex

   @ .\essentials.jl:917 [inlined]

[2] _broadcast_getindex

   @ .\broadcast.jl:644 [inlined]

[3] _getindex

   @ .\broadcast.jl:674 [inlined]

[4] _broadcast_getindex

   @ .\broadcast.jl:650 [inlined]

[5] getindex

   @ .\broadcast.jl:610 [inlined]

[6] copyto_widen!(res::Vector{…}, bc::Base.Broadcast.Broadcasted{…}, pos::Int64, col::Int64)

   @ DataFrames C:\Users\programmer8\.julia\packages\DataFrames\kcA9R\src\other\broadcasting.jl:27

[7] copy(bc::Base.Broadcast.Broadcasted{DataFrames.DataFrameStyle, Tuple{…}, typeof(coalesce), Tuple{…}})

   @ DataFrames C:\Users\programmer8\.julia\packages\DataFrames\kcA9R\src\other\broadcasting.jl:77

[8] materialize(bc::Base.Broadcast.Broadcasted{DataFrames.DataFrameStyle, Nothing, typeof(coalesce), Tuple{…}})

   @ Base.Broadcast .\broadcast.jl:872

[9] top-level scope

   @ c:\data\process.jl:111

Some type information was truncated. Use `show(err)` to see complete types.

```

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [February 18, 2025, 6:02pm UTC](https://discourse.julialang.org/t/another-undefreferror-access-to-undefined-reference/126039/2 "2025-02-18T18:02:36Z")

</div>

Nobody will be able to say anything without a dataset to reproduce this with, or at least a stacktrace 🙂

---

<div class="post-metadata">

**Author:** ![steveo314](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steveo314/32/205248_2.png) [@steveo314](https://discourse.julialang.org/u/steveo314)\
**Post date:** [February 18, 2025, 6:06pm UTC](https://discourse.julialang.org/t/another-undefreferror-access-to-undefined-reference/126039/3 "2025-02-18T18:06:57Z")

</div>

I’ll recreate the stack trace. I cannot share the dataset and am unsure on how to create a sample dataset that would reproduce the issue.

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [February 18, 2025, 6:16pm UTC](https://discourse.julialang.org/t/another-undefreferror-access-to-undefined-reference/126039/4 "2025-02-18T18:16:03Z")

</div>

I’d hazard a guess that there is an unassigned array element somewhere; that’s not the same as being assigned to a `missing` value. Check:

```julia
((col, name) -> (name, isbitstype(eltype(col)), all(isassigned.(Ref(col), eachindex(col)))) ).(eachcol(df), names(df))

```

If I guessed right, it’ll show for each column whether its elements _can_ have a reference and if so, whether they are all assigned. If you see `0, 0` then that’s a column that can throw the error. If that’s the case, you’ll have to reevaluate how you’re instantiating the `DataFrame`, and you’ll also have to consider the columns that can’t have references because those elements just silently hold garbage values if not assigned.

---

<div class="post-metadata">

**Author:** ![steveo314](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steveo314/32/205248_2.png) [@steveo314](https://discourse.julialang.org/u/steveo314)\
**Post date:** [February 18, 2025, 6:42pm UTC](https://discourse.julialang.org/t/another-undefreferror-access-to-undefined-reference/126039/5 "2025-02-18T18:42:19Z")

</div>

```julia
ERROR: MethodError: no method matching keys(::DataFrame)

```

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [February 18, 2025, 6:48pm UTC](https://discourse.julialang.org/t/another-undefreferror-access-to-undefined-reference/126039/6 "2025-02-18T18:48:52Z")

</div>

You’ll need to explain the context, paste exact code, and paste the full stack trace. I could imagine it happening with `eachindex(::DataFrame)` but that’s ~~not happening.~~ evidently happening but shouldn’t.

---

<div class="post-metadata">

**Author:** ![steveo314](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steveo314/32/205248_2.png) [@steveo314](https://discourse.julialang.org/u/steveo314)\
**Post date:** [February 18, 2025, 6:50pm UTC](https://discourse.julialang.org/t/another-undefreferror-access-to-undefined-reference/126039/7 "2025-02-18T18:50:06Z")

</div>

That’s from running the line of your code with the dataframe name modified to fit my needs.

```julia
Stacktrace:
 [1] eachindex(itrs::DataFrame)
   @ Base .\abstractarray.jl:318
 [2] (::var"#21#22")(col::Vector{String}, name::String)
   @ Main c:\data\process.jl:111
 [3] _broadcast_getindex_evalf
   @ .\broadcast.jl:678 [inlined]
 [4] _broadcast_getindex
   @ .\broadcast.jl:651 [inlined]
 [5] getindex
   @ .\broadcast.jl:610 [inlined]
 [6] copy
   @ .\broadcast.jl:911 [inlined]
 [7] materialize(bc::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{…}, Nothing, var"#21#22", Tuple{…}})
   @ Base.Broadcast .\broadcast.jl:872
 [8] top-level scope
   @ c:\data\process.jl:111
Some type information was truncated. Use `show(err)` to see complete types.

```

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [February 18, 2025, 6:51pm UTC](https://discourse.julialang.org/t/another-undefreferror-access-to-undefined-reference/126039/8 "2025-02-18T18:51:51Z")

</div>

> [@steveo314](#):
>
> the dataframe name modified to fit my needs.

Yeah that could be a problem, hence the recommendations to paste the code and stacktrace. If you can’t reproduce the `DataFrame` object directly, could you at least show `typeof(df), eltype.(eachcol(df))` as well?

---

<div class="post-metadata">

**Author:** ![steveo314](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steveo314/32/205248_2.png) [@steveo314](https://discourse.julialang.org/u/steveo314)\
**Post date:** [February 18, 2025, 6:58pm UTC](https://discourse.julialang.org/t/another-undefreferror-access-to-undefined-reference/126039/9 "2025-02-18T18:58:09Z")

</div>

`show(eltype.(eachcol(allNcoa)))` returns a vector of the 74 cols as `String` types

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [February 18, 2025, 6:59pm UTC](https://discourse.julialang.org/t/another-undefreferror-access-to-undefined-reference/126039/10 "2025-02-18T18:59:14Z")

</div>

Alright, any one of those could have an undef element. And the line that caused the `eachindex(itrs::DataFrame)` error?

---

<div class="post-metadata">

**Author:** ![steveo314](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steveo314/32/205248_2.png) [@steveo314](https://discourse.julialang.org/u/steveo314)\
**Post date:** [February 18, 2025, 7:13pm UTC](https://discourse.julialang.org/t/another-undefreferror-access-to-undefined-reference/126039/11 "2025-02-18T19:13:35Z")

</div>

Trying to find something that would show the `undef`.  
Both of these also give the `undef` error:  
`VSCodeServer.vscodedisplay(df)`

`println(ismissing.(df))`

---

<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:** [February 18, 2025, 7:34pm UTC](https://discourse.julialang.org/t/another-undefreferror-access-to-undefined-reference/126039/12 "2025-02-18T19:34:12Z")

</div>

> [@steveo314](#):
>
> `println(ismissing.(df))`

this is not how you do it. You want to use `isassigned(col, idx)` to check if a given index in a column is assigned or not, before trying to access it (which is what `ismissing.(col)` would do)

---

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [April 18, 2025, 7:19am UTC](https://discourse.julialang.org/t/another-undefreferror-access-to-undefined-reference/126039/14 "2025-04-18T07:19:15Z")

</div>

> [@Benny](#):
>
> I’d hazard a guess that there is an unassigned array element somewhere

I defined a string Matrix with some undefined values ​​and then tried to build a DataFrame, but the constructor fails for undefined reference  
I wonder if and how it is possible to have an undefined value inside a table in DataFrames

---

<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:** [April 18, 2025, 7:34am UTC](https://discourse.julialang.org/t/another-undefreferror-access-to-undefined-reference/126039/15 "2025-04-18T07:34:02Z")

</div>

> [@rocco\_sprmnt21](#):
>
> I wonder if and how it is possible to have an undefined value inside a table in DataFrames

Not really. In general it’s not a good idea to keep undefined entries in Julia arrays. Better use `missing` or `nothing` for entries where there’s no value.

---

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [April 18, 2025, 11:44am UTC](https://discourse.julialang.org/t/another-undefreferror-access-to-undefined-reference/126039/16 "2025-04-18T11:44:48Z")

</div>

Of course. But my intention was to create a similar situation (from what I understand, but I’m not sure) to the one described by the OP

---

<div class="post-metadata">

**Author:** ![steveo314](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steveo314/32/205248_2.png) [@steveo314](https://discourse.julialang.org/u/steveo314)\
**Post date:** [April 18, 2025, 1:15pm UTC](https://discourse.julialang.org/t/another-undefreferror-access-to-undefined-reference/126039/17 "2025-04-18T13:15:23Z")

</div>

I need to revisit that dataset from when I originally raised the question. I got this same error on a dataset yesterday. I had to write a quick function to drill down using a try-catch. Yesterday, the error was from having double quotes inside of a double quoted csv field. The error comes when trying to `coalesce()` after the data was read in with CSV.jl

`"John "Jonathan" Smith","","",""`

```julia
	function find_undef(df::DataFrame)
		undef_indices = []
		for col in 1:ncol(df)
			for row in 1:nrow(df)
				try
					if ismissing(df[row, col])
						push!(undef_indices, (row, col))
					end
				catch e
					msg = string("Error at"*string(row)*","*string(col))
					println(msg)
				end
			end
		end
		return undef_indices
	end
	undef_postitions = find_undef(nonm)
	println(undef_positions

```

---

<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:** [April 18, 2025, 1:53pm UTC](https://discourse.julialang.org/t/another-undefreferror-access-to-undefined-reference/126039/18 "2025-04-18T13:53:03Z")

</div>

This may indicate a bug in the CSV reader. Are you using CSV.jl? A file to reproduce the problem would be very useful.

---

<div class="post-metadata">

**Author:** ![steveo314](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steveo314/32/205248_2.png) [@steveo314](https://discourse.julialang.org/u/steveo314)\
**Post date:** [April 18, 2025, 2:43pm UTC](https://discourse.julialang.org/t/another-undefreferror-access-to-undefined-reference/126039/20 "2025-04-18T14:43:13Z")

</div>

If you use the data below inside a csv file and then try to read it in, it gives the error `Cannot 'convert' an object of type Missing to an object of type String`. Removing the `types=String`, truncates the cell and only places `Tom` in row 1 col 1.

```julia
df = DataFrame(CSV.File("/home/user/sample.csv",types=String))

```

```julia
"name","id","keycode"
"Tom "Thomas" Smith",1,"U9T"
"Sally Jones",2,"Y9E"
"Lori Johns",3,"U7T"
"Paul Gray",4,"E4R"

```

---

<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:** [April 18, 2025, 3:20pm UTC](https://discourse.julialang.org/t/another-undefreferror-access-to-undefined-reference/126039/21 "2025-04-18T15:20:02Z")

</div>

Interesting. This is definitely worth reporting against CSV.jl, even though it doesn’t seem to produce an undef cell.

(Note that I needed to add a final " after E4R to reproduce this behavior, I guess that’s just a typo.)

---

<div class="post-metadata">

**Author:** ![steveo314](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steveo314/32/205248_2.png) [@steveo314](https://discourse.julialang.org/u/steveo314)\
**Post date:** [April 18, 2025, 6:14pm UTC](https://discourse.julialang.org/t/another-undefreferror-access-to-undefined-reference/126039/22 "2025-04-18T18:14:30Z")

</div>

I’ll have to issue a bug report for it. And yes the missing dq was a typo. Thank you for catching it.

[Next page](https://discourse.julialang.org/t/another-undefreferror-access-to-undefined-reference/126039.md?page=2)
