fix: accept numpy integer types as Parachute trigger - #1116
Open
abhi-0203 wants to merge 1 commit into
Open
Conversation
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
Gui-FernandesBR
left a comment
Member
There was a problem hiding this comment.
I suggest using "NUMERICAL_TYPES" constant from the Function module
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace
isinstance(trigger, (int, float))withisinstance(trigger, Real) and not isinstance(trigger, bool)inParachute.__init__().numpy.int64andnumpy.int32don't subclass Python'sintorfloat, so they were rejected with aValueErroreven though they represent valid numeric altitude values.numbers.Realcovers all numeric types (int, float, numpy scalars).Also excludes
bool— currentlytrigger=Trueis silently accepted as a 1m height, which is never intentional.Changes
rocketpy/rocket/parachute.py: ImportRealfromnumbers, replaceisinstance(trigger, (int, float))withisinstance(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