From dddb9f70fa131e898e008708ca1cfce50997180e Mon Sep 17 00:00:00 2001 From: driesdeprest Date: Wed, 18 Dec 2024 12:48:56 +0100 Subject: [PATCH] move warning and make more explicit --- kloppy/exceptions.py | 4 ++++ .../serializers/event/wyscout/deserializer_v3.py | 8 +++++--- kloppy/tests/prs/pr_358/test_pr_358.py | 14 ++++++++------ kloppy/utils.py | 4 ---- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/kloppy/exceptions.py b/kloppy/exceptions.py index c6970585..e15a3338 100644 --- a/kloppy/exceptions.py +++ b/kloppy/exceptions.py @@ -40,3 +40,7 @@ class UnknownEncoderError(KloppyError): class KloppyParameterError(KloppyError): pass + + +class DeserializationWarning(Warning): + pass diff --git a/kloppy/infra/serializers/event/wyscout/deserializer_v3.py b/kloppy/infra/serializers/event/wyscout/deserializer_v3.py index 8fa58e50..2a277eb0 100644 --- a/kloppy/infra/serializers/event/wyscout/deserializer_v3.py +++ b/kloppy/infra/serializers/event/wyscout/deserializer_v3.py @@ -40,8 +40,8 @@ TakeOnResult, Team, ) -from kloppy.exceptions import DeserializationError -from kloppy.utils import performance_logging, DeserializationWarning +from kloppy.exceptions import DeserializationError, DeserializationWarning +from kloppy.utils import performance_logging from ..deserializer import EventDataDeserializer from .deserializer_v2 import WyscoutInputs @@ -786,7 +786,9 @@ def deserialize(self, inputs: WyscoutInputs) -> EventDataset: elif player_id not in players[team_id]: player = None warnings.warn( - f"Player {player_id} not listed in the team performing the event.", + f"Event {raw_event['id']} was performed by player {player_id} and team {team_id}, " + f"but the player does not appear to be part of that team's lineup. " + f"Handled by setting the event's player to None.", DeserializationWarning, ) else: diff --git a/kloppy/tests/prs/pr_358/test_pr_358.py b/kloppy/tests/prs/pr_358/test_pr_358.py index 18ccd847..573005ab 100644 --- a/kloppy/tests/prs/pr_358/test_pr_358.py +++ b/kloppy/tests/prs/pr_358/test_pr_358.py @@ -26,14 +26,16 @@ ) from kloppy import wyscout +from kloppy.exceptions import DeserializationWarning def test_ignore_unknown_player(base_dir): - dataset = wyscout.load( - event_data=base_dir / "prs" / "pr_358" / "wyscout_events_v3.json", - coordinates="wyscout", - ) + with pytest.warns(DeserializationWarning, match="..."): + dataset = wyscout.load( + event_data=base_dir / "prs" / "pr_358" / "wyscout_events_v3.json", + coordinates="wyscout", + ) - assert len(dataset.events) == 2 + assert len(dataset.events) == 2 - assert dataset.events[1].player is None + assert dataset.events[1].player is None diff --git a/kloppy/utils.py b/kloppy/utils.py index 20a69caf..b0858398 100644 --- a/kloppy/utils.py +++ b/kloppy/utils.py @@ -169,7 +169,3 @@ def __get__(self, instance, owner): stacklevel=2, ) return self.value - - -class DeserializationWarning(Warning): - pass