Skip to content

Commit 4b57892

Browse files
committed
Add global option for urls_as_links
1 parent a0879c2 commit 4b57892

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

pandas/core/config_init.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,13 @@ def use_numexpr_cb(key):
215215
(default: True)
216216
"""
217217

218+
pc_html_urls_as_links_doc = """\
219+
: boolean
220+
When True, DataFrame's to_html() will output cells that appear to contain
221+
a URL with a link to that URL.
222+
(default: False)
223+
"""
224+
218225
pc_width_doc = """
219226
: int
220227
Width of the display in characters. In case python/IPython is running in
@@ -371,6 +378,8 @@ def table_schema_cb(key):
371378
validator=is_int)
372379
cf.register_option('html.use_mathjax', True, pc_html_use_mathjax_doc,
373380
validator=is_bool)
381+
cf.register_option('html.urls_as_links', False, pc_html_urls_as_links_doc,
382+
validator=is_bool)
374383

375384
with cf.config_prefix('html'):
376385
cf.register_option('border', 1, pc_html_border_doc,

pandas/core/frame.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2086,7 +2086,7 @@ def to_html(self, buf=None, columns=None, col_space=None, header=True,
20862086
sparsify=None, index_names=True, justify=None, bold_rows=True,
20872087
classes=None, escape=True, max_rows=None, max_cols=None,
20882088
show_dimensions=False, notebook=False, decimal='.',
2089-
border=None, table_id=None, urls_as_links=False):
2089+
border=None, table_id=None, urls_as_links=None):
20902090
"""
20912091
Render a DataFrame as an HTML table.
20922092
@@ -2129,6 +2129,9 @@ def to_html(self, buf=None, columns=None, col_space=None, header=True,
21292129
justify not in fmt._VALID_JUSTIFY_PARAMETERS):
21302130
raise ValueError("Invalid value for justify parameter")
21312131

2132+
if urls_as_links is None:
2133+
urls_as_links = get_option("display.html.urls_as_links")
2134+
21322135
formatter = fmt.DataFrameFormatter(self, buf=buf, columns=columns,
21332136
col_space=col_space, na_rep=na_rep,
21342137
formatters=formatters,

pandas/tests/io/formats/test_to_html.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,3 +1998,9 @@ def test_to_html_urls_as_links(self):
19981998

19991999
assert result_with_links == expected_with_links
20002000
assert result_no_links == expected_no_links
2001+
2002+
pd.options.display.html.urls_as_links = True
2003+
result_no_option_specified = df.to_html()
2004+
pd.options.display.html.urls_as_links = False
2005+
2006+
assert result_no_option_specified == expected_with_links

0 commit comments

Comments
 (0)