nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: astanin/python-tabulate
Pull request #157 (2021-11-11 00:09:18)

provide a parameter that allows for controlling header maxcolwidth
Used a separate parameter to not break any usage/thoughts for maxcolwidth in the data. I can see how it may be useful to keep the two separate


Patch:
diff --git a/tabulate.py b/tabulate.py
index 0579fb3..c7f6eeb 100644
--- a/tabulate.py
+++ b/tabulate.py
@@ -1251,6 +1251,7 @@ def tabulate(
     disable_numparse=False,
     colalign=None,
     maxcolwidths=None,
+    maxheadercolwidths=None,
 ):
     """Format a fixed width table for pretty printing.
 
@@ -1572,6 +1573,7 @@ def tabulate(
     |            |            | better if it is wrapped a bit |
     +------------+------------+-------------------------------+
 
+    Header column width can be specified in a similar way using `maxheadercolwidth`
 
     """
 
@@ -1593,6 +1595,19 @@ def tabulate(
             list_of_lists, maxcolwidths, numparses=numparses
         )
 
+    if maxheadercolwidths is not None:
+        num_cols = len(list_of_lists[0])
+        if isinstance(maxheadercolwidths, int):  # Expand scalar for all columns
+            maxheadercolwidths = _expand_iterable(maxheadercolwidths, num_cols, maxheadercolwidths)
+        else:  # Ignore col width for any 'trailing' columns
+            maxheadercolwidths = _expand_iterable(maxheadercolwidths, num_cols, None)
+
+        numparses = _expand_numparse(disable_numparse, num_cols)
+        headers = _wrap_text_to_colwidths(
+            [headers], maxheadercolwidths, numparses=numparses
+        )[0]
+
+
     # empty values in the first column of RST tables should be escaped (issue #82)
     # "" should be escaped as "\\ " or ".."
     if tablefmt == "rst":


Test patch:
diff --git a/test/test_api.py b/test/test_api.py
index 5b77c0e..693c23c 100644
--- a/test/test_api.py
+++ b/test/test_api.py
@@ -56,6 +56,7 @@ def test_tabulate_signature():
         ("disable_numparse", False),
         ("colalign", None),
         ("maxcolwidths", None),
+        ("maxheadercolwidths", None),
     ]
     _check_signature(tabulate, expected_sig)
 
diff --git a/test/test_output.py b/test/test_output.py
index eed4489..4133564 100644
--- a/test/test_output.py
+++ b/test/test_output.py
@@ -200,6 +200,14 @@ def test_maxcolwidth_honor_disable_parsenum():
     result = tabulate(table, tablefmt="grid", maxcolwidths=6, disable_numparse=[2])
     assert_equal(expected, result)
 
+def test_plain_maxheadercolwidths_autowraps():
+    "Output: maxheadercolwidths will result in autowrapping header cell"
+    table = [["hdr", "fold"], ["1", "very long data"]]
+    expected = "\n".join(["  hdr  fo","       ld", "    1  very long", "       data"])
+    result = tabulate(
+        table, headers="firstrow", tablefmt="plain", maxcolwidths=[10, 10], maxheadercolwidths=[None, 2]
+    )
+    assert_equal(expected, result)
 
 def test_simple():
     "Output: simple with headers"
Repository: astanin/python-tabulate
Pull request #210 (2022-10-26 16:35:50)

Replace deprecated HTML
As stated on [wikipedia:WP:HTML5](https://en.wikipedia.org/wiki/Wikipedia:HTML_5), all instances of `align="center"` or `align="right"` must be replaced with `style="text-align: center;"` or `style="text-align: right;"`, respectively, to align text.


Patch:
diff --git a/tabulate/__init__.py b/tabulate/__init__.py
index 9cf6991..3b1a1e1 100644
--- a/tabulate/__init__.py
+++ b/tabulate/__init__.py
@@ -136,9 +136,9 @@ def _pipe_line_with_colons(colwidths, colaligns):
 def _mediawiki_row_with_attrs(separator, cell_values, colwidths, colaligns):
     alignment = {
         "left": "",
-        "right": 'align="right"| ',
-        "center": 'align="center"| ',
-        "decimal": 'align="right"| ',
+        "right": 'style="text-align: right;"| ',
+        "center": 'style="text-align: center;"| ',
+        "decimal": 'style="text-align: right;"| ',
     }
     # hard-coded padding _around_ align attribute and value together
     # rather than padding parameter which affects only the value
@@ -1952,11 +1952,11 @@ def tabulate(
     {| class="wikitable" style="text-align: left;"
     |+ <!-- caption -->
     |-
-    ! strings   !! align="right"|   numbers
+    ! strings   !! style="text-align: right;"|   numbers
     |-
-    | spam      || align="right"|   41.9999
+    | spam      || style="text-align: right;"|   41.9999
     |-
-    | eggs      || align="right"|  451
+    | eggs      || style="text-align: right;"|  451
     |}
 
     "html" produces HTML markup as an html.escape'd str


Test patch:
diff --git a/test/test_output.py b/test/test_output.py
index 9a9a452..9043aed 100644
--- a/test/test_output.py
+++ b/test/test_output.py
@@ -2322,11 +2322,11 @@ def test_mediawiki():
             '{| class="wikitable" style="text-align: left;"',
             "|+ <!-- caption -->",
             "|-",
-            '! strings   !! align="right"|   numbers',
+            '! strings   !! style="text-align: right;"|   numbers',
             "|-",
-            '| spam      || align="right"|   41.9999',
+            '| spam      || style="text-align: right;"|   41.9999',
             "|-",
-            '| eggs      || align="right"|  451',
+            '| eggs      || style="text-align: right;"|  451',
             "|}",
         ]
     )
@@ -2341,9 +2341,9 @@ def test_mediawiki_headerless():
             '{| class="wikitable" style="text-align: left;"',
             "|+ <!-- caption -->",
             "|-",
-            '| spam || align="right"|  41.9999',
+            '| spam || style="text-align: right;"|  41.9999',
             "|-",
-            '| eggs || align="right"| 451',
+            '| eggs || style="text-align: right;"| 451',
             "|}",
         ]
     )
Repository: astanin/python-tabulate
Pull request #232 (2022-12-27 03:25:04)

Fix bug/issue #231: SEPARATING_LINE feature doesn't work when the requested format pads columns
The subject says it all.. 😉 
Tested:
```
lint: OK (6.63=setup[4.07]+cmd[2.56] seconds)
  py37: OK (5.15=setup[3.97]+cmd[1.19] seconds)
  py38: OK (4.83=setup[3.63]+cmd[1.20] seconds)
  py39: OK (4.42=setup[3.28]+cmd[1.14] seconds)
  py310: OK (4.77=setup[3.57]+cmd[1.20] seconds)
  py311: OK (4.59=setup[3.34]+cmd[1.25] seconds)
  congratulations :) (30.46 seconds)
```



Patch:
diff --git a/tabulate/__init__.py b/tabulate/__init__.py
index 3b1a1e1..bf2ed78 100644
--- a/tabulate/__init__.py
+++ b/tabulate/__init__.py
@@ -101,12 +101,17 @@ TableFormat = namedtuple(
 )
 
 
+def _is_separating_line_value(value):
+    return type(value) == str and value.strip() == SEPARATING_LINE
+
+
 def _is_separating_line(row):
     row_type = type(row)
     is_sl = (row_type == list or row_type == str) and (
-        (len(row) >= 1 and row[0] == SEPARATING_LINE)
-        or (len(row) >= 2 and row[1] == SEPARATING_LINE)
+        (len(row) >= 1 and _is_separating_line_value(row[0]))
+        or (len(row) >= 2 and _is_separating_line_value(row[1]))
     )
+
     return is_sl
 
 


Test patch:
diff --git a/test/test_output.py b/test/test_output.py
index 9043aed..b58b187 100644
--- a/test/test_output.py
+++ b/test/test_output.py
@@ -2881,6 +2881,27 @@ def test_list_of_lists_with_index_with_sep_line():
     assert_equal(expected, result)
 
 
+def test_with_padded_columns_with_sep_line():
+    table = [
+        ["1", "one"],  # "1" as a str on purpose
+        [1_000, "one K"],
+        SEPARATING_LINE,
+        [1_000_000, "one M"],
+    ]
+    expected = "\n".join(
+        [
+            "+---------+-------+",
+            "|       1 | one   |",
+            "|    1000 | one K |",
+            "|---------+-------|",
+            "| 1000000 | one M |",
+            "+---------+-------+",
+        ]
+    )
+    result = tabulate(table, tablefmt="psql")
+    assert_equal(expected, result)
+
+
 def test_list_of_lists_with_supplied_index():
     "Output: a table with a supplied index"
     dd = zip(*[list(range(3)), list(range(101, 104))])
Repository: astanin/python-tabulate
Pull request #300 (2023-11-18 22:43:44)

Fix TypeError when using a tuple for maxcolwidths #214
This PR fixes issue [#214](https://github.com/astanin/python-tabulate/issues/214)

Issue:
- When you used a tuple for maxcolwidths, it caused an `TypeError` error.

PR:
- The original PR [#215](https://github.com/astanin/python-tabulate/pull/215) created by [Racerroar888](https://github.com/Racerroar888) was closed without merging, because of a merge conflict   
- This new PR includes the original code fix, a unit test, and fixes the merge conflict.



Patch:
diff --git a/README.md b/README.md
index 07ab28c..7710147 100644
--- a/README.md
+++ b/README.md
@@ -1136,5 +1136,4 @@ Bart Broere, Vilhelm Prytz, Alexander Gažo, Hugo van Kemenade,
 jamescooke, Matt Warner, Jérôme Provensal, Kevin Deldycke,
 Kian-Meng Ang, Kevin Patterson, Shodhan Save, cleoold, KOLANICH,
 Vijaya Krishna Kasula, Furcy Pin, Christian Fibich, Shaun Duncan,
-Dimitri Papadopoulos, Élie Goudout.
-
+Dimitri Papadopoulos, Élie Goudout, Racerroar888, Phill Zarfos.
diff --git a/tabulate/__init__.py b/tabulate/__init__.py
index 11bb865..baf9a0c 100644
--- a/tabulate/__init__.py
+++ b/tabulate/__init__.py
@@ -2091,6 +2091,8 @@ def tabulate(
     list_of_lists, separating_lines = _remove_separating_lines(list_of_lists)
 
     if maxcolwidths is not None:
+        if type(maxcolwidths) is tuple:  # Check if tuple, convert to list if so
+            maxcolwidths = list(maxcolwidths)
         if len(list_of_lists):
             num_cols = len(list_of_lists[0])
         else:


Test patch:
diff --git a/test/test_regression.py b/test/test_regression.py
index 8f60ce7..29f275e 100644
--- a/test/test_regression.py
+++ b/test/test_regression.py
@@ -488,6 +488,27 @@ def test_preserve_line_breaks_with_maxcolwidths():
     assert_equal(expected, result)
 
 
+def test_maxcolwidths_accepts_list_or_tuple():
+    "Regression: maxcolwidths can accept a list or a tuple (github issue #214)"
+    table = [["lorem ipsum dolor sit amet"]*3]
+    expected = "\n".join(
+        [
+            "+-------------+----------+----------------------------+",
+            "| lorem ipsum | lorem    | lorem ipsum dolor sit amet |",
+            "| dolor sit   | ipsum    |                            |",
+            "| amet        | dolor    |                            |",
+            "|             | sit amet |                            |",
+            "+-------------+----------+----------------------------+",
+        ]
+    )
+    # test with maxcolwidths as a list
+    result = tabulate(table, tablefmt="grid", maxcolwidths=[12, 8])
+    assert_equal(expected, result)
+    # test with maxcolwidths as a tuple
+    result = tabulate(table, tablefmt="grid", maxcolwidths=(12, 8))
+    assert_equal(expected, result)
+
+
 def test_exception_on_empty_data_with_maxcolwidths():
     "Regression: exception on empty data when using maxcolwidths (github issue #180)"
     result = tabulate([], maxcolwidths=5)
Repository: astanin/python-tabulate
Pull request #331 (2024-06-25 21:29:21)

Fix support for separating lines


Patch:
diff --git a/tabulate/__init__.py b/tabulate/__init__.py
index 11bb865..ff8591c 100644
--- a/tabulate/__init__.py
+++ b/tabulate/__init__.py
@@ -2304,6 +2304,8 @@ def _expand_iterable(original, num_desired, default):
 
 def _pad_row(cells, padding):
     if cells:
+        if cells == SEPARATING_LINE:
+            return SEPARATING_LINE
         pad = " " * padding
         padded_cells = [pad + cell + pad for cell in cells]
         return padded_cells
@@ -2427,9 +2429,10 @@ def _format_table(fmt, headers, headersaligns, rows, colwidths, colaligns, is_mu
     if padded_rows and fmt.linebetweenrows and "linebetweenrows" not in hidden:
         # initial rows with a line below
         for row, ralign in zip(padded_rows[:-1], rowaligns):
-            append_row(
-                lines, row, padded_widths, colaligns, fmt.datarow, rowalign=ralign
-            )
+            if row != SEPARATING_LINE:
+                append_row(
+                    lines, row, padded_widths, colaligns, fmt.datarow, rowalign=ralign
+                )
             _append_line(lines, padded_widths, colaligns, fmt.linebetweenrows)
         # the last row without a line below
         append_row(


Test patch:
diff --git a/test/test_output.py b/test/test_output.py
index d572498..1768720 100644
--- a/test/test_output.py
+++ b/test/test_output.py
@@ -335,6 +335,36 @@ def test_simple_headerless_with_sep_line():
     assert_equal(expected, result)
 
 
+def test_simple_headerless_with_sep_line_with_padding_in_tablefmt():
+    "Output: simple without headers with sep line with padding in tablefmt"
+    expected = "\n".join(
+        [
+            "|------|----------|",
+            "| spam |  41.9999 |",
+            "|------|----------|",
+            "| eggs | 451      |",
+        ]
+    )
+    result = tabulate(_test_table_with_sep_line, tablefmt="github")
+    assert_equal(expected, result)
+
+
+def test_simple_headerless_with_sep_line_with_linebetweenrows_in_tablefmt():
+    "Output: simple without headers with sep line with linebetweenrows in tablefmt"
+    expected = "\n".join(
+        [
+            "+------+----------+",
+            "| spam |  41.9999 |",
+            "+------+----------+",
+            "+------+----------+",
+            "| eggs | 451      |",
+            "+------+----------+",
+        ]
+    )
+    result = tabulate(_test_table_with_sep_line, tablefmt="grid")
+    assert_equal(expected, result)
+
+
 def test_simple_multiline_headerless():
     "Output: simple with multiline cells without headers"
     table = [["foo bar\nbaz\nbau", "hello"], ["", "multiline\nworld"]]
Repository: astanin/python-tabulate
Pull request #366 (2025-05-06 12:13:21)

Fix multiline support for github format
## Issue (https://github.com/astanin/python-tabulate/issues/355#issuecomment-2754367738)
In the `tabulate` library, the `github` format did not properly handle multiline text.  
If you passed tabulate data cells containing multiline text and used the `maxcolwidths` parameter to truncate text, the result was incorrect because the `github` format was not included in the list of formats that support multiline text processing.

## Solution
The issue was that the `github` format was not added to the `multiline_formats` dictionary, which defines the formats that support multiline text.  
The solution was simple: just add `"github": "github"` to this dictionary.

After our fix, the `github` format now correctly processes multiline text, just like other supported formats such as `fancy_outline`.


Patch:
diff --git a/tabulate/__init__.py b/tabulate/__init__.py
index b15d7f0..d418e96 100644
--- a/tabulate/__init__.py
+++ b/tabulate/__init__.py
@@ -737,6 +737,7 @@ multiline_formats = {
     "pretty": "pretty",
     "psql": "psql",
     "rst": "rst",
+    "github": "github",
     "outline": "outline",
     "simple_outline": "simple_outline",
     "rounded_outline": "rounded_outline",


Test patch:
diff --git a/test/test_output.py b/test/test_output.py
index e3d369a..2a1415b 100644
--- a/test/test_output.py
+++ b/test/test_output.py
@@ -509,6 +509,23 @@ def test_github():
     assert_equal(expected, result)
 
 
+def test_github_multiline():
+    "Output: github with multiline cells with headers"
+    table = [[2, "foo\nbar"]]
+    headers = ("more\nspam eggs", "more spam\n& eggs")
+    expected = "\n".join(
+        [
+            "|        more | more spam   |",
+            "|   spam eggs | & eggs      |",
+            "|-------------|-------------|",
+            "|           2 | foo         |",
+            "|             | bar         |",
+        ]
+    )
+    result = tabulate(table, headers, tablefmt="github")
+    assert_equal(expected, result)
+
+
 def test_grid():
     "Output: grid with headers"
     expected = "\n".join(