@@ -1212,27 +1212,49 @@ def _filter_ttl(
12121212 # Non-entity snapshots only contain entities with an eligible source row.
12131213 return df_to_join [valid ].persist ()
12141214
1215- # Keep the request row when every candidate is outside the time range.
1216- # Null candidates sort first, so deduplication still prefers a valid match.
1217- return df_to_join .assign (
1218- ** {
1219- # Use pandas' nullable missing value so integer feature columns do not
1220- # get silently widened to float64 when an ineligible candidate is nulled.
1221- column : (
1222- df_to_join [column ]
1215+ # Keep eligible candidates as-is. Besides avoiding unnecessary work, this
1216+ # preserves plain integer dtypes when every request has a match.
1217+ eligible = df_to_join [valid ]
1218+ request_columns = [
1219+ column for column in df_to_join .columns if column in preserved_columns
1220+ ]
1221+ requests = df_to_join [request_columns ].drop_duplicates ()
1222+ matched_requests = eligible [request_columns ].drop_duplicates ()
1223+ missing_requests = requests .merge (
1224+ matched_requests , on = request_columns , how = "left" , indicator = True
1225+ )
1226+ missing_requests = missing_requests [missing_requests ["_merge" ] == "left_only" ]
1227+ missing_requests = missing_requests .drop (columns = ["_merge" ])
1228+
1229+ # Re-add one null-feature row only for requests that lost every candidate.
1230+ # Keep this in the original frame so Dask's timestamp dtypes and divisions
1231+ # remain intact while the later deduplication sorts candidates.
1232+ marked = df_to_join .merge (
1233+ missing_requests .assign (__ttl_missing = True ),
1234+ on = request_columns ,
1235+ how = "left" ,
1236+ )
1237+ ttl_missing = marked ["__ttl_missing" ].fillna (False )
1238+ marked = marked [valid | ttl_missing ]
1239+ return (
1240+ marked .assign (
1241+ ** {
1242+ column : marked [column ]
12231243 .astype (
12241244 "UInt64"
1225- if is_unsigned_integer_dtype (df_to_join [column ].dtype )
1245+ if is_unsigned_integer_dtype (marked [column ].dtype )
12261246 else "Int64"
12271247 )
1228- .mask (~ valid , other = pd .NA )
1229- if is_integer_dtype (df_to_join [column ].dtype )
1230- else df_to_join [column ].mask (~ valid , other = pd .NA )
1231- )
1232- for column in df_to_join .columns
1233- if column not in preserved_columns
1234- }
1235- ).persist ()
1248+ .mask (ttl_missing , other = pd .NA )
1249+ if is_integer_dtype (marked [column ].dtype )
1250+ else marked [column ].mask (ttl_missing , other = pd .NA )
1251+ for column in marked .columns
1252+ if column not in preserved_columns and column != "__ttl_missing"
1253+ }
1254+ )
1255+ .drop (columns = ["__ttl_missing" ])
1256+ .persist ()
1257+ )
12361258
12371259
12381260def _apply_created_timestamp_cutoff (
0 commit comments