-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add type annotations to ClusterSequence #87
Conversation
On the test failure:
On the PR itself: I think this is a valuable thing, if it gets past a blocker. fastjet is more easily typeable than most Awkward Array-based projects because some of these methods can only return ak.Array, not ak.Record or a scalar. In more general applications, whether a given slice returns an array or a scalar (ak.Record is a kind of scalar) depends on the type of the arguments, which is not a distinction in Python types. (As far as Python is concerned, it's a difference in values, not types.) Actually, there might be a few of these methods that, when they accept a single event (ak.Array of Momentum4D) as input, return a single number (scalar). Those cannot be annotated with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late reply, I have been busy with a lot of stuff in the past 2 months. I have commented on all the methods that have been marked as returning an Awkward Array but can return a single value (bool, int or float) if the input is a single event type.
src/fastjet/__init__.py
Outdated
@@ -295,7 +295,7 @@ def constituents(self, min_pt=0): | |||
""" | |||
raise AssertionError() | |||
|
|||
def exclusive_dmerge(self, njets=10): | |||
def exclusive_dmerge(self, njets=10) -> ak.Array: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can return a single number (single event).
src/fastjet/__init__.py
Outdated
@@ -306,7 +306,7 @@ def exclusive_dmerge(self, njets=10): | |||
""" | |||
raise AssertionError() | |||
|
|||
def exclusive_dmerge_max(self, njets=10): | |||
def exclusive_dmerge_max(self, njets=10) -> ak.Array: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same problem.
src/fastjet/__init__.py
Outdated
@@ -317,7 +317,7 @@ def exclusive_dmerge_max(self, njets=10): | |||
""" | |||
raise AssertionError() | |||
|
|||
def exclusive_ymerge_max(self, njets=10): | |||
def exclusive_ymerge_max(self, njets=10) -> ak.Array: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here as well.
src/fastjet/__init__.py
Outdated
@@ -328,7 +328,7 @@ def exclusive_ymerge_max(self, njets=10): | |||
""" | |||
raise AssertionError() | |||
|
|||
def exclusive_ymerge(self, njets=10): | |||
def exclusive_ymerge(self, njets=10) -> ak.Array: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This too.
src/fastjet/__init__.py
Outdated
@@ -339,7 +339,7 @@ def exclusive_ymerge(self, njets=10): | |||
""" | |||
raise AssertionError() | |||
|
|||
def Q(self): | |||
def Q(self) -> ak.Array: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This too.
src/fastjet/__init__.py
Outdated
@@ -422,7 +422,7 @@ def n_exclusive_subjets(self, data, dcut=0): | |||
""" | |||
raise AssertionError() | |||
|
|||
def has_parents(self, data): | |||
def has_parents(self, data) -> ak.Array: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can return a single Bool.
src/fastjet/__init__.py
Outdated
@@ -433,7 +433,7 @@ def has_parents(self, data): | |||
""" | |||
raise AssertionError() | |||
|
|||
def has_child(self, data): | |||
def has_child(self, data) -> ak.Array: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can return a single Bool.
src/fastjet/__init__.py
Outdated
@@ -444,7 +444,7 @@ def has_child(self, data): | |||
""" | |||
raise AssertionError() | |||
|
|||
def jet_scale_for_algorithm(self, data): | |||
def jet_scale_for_algorithm(self, data) -> ak.Array: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can return a single number.
src/fastjet/__init__.py
Outdated
@@ -466,7 +466,7 @@ def unique_history_order(self): | |||
""" | |||
raise AssertionError() | |||
|
|||
def n_particles(self): | |||
def n_particles(self) -> ak.Array: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This too.
src/fastjet/__init__.py
Outdated
@@ -477,7 +477,7 @@ def n_particles(self): | |||
""" | |||
raise AssertionError() | |||
|
|||
def n_exclusive_jets(self, dcut=0): | |||
def n_exclusive_jets(self, dcut=0) -> ak.Array: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This too.
This PR adds return type annotations to the ClusterSequence class, allowing code analysis tools such as pylance to understand fastjet methods. The previous behavior was that pylance read the abstract method definitions and concluded that the methods allows raised an error. This marked all code after a fastjet call as unreachable.