Sub topic 11
Point-in-time correctness for time-dependent features
This chapter assumes you can build a training set from a feature table and a labeled DataFrame, as covered in the previous chapters. It also assumes you know what a primary key is in a Unity Catalog feature table. Here you will learn why a plain key join can leak future information into training data, and how a time series feature table and a timestamp lookup key prevent it.
The problem: label leakage through time
Many features change over time. A user's 90-day order count today is not the same as it was three months ago. If your feature table keeps only one row per user_id, that row holds the latest values.
Suppose you train a churn model on labeled events from last spring. A plain join on user_id attaches today's feature values to those old events. The model then sees information that did not exist when each event happened. This is called label leakage (also called data leakage). The model looks excellent in evaluation and then performs worse in production, where only past data is available.
Point-in-time correctness means that for each labeled event, you use the feature values that were known at the time of that event, and nothing newer.
How a time series feature table works
A time series feature table stores several rows per entity, one for each point in time at which the features were computed. Two things define it:
- The primary key includes a timestamp column, for example
["user_id", "feature_ts"]. - That timestamp column is also declared as a time series column.
The time series column tells the feature engineering client that rows for the same entity are ordered by that column. It is the column used to find the right row at lookup time.
| Design | Rows per user | Lookup behavior |
|---|---|---|
| Standard feature table, key `user_id` | One | Returns the current values |
| Time series feature table, key `user_id` + `feature_ts` | Many | Returns the latest values at or before the event time |
Creating a time series feature table
The table below is keyed by user_id and feature_ts. The timeseries_columns argument marks feature_ts as the time dimension.
from databricks.feature_engineering import FeatureEngineeringClient, FeatureLookup
fe = FeatureEngineeringClient()
fe.create_table(
name="main.ml.user_activity_features",
primary_keys=["user_id", "feature_ts"],
timeseries_columns=["feature_ts"],
df=activity_features_df,
)Here activity_features_df is a DataFrame with user_id, feature_ts, and the feature columns. Each row means: "as of feature_ts, these were the feature values for this user."
In SQL terms, a time series feature table is a Delta table whose primary key adds a TIMESERIES marker on the timestamp column. The Python client sets this for you.
Looking up features as of an event time
To get point-in-time behavior, add timestamp_lookup_key to the FeatureLookup. It names the column in your labeled DataFrame that holds the event time.
lookup = FeatureLookup(
table_name="main.ml.user_activity_features",
lookup_key="user_id",
timestamp_lookup_key="event_ts",
)
training_set = fe.create_training_set(
df=labeled_events_df, # user_id, event_ts, label
feature_lookups=[lookup],
label="label",
)For each row in labeled_events_df, the client finds the feature row with the same user_id and the latest feature_ts that is less than or equal to event_ts. This is often called an as-of join.
A worked example
Take one user, u1, with these feature rows:
| user_id | feature_ts | sessions_7d |
|---|---|---|
| u1 | 2026-01-01 | 2 |
| u1 | 2026-02-01 | 5 |
| u1 | 2026-03-01 | 9 |
And these labeled events:
| user_id | event_ts | label |
|---|---|---|
| u1 | 2026-01-15 | 0 |
| u1 | 2026-02-20 | 0 |
| u1 | 2026-03-10 | 1 |
The point-in-time join returns:
| event_ts | matched feature_ts | sessions_7d |
|---|---|---|
| 2026-01-15 | 2026-01-01 | 2 |
| 2026-02-20 | 2026-02-01 | 5 |
| 2026-03-10 | 2026-03-01 | 9 |
A plain key join would have attached 9 to all three events. The first two would have used values from the future.
Edge cases and gotchas
No earlier feature row exists
If an event happens before the first feature row for that key, no row qualifies. The lookup returns null for those features. Check for nulls in the training DataFrame and decide whether to drop those rows or impute values (see the chapter on missing values).
Equal timestamps are allowed
The match uses "at or before", so a feature row with feature_ts equal to event_ts is used. Make sure that your pipeline cannot produce a feature_ts earlier than the moment the data was actually available. A feature stamped 2026-02-01 but computed from data that arrived on 2026-02-03 still leaks.
Timestamp meaning matters more than the join
The as-of join is only as honest as feature_ts. Set it to the time the feature values became knowable, not the time the pipeline happened to run, and not the end of a window that includes later data. Late-arriving source data is a common cause of subtle leakage.
Time-to-live and stale matches
An as-of join can match a row that is very old. If a user has no new feature row for a year, the lookup still returns the year-old row. Consider whether that is acceptable, or whether the feature table should be refreshed on a regular schedule.
Scoring with time series tables
Models logged with time series lookups need an event timestamp in the scoring input, because the lookup depends on it. A batch scoring DataFrame must therefore contain the key and the timestamp column named in timestamp_lookup_key, not just the key.
batch_df = spark.table("main.ml.events_to_score").select("user_id", "event_ts")
predictions = fe.score_batch(
model_uri="models:/main.ml.churn_model/1",
df=batch_df,
)Splitting train and test data
Point-in-time joins stop feature leakage, but they do not stop leakage across your train and test split. For time-dependent data, split by event time (train on earlier events, test on later ones) instead of randomly. A random split lets the model learn from events that occur after some test events.
Quick checklist
- Declare the timestamp column in both
primary_keysandtimeseries_columns. - Set
timestamp_lookup_keyon each lookup for a time series table. - Define
feature_tsas the time the values were available. - Check for null features caused by events earlier than the first snapshot.
- Split train and test sets by time.
Exercise
A feature table has key user_id only and is refreshed nightly with the latest 30-day purchase count. You build a training set from labeled events dated six months ago using a plain lookup. Why is this a problem, and what two changes fix it?
Show answer
The plain lookup returns the current row for each user, so features reflect purchases made after the labeled events, which is label leakage. Fix it by (1) storing the feature history as a time series table, with feature_ts in primary_keys and timeseries_columns, and (2) setting timestamp_lookup_key to the event time column in the FeatureLookup, so each event gets the latest feature row at or before its own timestamp.
Exercise
A labeled event for u2 is dated 2026-01-05. The earliest feature row for u2 has feature_ts of 2026-01-10. What does the point-in-time lookup return, and what should you do about it?
Show answer
It returns null for the features, because no row exists at or before the event time. Check for these nulls in the training DataFrame, then drop the rows or impute values, depending on how the model will handle new users at inference time.