# Error message prints entire dataframe

**URL:** <https://discourse.julialang.org/t/error-message-prints-entire-dataframe/70883>\
**Category:** General Usage\
**Tags:** stacktrace, error-message\
**Created:** [November 3, 2021, 3:09pm UTC](https://discourse.julialang.org/t/error-message-prints-entire-dataframe/70883 "2021-11-03T15:09:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![k10](https://avatars.discourse-cdn.com/v4/letter/k/e5b9ba/32.png) [@k10](https://discourse.julialang.org/u/k10)\
**Post date:** [November 3, 2021, 3:09pm UTC](https://discourse.julialang.org/t/error-message-prints-entire-dataframe/70883/1 "2021-11-03T15:09:22Z")

</div>

I encounter an error when i improperly attempt to use the `length()` function on a dataframe.  
The error message ends up printing the entire dataframe like so:

`Error: MethodError(length, (5189×16 DataFrame`  
and then it prints over 5k rows of the dataframe.

How do i avoid printing the entire dataframe when the error is caught?

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [November 3, 2021, 3:11pm UTC](https://discourse.julialang.org/t/error-message-prints-entire-dataframe/70883/2 "2021-11-03T15:11:31Z")

</div>

I can’t replicate

```julia
julia> using DataFrames

julia> df = DataFrame(rand(10_000, 10), :auto);

julia> length(df)
ERROR: MethodError: no method matching length(::DataFrame)
Closest candidates are:
  length(::Union{Base.KeySet, Base.ValueIterator}) at abstractdict.jl:58
  length(::Union{LinearAlgebra.Adjoint{T, S}, LinearAlgebra.Transpose{T, S}} where {T, S}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/adjtrans.jl:195
  length(::Union{DataStructures.OrderedRobinDict, DataStructures.RobinDict}) at /home/peterwd/.julia/packages/DataStructures/nBjdy/src/ordered_robin_dict.jl:86
  ...
Stacktrace:
 [1] top-level scope
   @ REPL[3]:1

```

Could you show exactly your `length` command?

EDIT: I can replicate

```julia
julia> df = DataFrame(x = [1, 2]);

julia> try 
           length(df)
       catch e
           println(e)
       end
MethodError(length, (2×1 DataFrame
 Row │ x     
     │ Int64 
─────┼───────
   1 │ 1
   2 │ 2,), 0x00000000000073ca)

```

Not sure the best way to fix it.

---

<div class="post-metadata">

**Author:** ![k10](https://avatars.discourse-cdn.com/v4/letter/k/e5b9ba/32.png) [@k10](https://discourse.julialang.org/u/k10)\
**Post date:** [November 3, 2021, 3:14pm UTC](https://discourse.julialang.org/t/error-message-prints-entire-dataframe/70883/3 "2021-11-03T15:14:11Z")

</div>

right, so as you can see when you print the error it ends up printing the entire dataframe argument.  
i don’t want that since i’m dealing with very large dataframes (millions of rows potentially)

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [November 3, 2021, 3:17pm UTC](https://discourse.julialang.org/t/error-message-prints-entire-dataframe/70883/4 "2021-11-03T15:17:14Z")

</div>

I made an issue [here](https://github.com/JuliaData/DataFrames.jl/issues/2925) in the DataFrames.jl repo.

---

<div class="post-metadata">

**Author:** ![k10](https://avatars.discourse-cdn.com/v4/letter/k/e5b9ba/32.png) [@k10](https://discourse.julialang.org/u/k10)\
**Post date:** [November 3, 2021, 3:24pm UTC](https://discourse.julialang.org/t/error-message-prints-entire-dataframe/70883/5 "2021-11-03T15:24:23Z")

</div>

thanks for opening the issue.  
in searching for possible solutions, i encountered the [ClearStacktrace.jl](https://github.com/jkrumbiegel/ClearStacktrace.jl/blob/master/src/ClearStacktrace.jl) package. i don’t see how what they do there could help me. also the package is probably outdated since they overload `Base.show_stacktrace` which doesn’t seem to exist anymore.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [November 3, 2021, 5:26pm UTC](https://discourse.julialang.org/t/error-message-prints-entire-dataframe/70883/6 "2021-11-03T17:26:12Z")

</div>

As noted in the Julia issue [here](https://github.com/JuliaLang/julia/issues/42924) you can use the function `showerror` for better printing of errors.
