Skip to content

feat: summary() returns dict of stats along with printing and added validation tests #315#504

Open
archi3103 wants to merge 1 commit intodswah:mainfrom
archi3103:feat-summary-dict-return
Open

feat: summary() returns dict of stats along with printing and added validation tests #315#504
archi3103 wants to merge 1 commit intodswah:mainfrom
archi3103:feat-summary-dict-return

Conversation

@archi3103
Copy link

Fixes #315

This PR addresses the issue by modifying the summary() method to return a dictionary containing model and term statistics.

Changes

  • Updated summary() to create and return stats_dict.
  • I made sure to store the actual numbers for things like AIC and EDoF, so they stay accurate if someone wants to use them in a script.
  • Updated the function comments to show that it returns a dictionary now.
  • Added a new test file pygam/tests/test_summary_return.py to make sure the dictionary is returning the right numbers from the model.

Why this is a good modification

Currently, the summary() method only prints information to the console. But if someone wants to use values like the AIC or p-values in a loop to compare a bunch of different models, they have to copy the numbers by hand.

By having the function return a dictionary, it's much easier to work with the data in code or save it for later. I also made sure to keep the full numbers (not just the rounded ones in the table) so they stay accurate for calculations.

No changes to current functionality
I was careful to make sure this doesn't break anything for existing users. The table still prints in the console exactly as it did before.

If someone doesn't want or needs the dictionary, they can just call gam.summary() like they always have. In Python, if you don't assign the output of a function to a variable, the return value is just ignored, so it won't affect their workflow or clutter their terminal. This makes the change purely additive.

Testing

  • Full test suite passed locally (including the new validation test).
  • I also checked that the printed table still looks exactly the same as before.

@archi3103 archi3103 force-pushed the feat-summary-dict-return branch 6 times, most recently from 953ffaa to 6467da4 Compare March 8, 2026 16:43
@archi3103 archi3103 force-pushed the feat-summary-dict-return branch from 6467da4 to 4c09a49 Compare March 8, 2026 16:47
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.

how to get per feature value of EDoF from the result of gam.summary() to save in the txt file?

1 participant