Skip to content

Commit

Permalink
add DeserializationWarning
Browse files Browse the repository at this point in the history
  • Loading branch information
DriesDeprest committed Dec 18, 2024
1 parent 6b4cf48 commit e71e8d9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
19 changes: 14 additions & 5 deletions kloppy/infra/serializers/event/wyscout/deserializer_v3.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import logging
import warnings
from dataclasses import replace
from datetime import timedelta, timezone
from enum import Enum
Expand Down Expand Up @@ -40,7 +41,7 @@
Team,
)
from kloppy.exceptions import DeserializationError
from kloppy.utils import performance_logging
from kloppy.utils import performance_logging, DeserializationWarning

from ..deserializer import EventDataDeserializer
from .deserializer_v2 import WyscoutInputs
Expand Down Expand Up @@ -780,6 +781,17 @@ def deserialize(self, inputs: WyscoutInputs) -> EventDataset:
str(raw_event["possession"]["team"]["id"])
]

if player_id == INVALID_PLAYER:
player = None
elif player_id not in players[team_id]:
player = None
warnings.warn(
f"Player {player_id} not listed in the team performing the event.",
DeserializationWarning,
)
else:
player = players[team_id][player_id]

generic_event_args = {
"event_id": raw_event["id"],
"raw_event": raw_event,
Expand All @@ -792,10 +804,7 @@ def deserialize(self, inputs: WyscoutInputs) -> EventDataset:
else None
),
"team": team,
"player": players[team_id][player_id]
if player_id != INVALID_PLAYER
and player_id in players[team_id]
else None,
"player": player,
"ball_owning_team": ball_owning_team,
"ball_state": None,
"period": periods[-1],
Expand Down
4 changes: 4 additions & 0 deletions kloppy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,7 @@ def __get__(self, instance, owner):
stacklevel=2,
)
return self.value


class DeserializationWarning(Warning):
pass

0 comments on commit e71e8d9

Please sign in to comment.