# How to call the original Base.show function extended in DataFrames.jl while overriding it?

**URL:** https://discourse.julialang.org/t/how-to-call-the-original-base-show-function-extended-in-dataframes-jl-while-overriding-it/104437
**Category:** New to Julia
**Tags:** question, dispatch, function, methods, world\_age
**Created:** [September 30, 2023, 5:20pm UTC](https://discourse.julialang.org/t/how-to-call-the-original-base-show-function-extended-in-dataframes-jl-while-overriding-it/104437 "2023-09-30T17:20:22Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![raythurnevoid](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raythurnevoid/32/52651_2.png) [@raythurnevoid](https://discourse.julialang.org/u/raythurnevoid)
#### Post date: [September 30, 2023, 5:20pm UTC](https://discourse.julialang.org/t/how-to-call-the-original-base-show-function-extended-in-dataframes-jl-while-overriding-it/104437/1 "2023-09-30T17:20:22Z")

</div>

I’m using the `DataFrames.jl` package and I want to change the default behavior of `show()`, I want to print all the rows and columns without passing additional arguments because I want it to work seamlessly while calling `display()`

Therefore my question is similar to [this](https://discourse.julialang.org/t/extend-methods-from-another-module-while-calling-the-original-method-within-the-extended-method/62791) but slightly different and I’m not sure what path to take.

As far as I know I have 3 options:

- extend display()
- ~~apply [this solution](https://discourse.julialang.org/t/extend-methods-from-another-module-while-calling-the-original-method-within-the-extended-method/62791/2)~~ → _Not applicable since DataFrams.jl is extending `Base.show` thus i can’t just invoke the DataFrame’s version of `show`_
- use irtools

Do you have any suggestion?

---

<div class="post-metadata">

### Author: ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)
#### Post date: [September 30, 2023, 7:11pm UTC](https://discourse.julialang.org/t/how-to-call-the-original-base-show-function-extended-in-dataframes-jl-while-overriding-it/104437/2 "2023-09-30T19:11:08Z")

</div>

You just need to overwrite `show` if you are just doing this for yourself.

```julia
julia> struct A end

julia> A()
A()

julia> Base.show(io::IO, ::MIME"text/plain", ::A) = println("A is an emtpy struct")

julia> A()
A is an emtpy struct

julia> Base.show(io::IO, ::MIME"text/plain", ::A) = println("A() is an emtpy struct")

julia> A()
A() is an emtpy struct

help?> show

```

If you are trying to do for others, then you should create a struct that wraps a `DataFrame` and then modify the show method for that struct as above.

See [Types · The Julia Language](https://docs.julialang.org/en/v1/manual/types/#man-custom-pretty-printing)

---

<div class="post-metadata">

### Author: ![raythurnevoid](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raythurnevoid/32/52651_2.png) [@raythurnevoid](https://discourse.julialang.org/u/raythurnevoid)
#### Post date: [October 1, 2023, 12:06am UTC](https://discourse.julialang.org/t/how-to-call-the-original-base-show-function-extended-in-dataframes-jl-while-overriding-it/104437/4 "2023-10-01T00:06:48Z")

</div>

no that’s not enough because the DataFrames.jl show function is way complicated and I clearly don’t want to rewrite the whole thing I just want to change the parameters it uses by default.

---

<div class="post-metadata">

### Author: ![raythurnevoid](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raythurnevoid/32/52651_2.png) [@raythurnevoid](https://discourse.julialang.org/u/raythurnevoid)
#### Post date: [October 1, 2023, 3:52am UTC](https://discourse.julialang.org/t/how-to-call-the-original-base-show-function-extended-in-dataframes-jl-while-overriding-it/104437/5 "2023-10-01T03:52:55Z")

</div>

I found out how to accomplish it with `Base.invoke_in_world`:

```julia
module Y
function Base.show(::Val{:test})
    println("TEST Y")
end
end

module X
w = Base.get_world_counter()
function Base.show(::Val{:test})
    println("TEST X")
    Base.invoke_in_world(w, Base.show, Val(:test))
end
end

show(Val(:test))
# Result:
# TEST X
# TEST Y

```

Here’s how I’ve overwritten the extended `Base.show` method from `DataFrames.jl`:

```julia
df_show_formatters = (v, i::Int, j::Int) -> (typeof(v) <: DateTime ? Dates.format(v, "dd-mm-yyyy HH:MM") : v)
w = Base.get_world_counter()

function Base.show(io::IO, mime::MIME"text/plain", df::AbstractDataFrame; kwargs...)

    write(io, "Additional output here\n\n")

    Base.invoke_in_world(w, Base.show,
        io,
        mime,
        df;
        allcols=true,
        allrows=true,
        formatters=df_show_formatters,
        kwargs...
    )
end

function Base.show(io::IO, mime::MIME"text/html", df::AbstractDataFrame; kwargs...)
    Base.invoke_in_world(w, Base.show,
        io,
        mime,
        df;
        max_num_of_columns=-1,
        max_num_of_rows=-1,
        formatters=df_show_formatters,
        table_style=Dict(
            "white-space" => "nowrap"
        ),
        kwargs...
    )
end

```

This works both in the REPL and Jupyter, I’m using it to pretty format DateTime cells, avoid word wrapping in HTML and show all the df content by default

Here is a comparison before and after the change in jupyter:  
Before  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/3/c/3cb7c1916a8afac898f81eeaabe04a6ee14dd436.png)  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/b/abab12957e1d9962375033e79ebd8a88a42c625d.png)

After  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/9/797501bf4aeacfb3c9ea0656e8b0a7f2c81aae82.png)  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/e/0/e042ef7b2e99ff5d6789cb4794da20be3033c296.png)
