Skip to content

Commit

Permalink
Added test for match utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Alek050 committed Apr 17, 2024
1 parent 018a9bb commit 91abb06
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
7 changes: 4 additions & 3 deletions databallpy/utils/match_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pandas as pd

from databallpy.events import BaseOnBallEvent
from databallpy.events import DribbleEvent, PassEvent, ShotEvent


def player_column_id_to_full_name(
Expand Down Expand Up @@ -51,12 +51,13 @@ def player_id_to_column_id(


def create_event_attributes_dataframe(
events: dict[str | int, BaseOnBallEvent]
events: dict[str | int, ShotEvent | PassEvent | DribbleEvent]
) -> pd.DataFrame:
"""Function to create a DataFrame from a dictionary of events
Args:
events (dict[str | int, BaseOnBallEvent]): The dictionary of events
events (dict[str | int, ShotEvent | PassEvent | DribbleEvent]):
The dictionary of events
Returns:
pd.DataFrame: DataFrame with the attributes of the events
Expand Down
27 changes: 27 additions & 0 deletions tests/utils/test_match_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import unittest
from dataclasses import dataclass

import pandas as pd

from databallpy.utils.match_utils import (
create_event_attributes_dataframe,
player_column_id_to_full_name,
player_id_to_column_id,
)
Expand Down Expand Up @@ -49,3 +51,28 @@ def test_player_id_to_column_id(self):

with self.assertRaises(ValueError):
player_id_to_column_id(self.home_players, self.away_players, 999)

def test_create_event_attributes_dataframe(self):
@dataclass
class Event:
event_id: int
event_type: str
event_team: str

@property
def df_attributes(self):
return ["event_id", "event_type", "event_team"]

events = {
1: Event(1, "pass", "home"),
2: Event(2, "shot", "away"),
}
df = create_event_attributes_dataframe(events)
expected_df = pd.DataFrame(
{
"event_id": [1, 2],
"event_type": ["pass", "shot"],
"event_team": ["home", "away"],
}
)
pd.testing.assert_frame_equal(df, expected_df)

0 comments on commit 91abb06

Please sign in to comment.