Skip to content

Commit 28677d6

Browse files
fix: preserve Friday equity bars during weekend validation (#88)
Correct the Polars ISO weekday threshold in equity validation and retain Saturday/Sunday regression coverage. Closes #87.
1 parent 6888629 commit 28677d6

2 files changed

Lines changed: 36 additions & 6 deletions

File tree

‎src/ml4t/data/assets/validation.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def _validate_equity(self, df: pl.DataFrame) -> dict[str, list[str]]:
128128

129129
# Check for weekend data (should not exist for regular equities)
130130
if "timestamp" in df.columns:
131-
weekend_data = df.filter(pl.col("timestamp").dt.weekday() >= 5)
131+
weekend_data = df.filter(pl.col("timestamp").dt.weekday() >= 6)
132132
if len(weekend_data) > 0:
133133
issues.append(f"Found {len(weekend_data)} weekend data points")
134134

‎tests/assets/test_validation.py‎

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,46 @@ def test_validate_valid_data_no_issues(self):
253253
class TestValidateEquity:
254254
"""Tests for equity-specific validation."""
255255

256-
def test_validate_weekend_data(self):
256+
@pytest.mark.parametrize(
257+
"timestamp",
258+
[
259+
pytest.param(datetime(2025, 7, 7, 10), id="monday"),
260+
pytest.param(datetime(2025, 7, 8, 10), id="tuesday"),
261+
pytest.param(datetime(2025, 7, 9, 10), id="wednesday"),
262+
pytest.param(datetime(2025, 7, 10, 10), id="thursday"),
263+
pytest.param(datetime(2025, 7, 11, 10), id="friday"),
264+
],
265+
)
266+
def test_validate_regular_weekdays_do_not_report_weekend(self, timestamp):
267+
info = AssetInfo(symbol="SPY", asset_class=AssetClass.EQUITY, exchange="NYSE")
268+
df = pl.DataFrame(
269+
{
270+
"timestamp": [timestamp],
271+
"open": [100.0],
272+
"high": [101.0],
273+
"low": [99.0],
274+
"close": [100.0],
275+
"volume": [1000.0],
276+
}
277+
)
278+
279+
assert AssetValidator(info).validate(df) == {}
280+
281+
@pytest.mark.parametrize(
282+
"timestamp",
283+
[
284+
pytest.param(datetime(2025, 7, 12, 10), id="saturday"),
285+
pytest.param(datetime(2025, 7, 13, 10), id="sunday"),
286+
],
287+
)
288+
def test_validate_weekend_data(self, timestamp):
257289
"""Test detecting weekend data for equities."""
258290
info = AssetInfo(symbol="AAPL", asset_class=AssetClass.EQUITY)
259291
validator = AssetValidator(info)
260292

261-
# January 7, 2023 is a Saturday
262293
df = pl.DataFrame(
263294
{
264-
"timestamp": [datetime(2023, 1, 7)],
295+
"timestamp": [timestamp],
265296
"open": [100.0],
266297
"high": [101.0],
267298
"low": [99.0],
@@ -272,8 +303,7 @@ def test_validate_weekend_data(self):
272303

273304
results = validator.validate(df)
274305

275-
assert "equity_specific" in results
276-
assert any("weekend" in issue.lower() for issue in results["equity_specific"])
306+
assert results == {"equity_specific": ["Found 1 weekend data points"]}
277307

278308
def test_validate_negative_prices(self):
279309
"""Test detecting non-positive prices."""

0 commit comments

Comments
 (0)