Skip to content

Remove numpy<2.4 pin now that pytensor fix is released#781

Merged
drbenvincent merged 12 commits intomainfrom
issue-723-pytensor-2-38-1
Apr 16, 2026
Merged

Remove numpy<2.4 pin now that pytensor fix is released#781
drbenvincent merged 12 commits intomainfrom
issue-723-pytensor-2-38-1

Conversation

@drbenvincent
Copy link
Copy Markdown
Collaborator

@drbenvincent drbenvincent commented Mar 4, 2026

Summary

  • remove the temporary numpy<2.4 upper bound and require pytensor>=2.38.1, now that the upstream NumPy 2.4 compatibility fix is available
  • keep environment.yml aligned with pyproject.toml for these dependency requirements
  • fix downstream runtime breakages triggered by NumPy 2.4 stricter scalar conversion in reporting and plotting code paths
  • make scalar extraction more robust by converting scalar-like xarray outputs at API boundaries (instead of relying on fragile array-to-float coercion)
  • add regression coverage for singleton-dimension xarray cases to prevent reintroducing these failures

Why this change

  • the dependency pin can now be removed safely because PyTensor has shipped the needed compatibility fix
  • once the pin is removed, CI and notebook execution exposed shape-related scalar conversion failures (TypeError: only 0-dimensional arrays can be converted to Python scalars)
  • this PR addresses both parts together: dependency unpinning and hardening call sites so behavior remains stable on newer NumPy versions

Files changed

  • pyproject.toml
  • environment.yml
  • causalpy/reporting.py
  • causalpy/experiments/diff_in_diff.py
  • causalpy/tests/test_reporting.py

Test plan

  • $CONDA_EXE run -n CausalPy prek run --all-files
  • $CONDA_EXE run -n CausalPy pytest causalpy/tests/test_reporting.py -q --no-cov
  • $CONDA_EXE run -n CausalPy pytest causalpy/tests/test_integration_skl_examples.py::test_did causalpy/tests/test_integration_pymc_examples.py::test_did -q --no-cov

Fixes #723.

@github-actions github-actions bot added the devops DevOps related label Mar 4, 2026
@read-the-docs-community
Copy link
Copy Markdown

read-the-docs-community bot commented Mar 4, 2026

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.42%. Comparing base (cd89079) to head (6ad54f3).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #781      +/-   ##
==========================================
+ Coverage   94.26%   94.42%   +0.15%     
==========================================
  Files          78       78              
  Lines       12005    12061      +56     
  Branches      699      699              
==========================================
+ Hits        11317    11389      +72     
+ Misses        496      484      -12     
+ Partials      192      188       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Require pytensor>=2.38.1 so installs include the einsum compatibility fix for numpy 2.4+ tracked in issue #723.

Made-with: Cursor
Normalize singleton xarray/numpy values before float conversion in reporting stats so summary generation and notebook rendering no longer fail under newer NumPy behavior.

Made-with: Cursor
Convert singleton array outputs to scalars before passing annotation coordinates to Matplotlib so notebook rendering works with NumPy 2.4+.

Made-with: Cursor
Keep singleton-to-scalar normalization in scalar effect summary paths while leaving the time-series summary code unchanged to avoid unnecessary patch-scope churn.

Made-with: Cursor
Use compact singleton-array to scalar coercion helpers in reporting and DiD plotting paths so NumPy 2.4 compatibility stays intact while reducing uncovered patch lines.

Made-with: Cursor
Route xarray-derived scalar outputs through the shared coercion helper in time-series summaries and add regression tests for singleton-dimension paths to keep NumPy 2.4+ compatible behavior stable.

Made-with: Cursor
@drbenvincent drbenvincent force-pushed the issue-723-pytensor-2-38-1 branch from 3f0cc2a to f85954e Compare March 4, 2026 13:39
@drbenvincent drbenvincent requested a review from juanitorduz March 4, 2026 13:42
Avoid unnecessary .values conversion in reporting paths and extend singleton scalar tests so NumPy 2.4+ behavior is handled at clear output boundaries.

Made-with: Cursor
Cover DataArray HDI and OLS xarray extraction branches in reporting helpers so patch coverage reflects the NumPy-compatibility paths exercised in CI.

Made-with: Cursor
Comment thread causalpy/reporting.py Outdated
Move the scalar-conversion helper to causalpy.utils so both
reporting.py and diff_in_diff.py share a single implementation,
as suggested in PR review.

Made-with: Cursor
@drbenvincent
Copy link
Copy Markdown
Collaborator Author

bugbot review

@cursor
Copy link
Copy Markdown

cursor bot commented Mar 11, 2026

PR Summary

Medium Risk
Removes a dependency upper bound and touches core reporting/plotting numeric extraction paths; risk is mainly runtime regressions from changed array→scalar handling across xarray/numpy shapes.

Overview
Unpins NumPy (removes numpy<2.4) and bumps the minimum pytensor to >=2.38.1 in both pyproject.toml and environment.yml to support newer NumPy releases.

Hardens reporting and DiD plotting against NumPy 2.4’s stricter scalar conversion by introducing utils._as_scalar and using it across HDI/tail/ROPE/stat summary computations and annotation coordinates, plus safer np.asarray(...) conversions for OLS xarray branches.

Adds regression tests covering singleton-array/DataArray scalar extraction, singleton treated_units dims surviving reductions, HDI DataArray return paths, and OLS xarray window/counterfactual extraction conversions.

Written by Cursor Bugbot for commit f812477. This will update automatically on new commits. Configure here.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Comment thread pyproject.toml
Convert remaining float(x.values) patterns to _as_scalar() in
interrupted_time_series.py and piecewise_its.py for consistency with the
hardening already applied to reporting.py and diff_in_diff.py.

Made-with: Cursor
@drbenvincent
Copy link
Copy Markdown
Collaborator Author

All review feedback and the Bugbot suggestion have been addressed. Just needs green CI on the latest commit (6b1bec5) and Juan's re-approval to unblock merge.

@drbenvincent drbenvincent requested a review from juanitorduz April 1, 2026 09:47
@drbenvincent drbenvincent requested a review from ricardoV94 April 15, 2026 18:24
@drbenvincent drbenvincent dismissed juanitorduz’s stale review April 16, 2026 08:23

I already addressed the changes

@drbenvincent drbenvincent merged commit 78ec91d into main Apr 16, 2026
15 checks passed
@drbenvincent drbenvincent deleted the issue-723-pytensor-2-38-1 branch April 16, 2026 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devops DevOps related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove numpy<2.4 pin once pytensor fixes numpy 2.4 compatibility

3 participants