Skip to content

Refactor: centralize column constants and eliminate duplicate segment assignment#1

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/refactor-duplicated-code
Draft

Refactor: centralize column constants and eliminate duplicate segment assignment#1
Copilot wants to merge 2 commits intomainfrom
copilot/refactor-duplicated-code

Conversation

Copy link
Copy Markdown

Copilot AI commented Feb 28, 2026

Two classes of code duplication existed across the src/ modules: column name strings were hardcoded independently in both feature_engineering.py and data_preprocessing.py, and df['segment'] = labels was assigned in both generate_model.py and profiling.py.

Changes

  • New src/constants.py — single source of truth for all column names (NUMERICAL_COLS, CATEGORICAL_COLS, and individual constants like ENGAGEMENT_SCORE_COL, CTR_COL, etc.)

  • src/data_preprocessing.py — replaces inline column lists with imports from constants.py

  • src/feature_engineering.py — replaces hardcoded column string literals with named constants from constants.py

  • generate_model.py — removes duplicate df['segment'] = labels assignment; delegates to profile_segments(df, labels) which already performs it

# Before — segment assigned in two places
labels = cluster_users(X, k=4)
df['segment'] = labels          # ← duplicated; also done inside profile_segments()

# After — single assignment via existing function
labels = cluster_users(X, k=4)
profile_segments(df, labels)    # owns the df['segment'] assignment

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…signment

Co-authored-by: Sasisundar2211 <139478565+Sasisundar2211@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor duplicated code for better maintainability Refactor: centralize column constants and eliminate duplicate segment assignment Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants