Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[General] Fixed Undersirable "None" value for positions.last() #374

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion kloppy/domain/models/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,20 @@ def ranges(self) -> List[Tuple[Time, Time, T]]:
return ranges_

def last(self, include_time: bool = False, default=SENTINEL):
def __get_last_non_none_key(items):
for key, value in reversed(items.items()):
if value is not None:
return key
return None

if not len(self.items):
if default == SENTINEL:
raise KeyError
else:
return default

time = self.items.keys()[-1]
time = __get_last_non_none_key(self.items)

if include_time:
return time, self.items[time]
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,23 @@ def extract_events(self) -> List[OptaEvent]:
def extract_date(self) -> Optional[str]:
"""Return the date of the game."""
game_elm = self.root.find("Game")
if game_elm and "game_date" in game_elm.attrib:
if game_elm is not None and "game_date" in game_elm.attrib:
return parse(game_elm.attrib["game_date"]).astimezone(timezone.utc)
else:
return None

def extract_game_week(self) -> Optional[str]:
"""Return the game_week of the game."""
game_elm = self.root.find("Game")
if game_elm and "matchday" in game_elm.attrib:
if game_elm is not None and "matchday" in game_elm.attrib:
return game_elm.attrib["matchday"]
else:
return None

def extract_game_id(self) -> Optional[str]:
"""Return the game_id of the game."""
game_elm = self.root.find("Game")
if game_elm and "id" in game_elm.attrib:
game_elm: Optional[Element] = self.root.find("Game")
if game_elm is not None and "id" in game_elm.attrib:
return game_elm.attrib["id"]
else:
return None
Loading