@@ -56,11 +56,13 @@ def __init__(
5656 for i in range (len (options .column_widths )):
5757 option = options .column_widths [i ]
5858 minimum = self .__column_widths [i ]
59- if option < minimum :
59+ if option is None :
60+ option = minimum
61+ elif option < minimum :
6062 raise ValueError (
6163 f"The value at index { i } of `column_widths` is { option } which is less than the minimum { minimum } ."
6264 )
63- self .__column_widths = options . column_widths
65+ self .__column_widths [ i ] = option
6466
6567 self .__alignments = options .alignments or [Alignment .CENTER ] * self .__columns
6668
@@ -314,25 +316,35 @@ def table2ascii(
314316 * ,
315317 first_col_heading : bool = False ,
316318 last_col_heading : bool = False ,
317- column_widths : Optional [List [int ]] = None ,
319+ column_widths : Optional [List [Optional [ int ] ]] = None ,
318320 alignments : Optional [List [Alignment ]] = None ,
319321 style : TableStyle = PresetStyle .double_thin_compact ,
320322) -> str :
321323 """
322324 Convert a 2D Python table to ASCII text
323325
324326 Args:
325- header (:class:`Optional[List[Any]]`): List of column values in the table's header row
326- body (:class:`Optional[List[List[Any]]]`): 2-dimensional list of values in the table's body
327- footer (:class:`Optional[List[Any]]`): List of column values in the table's footer row
328- first_col_heading (:class:`bool`): Whether to add a header column separator after the first column
329- last_col_heading (:class:`bool`): Whether to add a header column separator before the last column
330- column_widths (:class:`Optional[List[int]]`): List of widths in characters for each column (``None`` for auto-sizing)
331- alignments (:class:`List[Alignment]`): List of alignments (ex. `[Alignment.LEFT, Alignment.CENTER, Alignment.RIGHT]`)
332- style (:class:`TableStyle`): Table style to use for styling (preset styles can be imported)
327+ header (Optional[List[Any]]): List of column values in the table's header row.
328+ If not specified, the table will not have a header row.
329+ body (Optional[List[List[Any]]]): 2-dimensional list of values in the table's body.
330+ If not specified, the table will not have a body.
331+ footer (Optional[List[Any]]): List of column values in the table's footer row.
332+ If not specified, the table will not have a footer row.
333+ first_col_heading (:class:`bool`): Whether to add a header column separator after the first
334+ column. Defaults to ``False``.
335+ last_col_heading (:class:`bool`): Whether to add a header column separator before the last
336+ column. Defaults to ``False``.
337+ column_widths (Optional[List[Optional[:class:`int`]]]): List of widths in characters for each
338+ column. Any value of ``None`` indicates that the column width should be determined automatically.
339+ If ``column_widths`` is set to ``None``, all columns will be automatically sized. Defaults to ``None``.
340+ alignments (Optional[List[:class:`Alignment`]]): List of alignments for each column
341+ (ex. ``[Alignment.LEFT, Alignment.CENTER, Alignment.RIGHT]``). If not specified or set to ``None``,
342+ all columns will be center-aligned. Defaults to ``None``.
343+ style (:class:`TableStyle`): Table style to use for styling (preset styles can be imported).
344+ Defaults to :data:`PresetStyle.double_thin_compact`.
333345
334346 Returns:
335- str: The generated ASCII table
347+ :class:` str` : The generated ASCII table
336348 """
337349 return TableToAscii (
338350 header ,
0 commit comments