Skip to content

feat: parity with R moderndive PR #144 (glm, multi-cor, 3D, View)#14

Merged
ismayc merged 3 commits into
mainfrom
feat/pr144-parity
Jun 20, 2026
Merged

feat: parity with R moderndive PR #144 (glm, multi-cor, 3D, View)#14
ismayc merged 3 commits into
mainfrom
feat/pr144-parity

Conversation

@ismayc

@ismayc ismayc commented Jun 20, 2026

Copy link
Copy Markdown
Member

Brings the Python port up to R moderndive master, matching moderndive/moderndive#144 ("Resolving outstanding issues"). Implements all five gaps identified vs. that PR.

What's new

  1. get_correlation() — multiple predictors. "y ~ x1 + x2 + x3" returns one correlation per predictor (long by default; wide=True for one column each). A suppressible note (quiet=True) points to a full pairwise matrix. Single-predictor behavior is unchanged.
  2. glm() support in get_regression_table/points/summaries. GLM points are on the response scale (e.g. probabilities for logistic); summaries are GLM-shaped (deviance, null_deviance, aic, bic, log_lik, df_residual, df_null, nobs); get_regression_table() gains exponentiate= for odds/rate ratios.
  3. In-formula transformation handling in get_regression_points(). A transformed outcome (np.log(mpg)) is shown on the model scale as log_mpg/log_mpg_hat; transformed predictors (poly(), scale(), I()) show their original columns instead of leaking basis matrices.
  4. plot_3d_regression(data, "z ~ x + y") — interactive 3D scatter with a fitted regression plane (plotly), with validation + friendly errors.
  5. View() — interactive, searchable table via the optional itables package (the Python counterpart of R's DT::datatable()), with a graceful fallback when itables isn't installed. New optional view extra.

Plus: geom_categorical_model() alias confirmed, and a new moderndive/_messaging.py giving beginner-friendly, infer-style messages/errors (a summary line + hint bullets); informational notes use a suppressible ModernDiveMessage category and are used throughout the new code.

Quality

  • New tests/test_pr144_parity.py covers all five features + edge cases (errors, pandas input, transformed LHS/RHS, GLM response-scale residuals, exponentiate, quiet/wide, View fallback) and the messaging helpers.
  • 241 tests, 100% coverage, ruff check + format clean, docs build warning-free under -W (15 rendered plots incl. the new 3D one).

Notes

  • plotly is already a core dep, so plot_3d_regression needs nothing extra.
  • itables is optional (pip install "moderndive[view]") to keep the core light and Pyodide-friendly; also added to the doc extra so the docs can show View().

🤖 Generated with Claude Code

ismayc and others added 3 commits June 20, 2026 09:32
Bring the Python port up to the R moderndive master (PR #144 "Resolving
outstanding issues"):

- get_correlation(): multiple RHS predictors -> long output by default, wide=True
  for one column per predictor; suppressible (quiet=True) note about a full
  pairwise matrix. Single-predictor behavior unchanged.
- get_regression_table/points/summaries(): accept fitted glm() models. GLM points
  are on the response scale (e.g. probabilities); summaries are glm-shaped
  (deviance, null_deviance, aic, bic, log_lik, df_residual, df_null, nobs);
  get_regression_table() gains exponentiate= for odds/rate ratios.
- get_regression_points(): in-formula transformation handling — transformed
  outcome (np.log(mpg) -> log_mpg/log_mpg_hat) shown on the model scale, and
  transformed predictors (poly/scale/I) shown as their original columns rather
  than leaking basis matrices. Now requires a formula-API model (clear error).
- plot_3d_regression(data, "z ~ x + y"): interactive 3D scatter + fitted plane
  (plotly), with validation and beginner-friendly errors.
- View(): interactive searchable table via the optional itables package
  (Python counterpart of R DT::datatable), graceful fallback without it.
  New optional `view` extra.
- geom_categorical_model() alias of gg_categorical_model() (already present).
- New moderndive/_messaging.py: infer-style messages/errors (summary + → hints);
  informational notes use a suppressible ModernDiveMessage warning category, used
  across the new code.

Docs: API reference, regression guide (multi-cor, glm, 3D), getting-started
(View) updated; CHANGELOG. Tests: new tests/test_pr144_parity.py covering all
five features + edge cases + messaging. 241 tests, 100% coverage, ruff clean,
docs build warning-free under -W.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017CTL1QSTg1DmDUpqYuPEog
- get_regression_table/points/summaries() now also accept array-API fits
  (sm.OLS(y, X).fit() / sm.GLM(...)), not just the formula API. Term names fall
  back to exog_names when params is a bare numpy array; points are built from the
  endog/exog arrays (constant column dropped), with the same GLM response-scale
  handling. Formula-API transform handling is unchanged.
- New docs guide guides/messages.md: shows the beginner-friendly, infer-style
  messages/errors (summary + → hints) with executed output, and how to silence
  the informational ModernDiveMessage notes (quiet= / warnings filter).
- Tests cover numpy + pandas array-API OLS and GLM paths.

242 tests, 100% coverage, ruff clean, docs build warning-free under -W.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017CTL1QSTg1DmDUpqYuPEog
CI installs only the test extra (no itables), so the View render-path tests took
the fallback branch and failed. Force _itables_available() in those tests and add
a direct test of the real detector, so the suite passes (and stays at 100%
coverage) whether or not the optional itables dependency is present.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017CTL1QSTg1DmDUpqYuPEog
@ismayc ismayc merged commit 22fceaf into main Jun 20, 2026
6 checks passed
@ismayc ismayc deleted the feat/pr144-parity branch June 20, 2026 16:58
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