Skip to content

Separating lines break sized row indices and shift DataFrame labels #464

Open

Description

@kokotatan

showindex supplied as a list or tuple counts separating lines as data rows during length validation. The equivalent iterator succeeds. Separating lines should not consume row index values.

Reproducer against current master:

from tabulate import SEPARATING_LINE, tabulate

rows = [["a"], SEPARATING_LINE, ["b"]]
print(tabulate(rows, showindex=iter([10, 20]), tablefmt="grid"))  # succeeds
print(tabulate(rows, showindex=[10, 20], tablefmt="grid"))  # ValueError

The list raises ValueError: index must be as long as the number of data rows: len(index)=2 len(rows)=3. Conversely, a list of three IDs succeeds but silently drops its last ID. There are only two data rows.

The same counting problem affects a DataFrame's own index labels when a separator row is present:

import pandas as pd

frame = pd.DataFrame(
    [["a", 1], [SEPARATING_LINE, None], ["b", 2]],
    index=["row-a", "separator", "row-b"],
)
print(tabulate(frame, tablefmt="grid"))

The final data row gets the label separator rather than row-b. Its original label should stay attached to that row.

I reproduced these cases locally on Windows/Python 3.13 and prepared a small fix with public regression tests. AI assistance was used for investigation and review; the reproductions and tests were executed locally.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions