File tree 3 files changed +21
-1
lines changed
3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 309
309
- Bug in :func: `DataFrame.to_string ` where values were truncated using display options instead of outputting the full content (:issue: `9784 `)
310
310
- Bug in :meth: `DataFrame.to_json ` where a datetime column label would not be written out in ISO format with ``orient="table" `` (:issue: `28130 `)
311
311
- Bug in :func: `DataFrame.to_parquet ` where writing to GCS would fail with `engine='fastparquet' ` if the file did not already exist (:issue: `28326 `)
312
+ - Bug in :meth: `DataFrame.to_html ` where the length of the ``formatters `` argument was not verified (:issue: `28469 `)
312
313
313
314
Plotting
314
315
^^^^^^^^
Original file line number Diff line number Diff line change @@ -561,7 +561,17 @@ def __init__(
561
561
self .sparsify = sparsify
562
562
563
563
self .float_format = float_format
564
- self .formatters = formatters if formatters is not None else {}
564
+ if formatters is None :
565
+ self .formatters = {}
566
+ elif len (frame .columns ) == len (formatters ) or isinstance (formatters , dict ):
567
+ self .formatters = formatters
568
+ else :
569
+ raise ValueError (
570
+ (
571
+ "Formatters length({flen}) should match"
572
+ " DataFrame number of columns({dlen})"
573
+ ).format (flen = len (formatters ), dlen = len (frame .columns ))
574
+ )
565
575
self .na_rep = na_rep
566
576
self .decimal = decimal
567
577
self .col_space = col_space
Original file line number Diff line number Diff line change @@ -235,6 +235,15 @@ def test_to_html_truncate(datapath):
235
235
assert result == expected
236
236
237
237
238
+ @pytest .mark .parametrize ("size" , [1 , 5 ])
239
+ def test_html_invalid_formatters_arg_raises (size ):
240
+ # issue-28469
241
+ df = DataFrame (columns = ["a" , "b" , "c" ])
242
+ msg = "Formatters length({}) should match DataFrame number of columns(3)"
243
+ with pytest .raises (ValueError , match = re .escape (msg .format (size ))):
244
+ df .to_html (formatters = ["{}" .format ] * size )
245
+
246
+
238
247
def test_to_html_truncate_formatter (datapath ):
239
248
# issue-25955
240
249
data = [
You can’t perform that action at this time.
0 commit comments