Skip to content

feat: opt-in split_locations for events() — flat x/y(/z) coordinate c… - #80

Merged
willnewton merged 2 commits into
hudl:masterfrom
IliassSjm:split-locations
Oct 19, 2026
Merged

willnewton merged 2 commits into
hudl:masterfrom
IliassSjm:split-locations

Conversation

@IliassSjm

Copy link
Copy Markdown
Contributor

What

Adds an opt-in split_locations: bool = False keyword to sb.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>_z when 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:

  • they are unhashable, so drop_duplicates() and groupby on locations raise;
  • they block vectorised numpy/pandas operations (everyone ends up writing the same .apply(lambda loc: loc[0]));
  • they don't round-trip through Parquet — pd.read_parquet returns numpy arrays where lists were written, which silently breaks downstream isinstance(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.

@IliassSjm

Copy link
Copy Markdown
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!

@orca-security-us orca-security-us Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Infrastructure as Code high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca

@willnewton
willnewton merged commit dcb826e into hudl:master Oct 19, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants