-
Notifications
You must be signed in to change notification settings - Fork 28
add dim_reduce to aggregates, refactor patch utils #456
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #456 +/- ##
========================================
Coverage 99.84% 99.85%
========================================
Files 114 115 +1
Lines 9258 9372 +114
========================================
+ Hits 9244 9358 +114
Misses 14 14
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
dascore/proc/aggregate.py
Outdated
| dim_reduce | ||
| How to reduce the dimensional coordinate associated with the | ||
| aggregated axis. Can be the name of any valid aggregator, a callable, | ||
| "empty" - which returns and empty coord, or "squeeze" which drops |
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.
It would be helpful to note that "empty" is the default behavior.
| dim_reduce: str | Callable = "empty", | ||
| ) -> PatchType: | ||
| """ | ||
| Aggregate values along a specified dimension. |
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.
The notes section in the docs should be revised based on the new dim_reduce argument.
| is found in args, its corresponding values is `None`. | ||
| Return the name of the dimension, its axis position, and its value. | ||
| Examples |
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.
Thanks for including these examples in the docs. Super helpful as this function is being used in a lot of other functions.
ahmadtourei
left a comment
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.
Looks great! Please see my comments on a couple of suggestions.
Description
This PR does 3 sorta related things:
Adds a
dim_reducekeyword toPatch.aggregateand friends (eg mean, min, max) which controls what happens to the aggregated dimension. Options now are to apply another numpy-like reducer, squeeze out the dimension, or empty it. The default behavior is unchanged, but the additional options are useful when calculating stats over patches in a spool.Unified getting dimension name, axis, and values from args and kwargs into one new function
dascore.utils.patch.get_dim_axis_valueand replaced usages of two overlapping functions that did this before.Added a
validate_calloption topatch_functionwhich uses pydantic's validate_call decorator to do type checking on patch functions when enabled. This makes it much easier to enforce certain types and ranges on patch function parameters.Checklist
I have (if applicable):