Skip to content

Fixing #1047#1061

Open
GregoryAshton wants to merge 1 commit intomainfrom
1047-fix-numpy-incompatibility
Open

Fixing #1047#1061
GregoryAshton wants to merge 1 commit intomainfrom
1047-fix-numpy-incompatibility

Conversation

@GregoryAshton
Copy link
Copy Markdown
Collaborator

Issue

GitHub #1047

sample_subset_constrained raised a TypeError when sampling with size=None or size=1:

TypeError: only 0-dimensional arrays can be converted to Python scalars

Root Cause

evaluate_constraints returns a numpy array via np.ones_like. When sampling a single point, this is a 1-element array rather than a scalar. The subsequent int(is_valid) call on line 464 fails because int() only accepts 0-dimensional arrays.

Fix

Wrap is_valid with np.squeeze before converting to int, reducing the 1-element array to a 0-d scalar:

# before
n_valid_samples += int(is_valid)

# after
n_valid_samples += int(np.squeeze(is_valid))

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.23%. Comparing base (0985f75) to head (61d5159).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1061   +/-   ##
=======================================
  Coverage   66.23%   66.23%           
=======================================
  Files          89       89           
  Lines       17064    17064           
  Branches     2642     2642           
=======================================
  Hits        11303    11303           
  Misses       5021     5021           
  Partials      740      740           
Flag Coverage Δ
python310 66.05% <100.00%> (+0.01%) ⬆️
python311 66.19% <100.00%> (-0.05%) ⬇️
python312 66.20% <100.00%> (ø)
python313 66.20% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

Squeeze the output to one-dimension to fix incompatibility with numpy >
2.4
@ColmTalbot ColmTalbot force-pushed the 1047-fix-numpy-incompatibility branch from 61d5159 to 4071122 Compare March 25, 2026 18:37
@ColmTalbot
Copy link
Copy Markdown
Collaborator

I thought we had fixed this already...

@GregoryAshton
Copy link
Copy Markdown
Collaborator Author

My apologies @ColmTalbot I may have missed your MR that fixed it. If that is the case, please do close this

@mj-will mj-will added the bug Something isn't working label Apr 2, 2026
@mj-will mj-will requested a review from a team April 2, 2026 15:48
@mj-will
Copy link
Copy Markdown
Collaborator

mj-will commented Apr 2, 2026

Agreed on the call we would backport this to 2.7.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants