Skip to content

Commit 7e6b10c

Browse files
committed
BUG: Validate the justify parameter in to_html
Closes pandas-devgh-17527.
1 parent 2ff1241 commit 7e6b10c

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

doc/source/whatsnew/v0.21.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,7 @@ I/O
779779
- Bug in :func:`read_csv` where automatic delimiter detection caused a ``TypeError`` to be thrown when a bad line was encountered rather than the correct error message (:issue:`13374`)
780780
- Bug in ``DataFrame.to_html()`` with ``notebook=True`` where DataFrames with named indices or non-MultiIndex indices had undesired horizontal or vertical alignment for column or row labels, respectively (:issue:`16792`)
781781
- Bug in :func:`HDFStore.select` when reading a contiguous mixed-data table featuring VLArray (:issue:`17021`)
782+
- Bug in :func:`to_html` in which there was no validation of the ``justify`` parameter (:issue:`17527`)
782783

783784
Plotting
784785
^^^^^^^^

pandas/core/frame.py

+5
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,11 @@ def to_html(self, buf=None, columns=None, col_space=None, header=True,
16851685
.. versionadded:: 0.19.0
16861686
"""
16871687

1688+
if justify not in ("left", "right", "center", "justify",
1689+
"justify-all", "start", "end", "inherit",
1690+
"match-parent", "initial", "unset"):
1691+
raise ValueError("Invalid value for justify parameter")
1692+
16881693
formatter = fmt.DataFrameFormatter(self, buf=buf, columns=columns,
16891694
col_space=col_space, na_rep=na_rep,
16901695
formatters=formatters,

pandas/io/formats/format.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,10 @@
8080
Width to wrap a line in characters, default no wrap"""
8181

8282
justify_docstring = """
83-
justify : {'left', 'right'}, default None
84-
Left or right-justify the column labels. If None uses the option from
83+
justify : {'left', 'right', 'center', 'justify',
84+
'justify-all', 'start', 'end', 'inherit',
85+
'match-parent', 'initial', 'unset'}, default None
86+
How to justify the column labels. If None uses the option from
8587
the print configuration (controlled by set_option), 'right' out
8688
of the box."""
8789

0 commit comments

Comments
 (0)