Skip to content

Accept notes=None in DOCX output - #130

Open
soodoku wants to merge 1 commit into
py-econometrics:mainfrom
finite-sample:fix/docx-notes-none
Open

soodoku wants to merge 1 commit into
py-econometrics:mainfrom
finite-sample:fix/docx-notes-none

Conversation

@soodoku

@soodoku soodoku commented Nov 8, 2026

Copy link
Copy Markdown

What problem do you want to solve?

MTable(notes=None) works in every format except DOCX.

import pandas as pd
from maketables import MTable

t = MTable(pd.DataFrame({"c": ["1"]}, index=["r"]), notes=None)
for typ in ["tex", "typst", "gt", "docx"]:
    t.make(type=typ)

On main, tex, typst and gt succeed. docx raises TypeError: 'NoneType' object is not iterable. The LaTeX renderer (if self.notes is not None), Typst ("" if self.notes is None else ...) and great_tables all handle None explicitly. DOCX passes self.notes straight to _translate_symbols and python-docx.

Expected: DOCX output also succeeds.

Fix

DOCX treats None like an empty note. The notes row that DOCX always adds is kept, so the table layout is the same as with notes="". That matters because the font-size loop identifies the notes row as the last row.

Tests

New tests in tests/api/test_mtable_outputs.py:

  • test_notes_none_is_accepted_by_every_format, parametrized over the four formats;
  • test_docx_notes_none_matches_empty_notes, which checks that the DOCX table is identical for notes=None and notes="".

2 of the 5 cases fail on main (both DOCX) and all 5 pass with the fix.

  • Full suite: 503 passed. No snapshot changes.
  • pre-commit run --files <changed> and ty check are clean.

Open question

MTable.__init__ annotates notes: str, but three renderers already treat None as "no notes". Widening the annotation to str | None would document what the code does. It is left unchanged here to keep this PR to the bug.

🤖 Generated with Claude Code

MTable(notes=None) renders in LaTeX, Typst and HTML, which all check
for None explicitly, but DOCX passed self.notes straight to the symbol
translator and python-docx and raised "TypeError: 'NoneType' object is
not iterable". DOCX now treats None like an empty note, keeping the
(empty) notes row it always adds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant