Skip to content

Fix dtype promotion in selection arithmetic - #2287

Open
sixty-66 wants to merge 1 commit into
prody:mainfrom
sixty-66:fix/selection-arithmetic-promotion
Open

sixty-66 wants to merge 1 commit into
prody:mainfrom
sixty-66:fix/selection-arithmetic-promotion

Conversation

@sixty-66

Copy link
Copy Markdown

Integer-valued atom properties such as resnum raise a NumPy output-casting error in selections like resnum - 0.5 > 1 or resnum / 2 > 1. The binary-operation evaluator writes the result into its integer left-hand array, which cannot hold the floating-point result.

Keep the existing in-place operation when it succeeds, and retry without an output array when NumPy raises TypeError. This permits NumPy's normal dtype promotion while preserving integer arithmetic and the existing in-place path. Add regression coverage for arithmetic operators, scalar and array operands, chained expressions, precedence, unchanged atom data, and integer precision above 2**53.

Refs #2142. This addresses the arithmetic casting error; the separate negative-residue selection concern in that issue is outside this change.

Validation on Windows 11, Python 3.12.12, NumPy 2.5.4, SciPy 1.18.1, pyparsing 3.1.1, and Biopython 1.88:

  • python -m pytest prody/tests/atomic/test_select.py -p no:cacheprovider -q -k 'ArithmeticPromotion or IntegerArithmeticPrecision': 2 passed, 16 subtests passed. Before the fix, 10 arithmetic subcases failed with NumPy output-casting errors.
  • python -m pytest prody/tests/atomic/test_atomic.py prody/tests/atomic/test_subset.py -p no:cacheprovider -q: 10 passed.
  • Full selection module: 522 passed, 26 failed, 16 subtests passed. All 26 failures also occur with the upstream arithmetic method: the Biopython KDTree fallback lacks search_center_radius. Native ProDy extensions could not be built locally because the Microsoft C++ compiler is unavailable.
  • git diff --check: passed.

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