[ENH] unit tests for gen_imgs.py#396
Conversation
gen_imgs.pygen_imgs.py
fkiraly
left a comment
There was a problem hiding this comment.
Great, thanks!
Very quickly before I review: the file has conflicts with the file on main, and is not passing code formatting checks. Please ensure you have checked with pre-commit.
|
Hey @fkiraly, Thanks for the feedback. |
fkiraly
left a comment
There was a problem hiding this comment.
Great! @dswah might like to review if this makes sense logic-wise.
Regarding folder structure, I think this might not exactly work - and it will have a broken import inside the package, since the root files are not packaged.
Could you put the test outside the package and ensure it is run there?
|
@fkiraly do you see anything missing? |
- Moved test file from pygam/tests/ to tests/ to align with gen_imgs.py being in root - Verified pytest auto-discovers and runs tests from new location - All 13 tests pass successfully - Addresses maintainer feedback on folder structure
|
@dswah thanks for the feedback. |
fkiraly
left a comment
There was a problem hiding this comment.
No, all good from my side!
We only added |
Add Unit Tests for gen_imgs.py (Closes #387)
Summary
This PR addresses Issue #387 by adding comprehensive unit test coverage for the
gen_imgs.pymodule, which generates visualization plots for pyGAM documentation.Changes Made
Bug Fixes
gen_imgs.py:gam.generate_X_grid()calls to include requiredtermparametergam.partial_dependence()calls to use correcttermandXargumentsgam.lamto handle nested arrays/listsNew Tests
test_gen_imgs.pywith unit tests for all plotting functions:test_gen_basis_fns()- Tests basis function visualizationtest_cake_data_in_one()- Tests cake data plottingtest_faithful_data_poisson()- Tests faithful data with Poisson distributiontest_single_data_linear()- Tests single data linear modeltest_mcycle_data_linear()- Tests motorcycle data (2 plots)test_wage_data_linear()- Tests wage data visualizationtest_default_data_logistic()- Tests logistic regressiontest_constraints()- Tests constraint visualizationtest_trees_data_custom()- Tests custom tree datatest_gen_multi_data()- Tests multi-data generation (2 plots)test_gen_tensor_data()- Tests tensor data visualizationtest_chicago_tensor()- Tests Chicago tensor datatest_expectiles()- Tests expectile regressionTesting Strategy
mock.patchto isolateplt.savefigcallsTest Results
Files Changed
pyGAM/gen_imgs.py- API compatibility fixespyGAM/pygam/tests/test_gen_imgs.py- New test file (created)Why This Approach?
from mock import patchlike other test filesRelated Issue
Closes #387 - "Add test coverage for gen_imgs.py"
Note: The API fixes in
gen_imgs.pywere necessary because the script was using outdated pyGAM method signatures. These fixes ensure the script works with the current pyGAM version while maintaining backward compatibility.