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

add support for parsing of invalid time with only hours and minutes #80

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
7 changes: 6 additions & 1 deletion partridge/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ def parse_time(val: str) -> np.float64:
if val == "":
return np.nan

h, m, s = val.split(":")
h, m, *s = val.split(":")
if len(s) == 0:
s = "0"
else:
assert len(s) == 1
s = s[0]
ssm = int(h) * 3600 + int(m) * 60 + int(s)

# pandas doesn't have a NaN int, use floats
Expand Down
4 changes: 4 additions & 0 deletions tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def test_parse_time():
assert parse_time("1:02:03") == 3723
assert parse_time("25:24:23") == 91463
assert parse_time("250:24:23") == 901463
assert parse_time("00:00") == 0
assert parse_time("0:00") == 0
assert parse_time("01:02") == 3720
assert parse_time("1:02") == 3720


def test_parse_time_with_invalid_input():
Expand Down