Skip to content

Commit

Permalink
address copy-on-write-related warnings
Browse files Browse the repository at this point in the history
pandas is moving to a copy-on-write model.

From their guide:

> CoW means that any DataFrame or Series derived from another in any way always behaves as a copy. As a consequence, we can only change the values of an object through modifying the object itself.

Thus, `new_teams["trb"].fillna(0, inplace=True)` would not work with CoW (trb would be filled with zeroes only in a copy, not in the original `new_teams` dataframe).

This can be addressed by using a slightly different syntax for in-place updates.

Migration guide: https://pandas.pydata.org/docs/dev/user_guide/copy_on_write.html#copy-on-write-migration-guide
  • Loading branch information
razumau committed Jul 14, 2024
1 parent 9e2361e commit 366c7ca
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions scripts/teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ def add_new_teams(self, tournament: Tournament, player_rating: PlayerRating):
new_teams["trb"] = new_teams.baseTeamMembers.map(
lambda x: player_rating.calc_rt(x, self.q)
)
new_teams["trb"].fillna(0, inplace=True)
new_teams.fillna({"trb": 0}, inplace=True)
new_teams["rating"] = new_teams["trb"] * NEW_TEAMS_LOWERING_COEFFICIENT
new_teams["prev_rating"] = None
new_teams["prev_place"] = None
self.data = pd.concat([self.data, new_teams.drop("baseTeamMembers", axis=1)])

def calc_trb(self, player_rating: PlayerRating):
self.data["trb"] = player_rating.calc_tech_rating_all_teams(q=self.q)
self.data["trb"].fillna(0, inplace=True)
self.data.fillna({"trb": 0}, inplace=True)

0 comments on commit 366c7ca

Please sign in to comment.