Skip to content

Accept numpy/int scalar temperatures in Mixture.calc_property - #162

Closed
djkees wants to merge 1 commit into
nasa:mainfrom
djkees:up/accept-numpy-int-scalar-temperature
Closed

djkees wants to merge 1 commit into
nasa:mainfrom
djkees:up/accept-numpy-int-scalar-temperature

Conversation

@djkees

@djkees djkees commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Mixture.calc_property's temperature argument dispatch only recognized Python float as a scalar temperature. NumPy floating scalars (e.g. np.float32, which does not subclass float) fell through to the method's else branch and raised a spurious ValueError, even though such a value arises naturally from indexing into a float array (arr[0]). Plain Python int was rejected for the same reason.

Changes

  • source/bind/python/CEA.pyx: both scalar-dispatch checks in Mixture.calc_property (the pressure-dependent and pressure-independent branches) widened from isinstance(temperature, float) to isinstance(temperature, (float, int, np.floating)). Plain NumPy integer scalars (np.int64, etc.) remain deliberately rejected.
  • source/bind/python/tests/test_mixture.py: 5 new tests covering the dispatch boundary — numpy scalar (float32/float64) accepted and matching the float result, plain Python int accepted and matching the float result, numpy integer scalar still rejected, and an invalid type (string) still rejected.

Testing

  • make py-rebuild
  • pytest source/bind/python/tests -v — 118 passed
  • Manually reproduced the original repro (np.float32 scalar temperature); confirms it now returns a result instead of raising ValueError

Compatibility / Numerical behavior

  • No expected changes to numerical results

Only the type-dispatch logic changed — no change to what value is ultimately passed into the Fortran solver for any input that was already accepted.


Drafted with Claude's assistance

  • Confirmed the original bug empirically (isinstance(np.float32(3.0), float) is False while isinstance(np.float64(3.0), float) is True on this platform, explaining why only some numpy scalar dtypes triggered it) before writing the fix.
  • Ran the full Python test suite after rebuilding the extension (make py-rebuild) against this branch's upstream/main base and confirmed all 118 tests pass, including the 5 new ones added for this fix.

🤖 Generated with Claude Code

Widens the temperature-type dispatch to accept np.floating scalars
and plain Python int, not just Python float, so values like arr[0]
from a float32/float64 array no longer raise a spurious ValueError.

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
@djkees

djkees commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #163, which combines this fix with #161's into one PR since both touch the same code region.

@djkees djkees closed this Sep 17, 2026
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