Skip to content

Commit 0c8ba98

Browse files
committed
fix: preserve integer dtypes when masking expired Dask features
Use pandas' nullable missing value when retaining entity rows whose feature candidate is outside the TTL window. This keeps integer feature columns from being widened to float64 while preserving the existing candidate filtering behavior. Add a regression test for integer feature values. Prepared with Codex assistance; no human review is claimed. Signed-off-by: NUAAwqy <146524024+NUAAwqy@users.noreply.github.com>
1 parent 1487d53 commit 0c8ba98

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

‎sdk/python/feast/infra/offline_stores/dask.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,9 @@ def _filter_ttl(
12151215
# Null candidates sort first, so deduplication still prefers a valid match.
12161216
return df_to_join.assign(
12171217
**{
1218-
column: df_to_join[column].mask(~valid)
1218+
# Use pandas' nullable missing value so integer feature columns do not
1219+
# get silently widened to float64 when an ineligible candidate is nulled.
1220+
column: df_to_join[column].mask(~valid, other=pd.NA)
12191221
for column in df_to_join.columns
12201222
if column not in preserved_columns
12211223
}

‎sdk/python/tests/unit/infra/offline_stores/test_dask_ttl_entity_rows.py‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import pytest
99

1010
from feast import Entity, FeatureStore, FeatureView, Field, FileSource, RepoConfig
11-
from feast.types import Float64, ValueType
11+
from feast.types import Float64, Int64, ValueType
1212

1313

1414
def _store(tmp_path: Path) -> FeatureStore:
@@ -152,6 +152,38 @@ def test_later_feature_view_preserves_previous_features_and_entity_columns(
152152
assert result["second__value"].isna().all()
153153

154154

155+
def test_ttl_filter_does_not_widen_integer_feature_columns(tmp_path: Path) -> None:
156+
store = _store(tmp_path)
157+
data = _source()
158+
data["value"] = pd.Series(data["value"], dtype="Int64")
159+
path = tmp_path / "integer_stats.parquet"
160+
data.to_parquet(path)
161+
view = FeatureView(
162+
name="integer_stats",
163+
entities=[
164+
Entity(name="driver", join_keys=["driver_id"], value_type=ValueType.INT64)
165+
],
166+
schema=[Field(name="value", dtype=Int64)],
167+
source=FileSource(
168+
path=str(path),
169+
timestamp_field="event_timestamp",
170+
created_timestamp_column="created_ts",
171+
),
172+
ttl=timedelta(days=1),
173+
)
174+
store.apply([
175+
Entity(name="driver", join_keys=["driver_id"], value_type=ValueType.INT64),
176+
view,
177+
])
178+
179+
result = store.get_historical_features(
180+
entity_df=_entities(), features=["integer_stats:value"]
181+
).to_df().sort_values("driver_id").reset_index(drop=True)
182+
183+
assert str(result["value"].dtype) == "Int64"
184+
assert result["value"].tolist() == [pd.NA, pd.NA, 30, 40, pd.NA]
185+
186+
155187
def test_non_entity_snapshot_still_excludes_ineligible_entities(tmp_path: Path) -> None:
156188
store = _store(tmp_path)
157189
view = _view(tmp_path, "stats", _source(), timedelta(days=1))

0 commit comments

Comments
 (0)