From d167a9350c4b97b7de1d7a73d4cb925ec605d884 Mon Sep 17 00:00:00 2001 From: Philipp Verpoort Date: Wed, 21 Aug 2024 09:38:26 +0100 Subject: [PATCH] Bugfix in team.explode method. (#22) There was a bug in the .team.explode() method, which cause the function to get caught in an endless loop. This is now fixed. --- python/posted/team.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/python/posted/team.py b/python/posted/team.py index 738d7ac..1972810 100644 --- a/python/posted/team.py +++ b/python/posted/team.py @@ -139,12 +139,15 @@ def explode(self, if isinstance(fields, str) else fields ) for field in fields: - df = df \ - .assign(**{field: lambda df: df[field].apply( - lambda cell: df[field].dropna().unique().tolist() - if pd.isnull(cell) else cell - )}) \ + explodable = pd.Series( + index=df.index, + data=len(df)*[df[field].dropna().unique().tolist()], + ) + df = ( + df + .assign(**{field: df[field].fillna(explodable)}) .explode(field) + ) return df.reset_index(drop=True)