Skip to content

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

Open
abhi-0203 wants to merge 1 commit into
RocketPy-Team:masterfrom
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:masterfrom
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

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

2 participants