Skip to content

fix: accept numpy integer types as Parachute trigger - #1116

Open
abhi-0203 wants to merge 1 commit into
RocketPy-Team:developfrom
abhi-0203:fix/numpy-integer-trigger
Open

fix: accept numpy integer types as Parachute trigger#1116
abhi-0203 wants to merge 1 commit into
RocketPy-Team:developfrom
abhi-0203:fix/numpy-integer-trigger

Conversation

@abhi-0203

Copy link
Copy Markdown

Summary

Replace isinstance(trigger, (int, float)) with isinstance(trigger, Real) and not isinstance(trigger, bool) in Parachute.__init__().

numpy.int64 and numpy.int32 don't subclass Python's int or float, so they were rejected with a ValueError even though they represent valid numeric altitude values. numbers.Real covers all numeric types (int, float, numpy scalars).

Also excludes bool — currently trigger=True is silently accepted as a 1m height, which is never intentional.

Changes

  • rocketpy/rocket/parachute.py: Import Real from numbers, replace isinstance(trigger, (int, float)) with isinstance(trigger, Real) and not isinstance(trigger, bool)

Test plan

  • int 800 → accepted ✓
  • float 800.0 → accepted ✓
  • np.float64(800) → accepted ✓
  • np.int64(800) → accepted ✓
  • np.int32(800) → accepted ✓
  • True / False → rejected ✓ (was previously accepted as height 1m)

AST verified: no old pattern remains, import confirmed.

Closes #1106

isinstance(trigger, (int, float)) rejects numpy integer types
(np.int64, np.int32) because they don't subclass Python's int or float.
Replace with isinstance(trigger, numbers.Real) which covers all numeric
types (int, float, numpy scalars) while excluding bool.

Fixes RocketPy-Team#1106
@abhi-0203
abhi-0203 requested a review from a team as a code owner August 9, 2026 04:32

@Gui-FernandesBR Gui-FernandesBR left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I suggest using "NUMERICAL_TYPES" constant from the Function module

@ting-hong-shieh

Copy link
Copy Markdown

I exercised the trigger-type boundary on head e3d2f0fe7c583f3a632d9643dca98b071c60b79f:

Trigger type Result
Python int, NumPy int64 accepted
Python float, NumPy float32 accepted
Python bool, NumPy bool_ rejected with ValueError
Python complex, NumPy complex64 rejected with ValueError

Using numbers.Real with the explicit bool guard gives the intended boundary. A raw NUMERICAL_TYPES check would also include complex values, and Python bool needs its own exclusion, so I would keep the current predicate even though the shared constant was suggested earlier.

Two changes still look necessary before review:

  1. The pull request targets master; the development guide says ordinary fixes should target develop.
  2. The patch has no tests. A parametrized constructor test covering the eight cases above would protect both the NumPy-integer fix and the bool/complex exclusions.

No branch changes were made. Environment: Python 3.12.6; NumPy 2.5.2; RocketPy PR head above; macOS 26.5.2 arm64.

@Gui-FernandesBR
Gui-FernandesBR changed the base branch from master to develop August 14, 2026 09:45
@Gui-FernandesBR

Copy link
Copy Markdown
Member

I understand this PR still needs some fixes.

  1. Adding unit tests
  2. Using the NUMERICAL_TYPES from the Function module

@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.37%. Comparing base (e0ff281) to head (e3d2f0f).
⚠️ Report is 58 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1116      +/-   ##
===========================================
+ Coverage    82.18%   82.37%   +0.19%     
===========================================
  Files          122      122              
  Lines        16355    16378      +23     
===========================================
+ Hits         13441    13492      +51     
+ Misses        2914     2886      -28     

☔ View full report in Codecov by Harness.
📢 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.

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.

Parachute refuses a numpy integer trigger but accepts a numpy float

3 participants