> ## Documentation Index
> Fetch the complete documentation index at: https://calendar-effects.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# tests/test_ml_features.py

> Tests for ml.features: the calendar and retailer features of the big-move model (decision 0007).

`tests/test_ml_features.py` · chapter [Tests and team tooling](https://calendar-effects.mintlify.site/tour/10-tests-and-tooling.md), file 10 · 55 lines · [open in the repository](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/tests/test_ml_features.py)

## What it does

Tests for ml.features: the calendar and retailer features of the big-move model (decision 0007).

## What it checks

* feature names are unique and the label is not a feature (line 9)
* the time split runs forward without overlap (line 15)
* every event day is zero days from an event (line 19)
* days count down to the next event and up since the last (line 25)
* values are capped (line 36)
* the calendar has one row per day (line 44)
* is online follows config retailers (line 51)

## Connections

**Uses:** [`src/common/contracts.py`](https://calendar-effects.mintlify.site/reference/src/common/contracts), [`src/common/study.py`](https://calendar-effects.mintlify.site/reference/src/common/study), [`src/ml/features.py`](https://calendar-effects.mintlify.site/reference/src/ml/features)

## Source

```python title="tests/test_ml_features.py" lines expandable theme={null}
"""Tests for ml.features: the calendar and retailer features of the big-move model (decision 0007)."""
from datetime import date, timedelta

from common.contracts import load_retailers
from common.study import ML_EVENT_DAYS_CAP, ML_TEST_START_YEAR, ML_TRAIN_END_YEAR, ML_VALIDATION_YEAR
from ml.features import ATTENTION_FEATURES, FEATURES, LABEL, calendar_table, event_days, retailer_table


def test_feature_names_are_unique_and_the_label_is_not_a_feature():
    assert len(FEATURES) == len(set(FEATURES))
    assert set(ATTENTION_FEATURES) <= set(FEATURES)
    assert LABEL not in FEATURES


def test_the_time_split_runs_forward_without_overlap():
    assert ML_TRAIN_END_YEAR < ML_VALIDATION_YEAR < ML_TEST_START_YEAR


def test_every_event_day_is_zero_days_from_an_event():
    cal = calendar_table().set_index("date")
    for d in event_days():
        assert cal.loc[d, "days_to_event"] == 0 and cal.loc[d, "days_since_event"] == 0, d


def test_days_count_down_to_the_next_event_and_up_since_the_last():
    cal = calendar_table().set_index("date")
    events = set(event_days())
    for d in event_days()[:20]:
        before, after = d - timedelta(days=1), d + timedelta(days=1)
        if before in cal.index and before not in events:
            assert cal.loc[before, "days_to_event"] == 1, before
        if after in cal.index and after not in events:
            assert cal.loc[after, "days_since_event"] == 1, after


def test_values_are_capped():
    cal = calendar_table()
    for col in ("days_to_event", "days_since_event"):
        assert cal[col].between(0, ML_EVENT_DAYS_CAP).all(), col
    first = cal.iloc[0]
    assert first["days_since_event"] == ML_EVENT_DAYS_CAP or first["date"] in set(event_days())


def test_the_calendar_has_one_row_per_day():
    cal = calendar_table()
    assert cal["date"].is_unique
    assert (cal["date"].diff().dropna() == timedelta(days=1)).all()
    assert isinstance(cal["date"].iloc[0], date)


def test_is_online_follows_config_retailers():
    online = {r["ticker"]: int(r["retailer_type"] == "online") for r in load_retailers()}
    table = retailer_table()
    assert dict(zip(table["ticker"], table["is_online"])) == online
    assert set(table["is_online"]) <= {0, 1}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.