Conversation
emarx
approved these changes
Dec 24, 2023
Comment on lines
+119
to
+136
| @offline(tags="batch-most-recent-revenue") | ||
| def batch_most_recent_revenue( | ||
| records: DataFrame[RApplication.id, RApplication.records, Now] | ||
| ) -> DataFrame[RApplication.id, RApplication.most_recent_revenue]: | ||
| df: pl.LazyFrame = records.to_polars() | ||
|
|
||
| exploded = df.explode(pl.col(str(RApplication.records))).unnest(str(RApplication.records)) | ||
|
|
||
| time_consistent = exploded.filter(pl.col(str(RQuickbooksRecord.created_at)) <= pl.col(str(Now))) | ||
|
|
||
| most_recent_rev_output = ( | ||
| time_consistent.sort(by=str(RQuickbooksRecord.created_at), descending=True) | ||
| .groupby(str(RApplication.id), str(Now), maintain_order=True) | ||
| .agg(pl.first(str(RQuickbooksRecord.revenue)).alias(str(RApplication.most_recent_revenue))) | ||
| .select(str(RApplication.id), str(RApplication.most_recent_revenue)) | ||
| ) | ||
|
|
||
| return most_recent_rev_output |
There was a problem hiding this comment.
The output DataFrame should include all input application IDs, even when no records exist for an application. Consider using a right join with the input IDs and defaulting most_recent_revenue to 0 for applications without records. This ensures the output maintains the same cardinality as the input.
Spotted by Graphite Reviewer
Is this helpful? React 👍 or 👎 to let us know.
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.
No description provided.