from __future__ import annotations import pandas as pd from apps.tools.build_ranking_model import build_model def test_build_model_normalizes_reaction_date_strings(tmp_path) -> None: frame = pd.DataFrame( [ { "event_date": "2024-12-30", "reaction_date": "2024-12-30", "event_type": "earnings_release", "reaction_day_return": 0.08, "fwd_return_20d": 0.12, "event_direction": "bullish", "guidance_status": "raised", "close_location": 0.72, "volume_ratio_20d": 2.2, "gap_size": 0.03, "document_quality_score": 0.81, "parse_confidence_overall": 0.82, }, { "event_date": "2025-01-02", "reaction_date": "2025-01-02", "event_type": "earnings_release", "reaction_day_return": 0.09, "fwd_return_20d": 0.10, "event_direction": "bullish", "guidance_status": "raised", "close_location": 0.75, "volume_ratio_20d": 2.4, "gap_size": 0.02, "document_quality_score": 0.83, "parse_confidence_overall": 0.84, }, ] ) snapshot_path = tmp_path / "train.parquet" frame.to_parquet(snapshot_path) model = build_model(snapshot_path, cutoff_event_date="2024-12-31", min_bucket_count=1) assert model["training_rows"] == 1 assert model["global_mean"] == 0.12 event_type_feature = next(feature for feature in model["features"] if feature["name"] == "event_type") assert event_type_feature["values"]["earnings_release"] == 0.12