Skip to content

Conversation

@Nepomuk5665
Copy link

Summary

Fixed two instances where .astype() calls had no effect because the return value was discarded.

Problem

In scoring/src/scoring/note_ratings.py, the following pattern appeared in two functions:

raterModelOutput[c.raterParticipantIdKey].astype(ratings[c.raterParticipantIdKey].dtype)

Issue: In pandas, .astype() returns a new Series with the converted dtype - it does not modify the original Series in place. Since the return value was not being assigned, this code was effectively a no-op.

Affected functions:

  • get_note_counts_by_rater_sign() (line 393)
  • get_population_sampled_counts_by_rater_sign() (line 525)

Impact

This bug could cause type mismatch issues during subsequent merge operations if raterParticipantIdKey columns have different dtypes between the raterModelOutput and ratings DataFrames. The intent of the original code was clearly to ensure type compatibility before merging.

Fix

raterModelOutput = raterModelOutput.copy()
raterModelOutput[c.raterParticipantIdKey] = raterModelOutput[c.raterParticipantIdKey].astype(
  ratings[c.raterParticipantIdKey].dtype
)

The fix:

  1. Creates a defensive copy to avoid mutating the input DataFrame
  2. Properly assigns the result of .astype() back to the column

Testing

This is a straightforward bug fix that makes the existing code work as originally intended. The logic remains the same - only now the type conversion actually takes effect.

The .astype() method in pandas returns a new Series - it does not
modify in place. The previous code discarded the return value,
meaning the dtype conversion never actually happened.

This could cause type mismatch issues during merge operations if
raterParticipantIdKey columns have different dtypes between the
raterModelOutput and ratings DataFrames.

Fixed by assigning the result back to the column, with a defensive
.copy() to avoid modifying the original input DataFrame.
@CLAassistant
Copy link

CLAassistant commented Jan 23, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants