@@ -1638,7 +1638,7 @@ def _normalize_tabular_data(tabular_data, headers, showindex="default"):
16381638 return rows , headers , headers_pad
16391639
16401640
1641- def _wrap_text_to_colwidths (list_of_lists , colwidths , numparses = True , break_long_words = _BREAK_LONG_WORDS , break_on_hyphens = _BREAK_ON_HYPHENS ):
1641+ def _wrap_text_to_colwidths (list_of_lists , colwidths , numparses = True , missingval = _DEFAULT_MISSINGVAL , break_long_words = _BREAK_LONG_WORDS , break_on_hyphens = _BREAK_ON_HYPHENS ):
16421642 if len (list_of_lists ):
16431643 num_cols = len (list_of_lists [0 ])
16441644 else :
@@ -1656,7 +1656,13 @@ def _wrap_text_to_colwidths(list_of_lists, colwidths, numparses=True, break_long
16561656
16571657 if width is not None :
16581658 wrapper = _CustomTextWrap (width = width , break_long_words = break_long_words , break_on_hyphens = break_on_hyphens )
1659- casted_cell = str (cell )
1659+ # Cast based on our internal type handling. Any future custom
1660+ # formatting of types (such as datetimes) may need to be more
1661+ # explicit than just `str` of the object. Also doesn't work for
1662+ # custom floatfmt/intfmt, nor with any missing/blank cells.
1663+ casted_cell = (
1664+ missingval if cell is None else str (cell ) if cell == '' or _isnumber (cell ) else _type (cell , numparse )(cell )
1665+ )
16601666 wrapped = [
16611667 "\n " .join (wrapper .wrap (line ))
16621668 for line in casted_cell .splitlines ()
@@ -2258,7 +2264,7 @@ def tabulate(
22582264
22592265 numparses = _expand_numparse (disable_numparse , num_cols )
22602266 list_of_lists = _wrap_text_to_colwidths (
2261- list_of_lists , maxcolwidths , numparses = numparses , break_long_words = break_long_words , break_on_hyphens = break_on_hyphens
2267+ list_of_lists , maxcolwidths , numparses = numparses , missingval = missingval , break_long_words = break_long_words , break_on_hyphens = break_on_hyphens
22622268 )
22632269
22642270 if maxheadercolwidths is not None :
@@ -2272,7 +2278,7 @@ def tabulate(
22722278
22732279 numparses = _expand_numparse (disable_numparse , num_cols )
22742280 headers = _wrap_text_to_colwidths (
2275- [headers ], maxheadercolwidths , numparses = numparses , break_long_words = break_long_words , break_on_hyphens = break_on_hyphens
2281+ [headers ], maxheadercolwidths , numparses = numparses , missingval = missingval , break_long_words = break_long_words , break_on_hyphens = break_on_hyphens
22762282 )[0 ]
22772283
22782284 # empty values in the first column of RST tables should be escaped (issue #82)
0 commit comments