-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add total row to SegTransactionStats calculation #57
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
WalkthroughThe Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
PR Reviewer Guide 🔍
|
|
/describe |
TitleEnhancement: Add total row calculation and refactor segment statistics PR TypeEnhancement, Tests Description
Changes walkthrough 📝
|
PR Code Suggestions ✨
|
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- pyretailscience/segmentation.py (5 hunks)
- tests/test_segmentation.py (1 hunks)
Additional comments not posted (10)
tests/test_segmentation.py (6)
12-23: LGTM!The
base_dffixture is well-defined and provides a comprehensive DataFrame for testing.
25-40: LGTM!The test comprehensively checks multiple metrics calculated by the
_calc_seg_statsmethod and includes a 'total' row in the expected output.
42-63: LGTM!The test ensures the
_calc_seg_statsmethod works correctly without the 'quantity' column.
65-70: LGTM!The test ensures the
_calc_seg_statsmethod does not alter the original DataFrame.
72-90: LGTM!The test ensures the
_calc_seg_statsmethod works correctly with a single-segment DataFrame and includes a 'total' row in the expected output.
96-101: LGTM!The test ensures proper error handling when the DataFrame is missing a required column.
pyretailscience/segmentation.py (4)
Line range hint
35-50:
LGTM!The
ExistingSegmentationclass is well-defined and the validation logic ensures the required columns are present and non-null.
Line range hint
53-98:
LGTM!The
HMLSegmentationclass is well-defined and the segmentation logic is clear and concise.
145-189: LGTM!The
SegTransactionStatsclass is well-defined and the refactored_calc_seg_statsmethod provides detailed segment statistics. Theplotmethod update allows for more flexibility in plotting.
Line range hint
191-243:
LGTM!The
plotmethod update provides more flexibility in plotting and is well-defined.
Co-authored-by: codiumai-pr-agent-pro[bot] <151058649+codiumai-pr-agent-pro[bot]@users.noreply.github.com>
| total_aggs["total_quantity"] = [df["quantity"].sum()] | ||
|
|
||
| stats_df = pd.concat( | ||
| [ | ||
| df.groupby(segment_col).agg(**aggs), |
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.
Suggestion: Use the agg method directly with a dictionary for better readability and maintainability [Enhancement, importance: 5]
| total_aggs["total_quantity"] = [df["quantity"].sum()] | |
| stats_df = pd.concat( | |
| [ | |
| df.groupby(segment_col).agg(**aggs), | |
| stats_df = pd.concat( | |
| [ | |
| df.groupby(segment_col).agg(aggs), | |
| pd.DataFrame(total_aggs, index=["total"]), | |
| ], | |
| ) |
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- pyretailscience/segmentation.py (5 hunks)
Files skipped from review as they are similar to previous changes (1)
- pyretailscience/segmentation.py
PR Type
Enhancement, Tests
Description
SegTransactionStats._calc_seg_statsmethod.hide_totalparameter in theplotmethod to optionally hide the total row.TransactionItemLevelContractandTransactionLevelContract._calc_seg_statsmethod.Changes walkthrough 📝
segmentation.py
Add total row and refactor segment statistics calculationpyretailscience/segmentation.py
_calc_seg_statsmethod.hide_totalparameter in theplotmethod to optionallyhide the total row.
TransactionItemLevelContractandTransactionLevelContract.test_segmentation.py
Add unit tests for segment statistics calculationtests/test_segmentation.py
_calc_seg_statsmethod.per segment.
Summary by CodeRabbit
New Features
hide_totalparameter to control the visibility of the total row in plots.Bug Fixes
Tests