<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Using built-in display method modules in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/using-built-in-display-method-modules/m-p/149622#M53135</link>
    <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/218287"&gt;@holunder42&lt;/a&gt;&amp;nbsp;, I did some digging and here is what I found. Hopefully, it will help you further troubleshoot the issue.&lt;/P&gt;
&lt;P class="p1"&gt;Here’s what’s going on and how to solve it.&lt;/P&gt;
&lt;P class="p1"&gt;Why display behaves differently in a module&lt;/P&gt;
&lt;P class="p1"&gt;On Databricks, display is a notebook-scoped helper injected by the runtime. It lives in the notebook’s IPython namespace, not in your module’s global namespace.&lt;/P&gt;
&lt;P class="p1"&gt;When you write this inside a module:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;# foo.py
def df_show(df):
    display(df)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="p1"&gt;and then do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;from foo import df_show
df_show(df)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="p1"&gt;Python tries to resolve display in this order:&lt;/P&gt;
&lt;OL start="1"&gt;
&lt;LI&gt;
&lt;P class="p1"&gt;Local scope inside df_show&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P class="p1"&gt;The module’s global scope (foo’s globals)&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P class="p1"&gt;Builtins&lt;/P&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P class="p1"&gt;It does not look in the notebook’s globals, where Databricks has put display. So from the module’s point of view, display just doesn’t exist. The “plain &lt;SPAN class="s2"&gt;&lt;STRONG&gt;repr&lt;/STRONG&gt;&lt;/SPAN&gt; output” you’re seeing is effectively the fallback behavior (for example print or df.show() in your wrapper), not the Databricks visual display.&lt;/P&gt;
&lt;P class="p1"&gt;To get notebook-style visuals from code in a module, you need to inject the display function into the module code, or otherwise abstract it.&lt;/P&gt;
&lt;P class="p1"&gt;Recommended pattern: pass display as a dependency&lt;/P&gt;
&lt;P class="p1"&gt;Treat display as a UI dependency that you pass in from the notebook when you have it, and fall back to a simple print/show when you don’t.&lt;/P&gt;
&lt;P class="p1"&gt;foo.py (module):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;# foo.py

def df_show(df, visualizer=None):
    """
    visualizer: a callable like Databricks `display` or IPython.display.display.
    If None, fall back to a simple text representation.
    """
    if visualizer is not None:
        visualizer(df)
    else:
        # Fallback for non-Databricks environments
        try:
            # Nice tabular output in many console contexts
            df.show()
        except AttributeError:
            # Generic fallback
            print(df)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="p1"&gt;On Databricks notebook:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;from foo import df_show

df = spark.createDataFrame([{"x": 1}])

# Pass the notebook's `display` into your module
df_show(df, display)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="p1"&gt;Outside Databricks (plain Python / script):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;from foo import df_show
from pyspark.sql import SparkSession

spark = SparkSession.builder.getOrCreate()
df = spark.createDataFrame([{"x": 1}])

# No Databricks display available → falls back to df.show()
df_show(df)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="p1"&gt;This gives you:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;P class="p1"&gt;Databricks: full rich notebook visualization&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P class="p1"&gt;Non-Databricks: readable textual output via df.show() or print&lt;/P&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p3"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;Optional: central “smart display” wrapper&lt;/P&gt;
&lt;P class="p3"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;If you want to centralize this logic because you call it many times, define a “smart display” once and pass it around:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;# foo.py

def make_smart_display(visualizer=None):
    def _smart(obj):
        if visualizer is not None:
            visualizer(obj)
        else:
            try:
                obj.show()
            except AttributeError:
                print(obj)
    return _smart

def df_show(df, smart_display):
    smart_display(df)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="p1"&gt;Usage on Databricks:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;from foo import make_smart_display, df_show

smart_display = make_smart_display(display)
df_show(df, smart_display)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="p1"&gt;Usage off Databricks:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;from foo import make_smart_display, df_show

smart_display = make_smart_display()  # no visualizer → fallback
df_show(df, smart_display)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="p1"&gt;Design takeaway&lt;/P&gt;
&lt;P class="p1"&gt;The core idea is: keep UI concerns (like Databricks display) at the notebook boundary and inject them into reusable modules, rather than hard-coding display inside your modules. That way your code works cleanly both on Databricks and in any plain Python environment.&lt;/P&gt;
&lt;P class="p1"&gt;Cheers, Lou&lt;/P&gt;</description>
    <pubDate>Mon, 02 Mar 2026 14:16:22 GMT</pubDate>
    <dc:creator>Louis_Frolio</dc:creator>
    <dc:date>2026-03-02T14:16:22Z</dc:date>
    <item>
      <title>Using built-in display method modules</title>
      <link>https://community.databricks.com/t5/data-engineering/using-built-in-display-method-modules/m-p/149608#M53130</link>
      <description>&lt;P&gt;The builtin `display` function is very helpful. but we're moving code from notebooks into python modules.&lt;/P&gt;&lt;P&gt;Here, it seems that `display` is defined differently which results in poor visualization.&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;df &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; spark.&lt;/SPAN&gt;&lt;SPAN&gt;createDataFrame&lt;/SPAN&gt;&lt;SPAN&gt;([{&lt;/SPAN&gt;&lt;SPAN&gt;'x'&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;}])&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;display&lt;/SPAN&gt;&lt;SPAN&gt;(df)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;```&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;--&amp;gt; nice visual&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;But when I move the display-code to a module:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;def&lt;/SPAN&gt; &lt;SPAN&gt;df_show&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;df&lt;/SPAN&gt;&lt;SPAN&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;display&lt;/SPAN&gt;&lt;SPAN&gt;(df)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;And using it by&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;from foo import df_show&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;df_show(df)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;it only shows the __repr__ ouput.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;My target picture:&lt;/DIV&gt;&lt;DIV&gt;- have a wrapper version for all calls of `display` which:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; * refers to builtin-display when running in databricks&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; * refers to a custom print when running in python environment outside of databricks&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks for your support&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 02 Mar 2026 10:20:51 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/using-built-in-display-method-modules/m-p/149608#M53130</guid>
      <dc:creator>holunder42</dc:creator>
      <dc:date>2026-03-02T10:20:51Z</dc:date>
    </item>
    <item>
      <title>Re: Using built-in display method modules</title>
      <link>https://community.databricks.com/t5/data-engineering/using-built-in-display-method-modules/m-p/149620#M53134</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Display is for interactive exploration only and not intended for use in modular python code. You can use AI BI dashboards for visualizations.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2026 13:32:21 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/using-built-in-display-method-modules/m-p/149620#M53134</guid>
      <dc:creator>balajij8</dc:creator>
      <dc:date>2026-03-02T13:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: Using built-in display method modules</title>
      <link>https://community.databricks.com/t5/data-engineering/using-built-in-display-method-modules/m-p/149622#M53135</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/218287"&gt;@holunder42&lt;/a&gt;&amp;nbsp;, I did some digging and here is what I found. Hopefully, it will help you further troubleshoot the issue.&lt;/P&gt;
&lt;P class="p1"&gt;Here’s what’s going on and how to solve it.&lt;/P&gt;
&lt;P class="p1"&gt;Why display behaves differently in a module&lt;/P&gt;
&lt;P class="p1"&gt;On Databricks, display is a notebook-scoped helper injected by the runtime. It lives in the notebook’s IPython namespace, not in your module’s global namespace.&lt;/P&gt;
&lt;P class="p1"&gt;When you write this inside a module:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;# foo.py
def df_show(df):
    display(df)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="p1"&gt;and then do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;from foo import df_show
df_show(df)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="p1"&gt;Python tries to resolve display in this order:&lt;/P&gt;
&lt;OL start="1"&gt;
&lt;LI&gt;
&lt;P class="p1"&gt;Local scope inside df_show&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P class="p1"&gt;The module’s global scope (foo’s globals)&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P class="p1"&gt;Builtins&lt;/P&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P class="p1"&gt;It does not look in the notebook’s globals, where Databricks has put display. So from the module’s point of view, display just doesn’t exist. The “plain &lt;SPAN class="s2"&gt;&lt;STRONG&gt;repr&lt;/STRONG&gt;&lt;/SPAN&gt; output” you’re seeing is effectively the fallback behavior (for example print or df.show() in your wrapper), not the Databricks visual display.&lt;/P&gt;
&lt;P class="p1"&gt;To get notebook-style visuals from code in a module, you need to inject the display function into the module code, or otherwise abstract it.&lt;/P&gt;
&lt;P class="p1"&gt;Recommended pattern: pass display as a dependency&lt;/P&gt;
&lt;P class="p1"&gt;Treat display as a UI dependency that you pass in from the notebook when you have it, and fall back to a simple print/show when you don’t.&lt;/P&gt;
&lt;P class="p1"&gt;foo.py (module):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;# foo.py

def df_show(df, visualizer=None):
    """
    visualizer: a callable like Databricks `display` or IPython.display.display.
    If None, fall back to a simple text representation.
    """
    if visualizer is not None:
        visualizer(df)
    else:
        # Fallback for non-Databricks environments
        try:
            # Nice tabular output in many console contexts
            df.show()
        except AttributeError:
            # Generic fallback
            print(df)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="p1"&gt;On Databricks notebook:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;from foo import df_show

df = spark.createDataFrame([{"x": 1}])

# Pass the notebook's `display` into your module
df_show(df, display)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="p1"&gt;Outside Databricks (plain Python / script):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;from foo import df_show
from pyspark.sql import SparkSession

spark = SparkSession.builder.getOrCreate()
df = spark.createDataFrame([{"x": 1}])

# No Databricks display available → falls back to df.show()
df_show(df)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="p1"&gt;This gives you:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;P class="p1"&gt;Databricks: full rich notebook visualization&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P class="p1"&gt;Non-Databricks: readable textual output via df.show() or print&lt;/P&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p3"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;Optional: central “smart display” wrapper&lt;/P&gt;
&lt;P class="p3"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;If you want to centralize this logic because you call it many times, define a “smart display” once and pass it around:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;# foo.py

def make_smart_display(visualizer=None):
    def _smart(obj):
        if visualizer is not None:
            visualizer(obj)
        else:
            try:
                obj.show()
            except AttributeError:
                print(obj)
    return _smart

def df_show(df, smart_display):
    smart_display(df)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="p1"&gt;Usage on Databricks:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;from foo import make_smart_display, df_show

smart_display = make_smart_display(display)
df_show(df, smart_display)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="p1"&gt;Usage off Databricks:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;from foo import make_smart_display, df_show

smart_display = make_smart_display()  # no visualizer → fallback
df_show(df, smart_display)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="p1"&gt;Design takeaway&lt;/P&gt;
&lt;P class="p1"&gt;The core idea is: keep UI concerns (like Databricks display) at the notebook boundary and inject them into reusable modules, rather than hard-coding display inside your modules. That way your code works cleanly both on Databricks and in any plain Python environment.&lt;/P&gt;
&lt;P class="p1"&gt;Cheers, Lou&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2026 14:16:22 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/using-built-in-display-method-modules/m-p/149622#M53135</guid>
      <dc:creator>Louis_Frolio</dc:creator>
      <dc:date>2026-03-02T14:16:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using built-in display method modules</title>
      <link>https://community.databricks.com/t5/data-engineering/using-built-in-display-method-modules/m-p/149683#M53154</link>
      <description>&lt;P&gt;Thanks Lou, based on your feedback I found another way.&lt;/P&gt;&lt;P&gt;When importing&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;databricks&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;sdk&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;runtime&lt;/SPAN&gt; &lt;SPAN&gt;import&lt;/SPAN&gt; &lt;SPAN&gt;display&lt;/SPAN&gt;&lt;/PRE&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;i can force python to use databricks implementation even in modules.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;The full code results in&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;import&lt;/SPAN&gt; &lt;SPAN&gt;os&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;if&lt;/SPAN&gt; &lt;SPAN&gt;"DATABRICKS_RUNTIME_VERSION"&lt;/SPAN&gt; &lt;SPAN&gt;in&lt;/SPAN&gt; &lt;SPAN&gt;os&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;environ&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;from&lt;/SPAN&gt; &lt;SPAN&gt;databricks&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;sdk&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;runtime&lt;/SPAN&gt; &lt;SPAN&gt;import&lt;/SPAN&gt; &lt;SPAN&gt;display&lt;/SPAN&gt; &lt;SPAN&gt;as&lt;/SPAN&gt; &lt;SPAN&gt;db_display&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;else&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;db_display&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;None&lt;/SPAN&gt;&lt;SPAN&gt; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;# pylint: disable=invalid-name&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def&lt;/SPAN&gt; &lt;SPAN&gt;df_show&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;data&lt;/SPAN&gt;&lt;SPAN&gt;) -&amp;gt; &lt;/SPAN&gt;&lt;SPAN&gt;None&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;""" Wrapper to display dataframes in both, databricks and local environment&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; """&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;if&lt;/SPAN&gt; &lt;SPAN&gt;db_display&lt;/SPAN&gt; &lt;SPAN&gt;is&lt;/SPAN&gt; &lt;SPAN&gt;not&lt;/SPAN&gt; &lt;SPAN&gt;None&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;db_display&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;data&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;else&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;print&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;data&lt;/SPAN&gt;&lt;SPAN&gt;.show(&lt;/SPAN&gt;&lt;SPAN&gt;10&lt;/SPAN&gt;&lt;SPAN&gt;))&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;Which solves the initial question. Now it's to be decided if we should keep logic and visualization separate.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 03 Mar 2026 11:02:16 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/using-built-in-display-method-modules/m-p/149683#M53154</guid>
      <dc:creator>holunder42</dc:creator>
      <dc:date>2026-03-03T11:02:16Z</dc:date>
    </item>
    <item>
      <title>Hi @holunder42, The behavior you are seeing is expected....</title>
      <link>https://community.databricks.com/t5/data-engineering/using-built-in-display-method-modules/m-p/150332#M53368</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/218287"&gt;@holunder42&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;The behavior you are seeing is expected. The display() function is not a standard Python built-in. It is injected into the notebook's global namespace by the Databricks runtime when a notebook cell executes. When you move code into an imported Python module (.py file), that module has its own namespace and does not automatically inherit display(), spark, dbutils, or other notebook-scoped objects. That is why your module falls back to the standard __repr__ output.&lt;/P&gt;
&lt;P&gt;RECOMMENDED APPROACH: PASS DISPLAY AS A PARAMETER&lt;/P&gt;
&lt;P&gt;The cleanest pattern is to pass the display function (or any notebook-scoped object) into your module as an argument:&lt;/P&gt;
&lt;P&gt;In your module file (e.g., my_utils.py):&lt;/P&gt;
&lt;PRE&gt;def show_data(df, display_fn=None):
  if display_fn is not None:
      display_fn(df)
  else:
      # Fallback for standard Python environments
      print(df.toPandas().to_string())&lt;/PRE&gt;
&lt;P&gt;In your notebook:&lt;/P&gt;
&lt;PRE&gt;from my_utils import show_data
df = spark.table("my_catalog.my_schema.my_table")
show_data(df, display_fn=display)&lt;/PRE&gt;
&lt;P&gt;This keeps your module portable. When running inside a Databricks notebook, you pass the built-in display. When running outside (unit tests, local development), the fallback kicks in.&lt;/P&gt;
&lt;P&gt;ALTERNATIVE: LOOK UP DISPLAY AT RUNTIME&lt;/P&gt;
&lt;P&gt;You can also detect whether you are running inside a Databricks notebook and grab display from the IPython environment:&lt;/P&gt;
&lt;PRE&gt;def get_display():
  try:
      from IPython.display import display as ipython_display
      # Check if the Databricks-enhanced display is available
      shell = get_ipython()
      if hasattr(shell, 'user_ns') and 'display' in shell.user_ns:
          return shell.user_ns['display']
      return ipython_display
  except Exception:
      return print

def show_data(df):
  display_fn = get_display()
  display_fn(df)&lt;/PRE&gt;
&lt;P&gt;In this approach, get_ipython().user_ns gives you access to the notebook's namespace, which includes the Databricks-enhanced display function that renders rich table output and charts.&lt;/P&gt;
&lt;P&gt;ALTERNATIVE: USE IPYTHON.DISPLAY DIRECTLY&lt;/P&gt;
&lt;P&gt;If you only need basic rendering (not the full Databricks rich table with chart options), the IPython.display module works from imported modules:&lt;/P&gt;
&lt;PRE&gt;from IPython.display import display, HTML

def show_html(html_string):
  display(HTML(html_string))&lt;/PRE&gt;
&lt;P&gt;This renders HTML output in the notebook cell. However, it does not give you the Databricks-specific table visualization with sorting, filtering, and chart creation. For that, you need the notebook-scoped display function.&lt;/P&gt;
&lt;P&gt;SUMMARY&lt;/P&gt;
&lt;PRE&gt;- display() is notebook-scoped, not available by default in imported modules
- Best practice: pass display as an argument to your module functions
- Runtime lookup via get_ipython().user_ns['display'] also works
- IPython.display provides basic rendering but not the full Databricks visualization&lt;/PRE&gt;
&lt;P&gt;Docs reference for working with Python modules in notebooks:&lt;BR /&gt;
&lt;A href="https://docs.databricks.com/en/files/workspace-modules.html" target="_blank"&gt;https://docs.databricks.com/en/files/workspace-modules.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Docs reference for IPython kernel support in Databricks:&lt;BR /&gt;
&lt;A href="https://docs.databricks.com/en/notebooks/ipython-kernel.html" target="_blank"&gt;https://docs.databricks.com/en/notebooks/ipython-kernel.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;* This reply used an agent system I built to research and draft this response based on the wide set of documentation I have available and previous memory. I personally review the draft for any obvious issues and for monitoring system reliability and update it when I detect any drift, but there is still a small chance that something is inaccurate, especially if you are experimenting with brand new features.&lt;/P&gt;
&lt;P&gt;If this answer resolves your question, could you mark it as "Accept as Solution"? That helps other users quickly find the correct fix.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Mar 2026 05:46:20 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/using-built-in-display-method-modules/m-p/150332#M53368</guid>
      <dc:creator>SteveOstrowski</dc:creator>
      <dc:date>2026-03-09T05:46:20Z</dc:date>
    </item>
  </channel>
</rss>

