Skip to content

Commit 11127bc

Browse files
committed
fix(OP#9528): use drop_nulls subset in create_track_segments to preserve null-geo segments
drop_nulls() without a subset dropped every row where any column was null, including segments from null-padded tracks (geo columns present but null). This caused tracks without geo data in a mixed dataset to have zero segments in the geometry store, making them invisible to intersection detection. Restrict the drop to the non-geo shifted columns whose nulls exclusively mark the first (incomplete) detection row of each track.
1 parent 1a5737a commit 11127bc

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

OTAnalytics/plugin_datastore/track_geometry_store/polars_geometry_store.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,17 @@ def create_track_segments(df: pl.DataFrame) -> pl.DataFrame:
185185
pl.col(H).shift(1).over(TRACK_ID).alias(START_H),
186186
]
187187
+ geo_columns
188-
).drop_nulls() # Remove rows where shift resulted in null (first rows per track)
188+
).drop_nulls(
189+
subset=[
190+
START_OCCURRENCE,
191+
START_X,
192+
START_Y,
193+
START_W,
194+
START_H,
195+
]
196+
# Only drop on non-geo shifted columns. Geo columns may legitimately be
197+
# null (null-padded datasets) and must not cause valid segments to be dropped.
198+
)
189199

190200
geo_select = [END_GEO_X, END_GEO_Y, START_GEO_X, START_GEO_Y] if has_geo else []
191201

tests/unit/OTAnalytics/plugin_datastore/track_geometry_store/test_polars_geometry_store.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,17 @@ def test_segments_omit_geo_columns_when_only_geo_x_present(self) -> None:
827827
result = create_track_segments(df_only_x)
828828
assert START_GEO_X not in result.columns
829829

830+
def test_segments_preserved_when_geo_columns_have_null_values(self) -> None:
831+
given = create_segment_geo_given()
832+
df_null_geo = given.df_without_geo.with_columns(
833+
pl.lit(None, dtype=pl.Float64).alias(track.GEO_X),
834+
pl.lit(None, dtype=pl.Float64).alias(track.GEO_Y),
835+
)
836+
result = create_track_segments(df_null_geo)
837+
assert len(result) == 2
838+
assert result[START_GEO_X].is_null().all()
839+
assert result[END_GEO_X].is_null().all()
840+
830841

831842
@dataclass
832843
class LineIntersectionGeoGiven:

0 commit comments

Comments
 (0)