Repository navigation
feat: opt-in split_locations for events() — flat x/y(/z) coordinate c… - #80
Merged
Merged
Conversation
Contributor
Author
|
Checking in on this — happy to rebase or adjust scope if there's interest. The helper is self-contained and the tests are offline, so it should merge cleanly. No rush! |
There was a problem hiding this comment.
Orca Security Scan Summary
| Status | Check | Issues by priority | |
|---|---|---|---|
| Infrastructure as Code | View in Orca | ||
| Secrets | View in Orca |
willnewton
approved these changes
Oct 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds an opt-in
split_locations: bool = Falsekeyword tosb.events(). When enabled, every known location column (location,pass_end_location,carry_end_location,shot_end_location,goalkeeper_end_location) gets flat float companions<col>_x,<col>_y, and<col>_zwhen a third coordinate exists (e.g. shots). Original list columns are preserved, and the default behaviour is unchanged.Implemented as a standalone helper (
helpers.split_location_cols) so it can also be applied to an existing dataframe after the fact.Why
The list-valued location columns are the first thing most users have to work around:
drop_duplicates()andgroupbyon locations raise;.apply(lambda loc: loc[0]));pd.read_parquetreturns numpy arrays where lists were written, which silently breaks downstreamisinstance(loc, (list, tuple))checks.I hit the third one in a real project (cached World Cup events to Parquet, reloaded, and every coordinate extraction returned NaN). The helper handles list, tuple and ndarray inputs uniformly, so it also fixes dataframes that have already been through a Parquet cache.
Tests
tests/test_split_locations.py— six offline unit tests covering the x/y split, conditional z creation, NaN handling for missing/malformed values, the Parquet-roundtrip (ndarray) case, absent columns, and dtype/hashability of the output columns.Happy to extend this to
competition_events()and the README examples if you'd take it.