Skip to content

fix(docs): cast strata to str before replace in Oregon tutorial#116

Merged
TomeHirata merged 1 commit into
mainfrom
fix/oregon-strata-astype-str
Jun 26, 2026
Merged

fix(docs): cast strata to str before replace in Oregon tutorial#116
TomeHirata merged 1 commit into
mainfrom
fix/oregon-strata-astype-str

Conversation

@okiner-3

Copy link
Copy Markdown
Collaborator

Summary

The Oregon tutorial's preprocessing step calls .replace() directly on the strata column (renamed from numhh_list). Since numhh_list is a pandas categorical column, mapping its values to 'signed self up + others' (a category that does not exist) raises a type error.

This adds .astype(str) before .replace() so the column is converted to a string type first, avoiding the error.

Changes

df['strata'] = df['strata'].astype(str).replace({
    'signed self up + 1 additional person': 'signed self up + others',
    'signed self up + 2 additional people': 'signed self up + others'
})

numhh_list is a categorical column, so calling .replace() to map values
to a category that does not exist raises a type error. Convert to str
before .replace() to avoid this.
@okiner-3 okiner-3 self-assigned this Jun 19, 2026
@okiner-3 okiner-3 requested a review from TomeHirata June 19, 2026 14:25

@TomeHirata TomeHirata left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@TomeHirata TomeHirata merged commit 043ad8b into main Jun 26, 2026
10 checks passed
@TomeHirata TomeHirata deleted the fix/oregon-strata-astype-str branch June 26, 2026 13:53
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