Skip to content

Fix System.save_report for pandas 3.0 (and another two bugs)#243

Merged
yoelcortes merged 1 commit into
masterfrom
fix/save-report-pandas3-compat
May 26, 2026
Merged

Fix System.save_report for pandas 3.0 (and another two bugs)#243
yoelcortes merged 1 commit into
masterfrom
fix/save-report-pandas3-compat

Conversation

@yalinli2
Copy link
Copy Markdown
Member

pandas 3.0 made DataFrame/Series.to_excel's sheet_name keyword-only, so the positional calls in save_report raised
TypeError: NDFrame.to_excel() takes 2 positional arguments but 3 were given. Pass sheet_name= instead (Itemized costs, Cash flow, and report.tables_to_excel, which the other sheets route through). This is backward compatible: sheet_name has always been a valid keyword on pandas 2.x.

Also fixes two pre-existing, pandas-independent save_report bugs surfaced while testing:

  • Initialize diagram_completed = False so a custom sheets set that omits 'Flowsheet' no longer raises UnboundLocalError at cleanup.
  • Skip the 'Water mass balance' sheet (with a warning) when the system has no ProcessWaterCenter, instead of raising LookupError (the sheet is defined relative to a ProcessWaterCenter).

Enable test_save_report and add test_save_report_skips_water_mass_balance_without_PWC in tests/test_report.py (graphviz-free, so CI-safe).

pandas 3.0 made DataFrame/Series.to_excel's `sheet_name` keyword-only, so the
positional calls in save_report raised
`TypeError: NDFrame.to_excel() takes 2 positional arguments but 3 were given`.
Pass `sheet_name=` instead (Itemized costs, Cash flow, and report.tables_to_excel,
which the other sheets route through). This is backward compatible: `sheet_name`
has always been a valid keyword on pandas 2.x.

Also fixes two pre-existing, pandas-independent save_report bugs surfaced while
testing:
- Initialize `diagram_completed = False` so a custom `sheets` set that omits
  'Flowsheet' no longer raises UnboundLocalError at cleanup.
- Skip the 'Water mass balance' sheet (with a warning) when the system has no
  ProcessWaterCenter, instead of raising LookupError (the sheet is defined
  relative to a ProcessWaterCenter).

Enable test_save_report and add test_save_report_skips_water_mass_balance_without_PWC
in tests/test_report.py (graphviz-free, so CI-safe).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@yoelcortes yoelcortes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks good to me. Thank you for the improvements!!

@yoelcortes yoelcortes merged commit 9d66150 into master May 26, 2026
1 of 3 checks passed
@yalinli2 yalinli2 deleted the fix/save-report-pandas3-compat branch May 26, 2026 16:03
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.

2 participants