Repository navigation
refactor!: return result keys as columns on a RangeIndex - #639
Conversation
|
Claude finished @murray-ds's task in 22s —— View job Review of #639: result keys as columns on a RangeIndexThe change is consistent across modules. Net code is smaller (the diff removes helpers and constants), the breaking changes are documented, and the tests assert against full expected frames. I read the analysis, plots and segmentation source diffs. I didn't run the test suite or the integration backends. No blocking issues. The points below are minor. Suggestions
Positives
DocsThe |
🚀 Cloudflare Pages Deployment✅ Preview deployed successfully! Preview URL: https://d4ba09a4.pyretailscience-docs.pages.dev This preview will be updated automatically when you push new changes to this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests.
... and 6 files with indirect coverage changes 🚀 New features to boost your workflow:
|
Every analysis and segmentation result now carries customer_id, group_col and other key columns as ordinary columns instead of the index, so results merge on="customer_id". heatmap.plot and cohort.plot take a y_col naming the row-label column. Also inlines a few private helpers and constants that cost more lines than they saved, and sorts the customer frames in the query. Closes #488 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014D9DLjMrprSVmrij28jv39
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014D9DLjMrprSVmrij28jv39
dict(zip(customer_id, segment_name)) collapsed duplicate customers and ignored the per-period value columns, so compare whole frames instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014D9DLjMrprSVmrij28jv39
82813a2 to
f9db574
Compare
Closes #488
Every analysis and segmentation result returns its key and grouping columns as ordinary columns on a default RangeIndex. Nothing is keyed by the index any more, so results join with
merge(..., on="customer_id"), and the plots that need row labels take ay_colnaming that column.Breaking changes
PurchasesPerCustomer.df,DaysBetweenPurchases.dfcustomer_id, sorted by itTransactionChurn.dftransaction_number, sorted by itRFMSegmentation.df,ThresholdSegmentation.df,HMLSegmentation.df,NLRSegmentation.dfcustomer_id, thengroup_colwhen givenCrossShop.cross_shop_dfgroup_col(first column)GainLoss.gain_loss_dfgroup_colwhen given, thencustomer_idGainLoss.gain_loss_table_dfgroup_colcolumn when groupedRevenueTree.dfgroup_colcolumnsCohortAnalysis.dfmin_period_shopped, then one column per periodCode that used
right_index=True,.loc[customer_id]or.indexon these frames needs to merge on, filter by or read the column instead.Three changes need a line of their own in the release notes:
calc_tree_kpistakesgroup_coland pairs rows across periods on it. Withoutgroup_col, each frame must hold one row, and rows are paired by position. A caller who relied on index labels to keep two stores apart now gets one combined row with no error, so passgroup_col.CrossShopcounting customers: withvalue_col="customer_id", agg_func="nunique", the count column is namedcustomer_id_nuniquein both frames, sincecustomer_idis now the key column.cohort.plotdefaults toy_col="min_period_shopped", soCohortAnalysis.dfplots as is. A hand-built matrix with the cohorts in the index needsy_col=None.heatmap.plotdefaults toy_col=None(the index) and raises aTypeErrornaming the non-numeric column, with a hint to passy_col.Other changes
GainLosswith a categoricalgroup_colno longer gives all-zero rows for unused categories.order_byin the query._TRANSACTION_NUMBER_COL,_GROUPING_FLAG_PREFIX,CrossShop._generate_default_labels,line._generate_colors,graph_utils._hatches_gen,bar._get_bar_value), and a no-opreset_indexinProductAssociation.dfis gone.docs/analysis_modules.md, its SVG script and the affected notebooks follow the new shape. The notebooks were re-executed.Tests
Tests for every result above compare against expected frames with the key columns as columns. New tests cover the
CrossShopname clash, grouped and ungroupedGainLosstables and plot labels, unused categories,calc_tree_kpispairing and its errors, andheatmap/cohorty_col. The full suite passes locally (1711) andmkdocs build --strictpassed. The integration backends weren't run locally.Not in this PR
GainLosswith agroup_colnamed like an output column (e.g."new") fails.GainLossbuilds a stores × customers intermediate frame, about 5 s per step at 200 stores and 100K customers. This predates the change.🤖 Generated with Claude Code
https://claude.ai/code/session_014D9DLjMrprSVmrij28jv39