Skip to content

Commit 9029a56

Browse files
committed
one more punt edge case
1 parent 613e070 commit 9029a56

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

sportsdataverse/cfb/cfb_pbp.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,13 +2535,15 @@ def __add_play_category_flags(self, play_df):
25352535
(play_df.punt == True)
25362536
& (play_df.text.str.contains("^\\(\d{1,2}:\d{2}\\) ", regex=True))
25372537
& (play_df["start.pos_team.id"] != play_df["end.pos_team.id"])
2538-
& (~(play_df["punt_oob"])),
2538+
& (~(play_df["punt_oob"]))
2539+
& (~(play_df["penalty_in_text"])),
25392540
"end.yardsToEndzone"
25402541
] = 100 - play_df.loc[
25412542
(play_df.punt == True)
25422543
& (play_df.text.str.contains("^\\(\d{1,2}:\d{2}\\) ", regex=True))
25432544
& (play_df["start.pos_team.id"] != play_df["end.pos_team.id"])
2544-
& (~(play_df["punt_oob"])),
2545+
& (~(play_df["punt_oob"]))
2546+
& (~(play_df["penalty_in_text"])),
25452547
"end.yardsToEndzone"
25462548
]
25472549

@@ -3166,6 +3168,12 @@ def __add_yardage_cols(self, play_df):
31663168
)
31673169
),
31683170
(play_df.punt == True)
3171+
& (
3172+
play_df["cleaned_text"].str.contains(
3173+
r"return \d+ yards", case=False, flags=0, na=False, regex=True
3174+
)
3175+
),
3176+
(play_df.punt == True)
31693177
& (
31703178
play_df["cleaned_text"].str.contains(
31713179
r"returned \d+ yards", case=False, flags=0, na=False, regex=True
@@ -3178,20 +3186,28 @@ def __add_yardage_cols(self, play_df):
31783186
20,
31793187
0,
31803188
0,
3189+
31813190
-1 * play_df.cleaned_text.str.extract(
31823191
r"return for loss of (\d+) y.*ds", flags=re.IGNORECASE
31833192
)[0].astype(float),
3193+
31843194
0,
3195+
3196+
play_df.cleaned_text.str.extract(r"return (\d+) y.*ds")[0]
3197+
.astype(float),
3198+
31853199
play_df.cleaned_text.str.extract(r"((?<= returned)[^,]+)", flags=re.IGNORECASE)[
31863200
0
31873201
]
31883202
.str.extract(r"(\d+)")[0]
31893203
.astype(float),
3204+
31903205
play_df.cleaned_text.str.extract(
31913206
r"((?<= returns for)[^,]+)", flags=re.IGNORECASE
31923207
)[0]
31933208
.str.extract(r"(\d+)")[0]
31943209
.astype(float),
3210+
31953211
play_df.cleaned_text.str.extract(
31963212
r"((?<= return for)[^,]+)", flags=re.IGNORECASE
31973213
)[0]

tests/cfb/test_pbp.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ def test_25_yardage_detection(play_text: str, yards_field: str, expected_yards:
607607
(401754571, "(13:37) #47 M.Nichols punt 57 yards to the SU22 #10 D.Kerr return for loss of 11 yards to the SU20 fumbled by #10 D.Kerr at SU20 forced by #17 J.Hamilton recovered by SU #26 T.Haile at SU11, End Of Play", 57, -11, True, True, 89, 183),
608608
(401754572, "(02:21) #94 D.Joyce punt 47 yards to the STAN15 fair catch by #13 L.Thorpe at STAN15", 47, 0, False, True, 85, 24),
609609
(401757292, "(08:05) #32 A.Logan punt 39 yards to the JSU10, out of bounds at JSU10", 39, 0, False, True, 90, 55),
610+
(401757292, "(05:26) #32 A.Logan punt 45 yards to the JSU19 #1 M.Pettway return 3 yards to the JSU22 (#9 P.Hughes) PENALTY JSU Holding (#80 C.Williams) 10 yards from JSU22 to JSU12", 45, 3, False, True, 88, 55),
610611
# base case
611612
(401752748, "Grant Chadwick punt for 48 yds , KC Concepcion returns for 14 yds to the TA&M 32", 48, 14, False, True, 68, 245),
612613

0 commit comments

Comments
 (0)