Is there a way to exclude weekends from being test...
# ask-elementary-ai
a
Is there a way to exclude weekends from being tested ? For example, if saturday or sunday falls into the detection period, I just want to skip them or mark them as success.
k
A message from kapa.ai
Based on the knowledge sources, there isn't a direct way to exclude weekends from being tested or to skip them in the detection period. However, there are a couple of approaches you can use to handle data that has different patterns on weekends: ## Use Seasonality Configuration The recommended approach is to use the
seasonality: day_of_week
configuration. This tells Elementary to compare each day only against the same day of the week from previous periods (e.g., Saturdays compared only to previous Saturdays, Sundays to Sundays, etc.). According to the [seasonality documentation](https://docs.elementary-data.com/data-tests/anomaly-detection-configuration/seasonality), this is particularly useful for datasets that have lower volume over weekends:
Copy code
yaml models:   - name: this_is_a_model     tests:       - elementary.volume_anomalies:           seasonality: day_of_week           time_bucket:             period: day             count: 1
With this configuration, if you typically have 0 rows on weekends, Elementary will compare Saturday's 0 rows against previous Saturdays' 0 rows, so it won't flag this as an anomaly. ## Alternative: Use where_expression If you want to completely exclude weekends from the test, you could use the
where_expression
parameter to filter out weekend data entirely. As mentioned in a [Slack discussion](https://slack.com/archives/C02CTC89LAX/p1686640037495849), you can add a where clause to exclude specific dates:
Copy code
yaml - elementary.volume_anomalies:     where_expression: "DAYOFWEEK(timestamp_column) NOT IN (1, 7)"  # Adjust syntax for your warehouse
However, this would exclude weekends from both the detection and training periods, which may not be exactly what you want. Note: There is currently no built-in feature to mark specific days as "success" or to skip them entirely from the detection period while keeping them in the training data.
a
@kapa.ai the where_expression would still fail because it would still test for weekend days and it would find no data since I filtered it. Also I need fail_on_zero=true otherwise It would not fail on week days when missing data.
k
A message from kapa.ai
You're absolutely right, and I apologize for the confusion in my previous response. The
where_expression
approach wouldn't work for your use case because: 1. The
where_expression
filters the data being tested, but Elementary still evaluates the time buckets within the detection period 2. If you filter out weekends with
where_expression
, those weekend buckets would have 0 rows 3. With
fail_on_zero: true
, the test would fail on those weekend buckets Based on the knowledge sources, there is currently no built-in way to completely exclude specific days (like weekends) from the detection period while still using
fail_on_zero: true
for weekdays
. ## The Current Limitation According to a [Slack discussion](https://slack.com/archives/C02CTC89LAX/p1698683615614929), Elementary needs the data of full time buckets to determine anomalies, and by default it only calculates anomalies on "full buckets." The platform doesn't currently support skipping specific days within the detection period. ## Your Best Option The
seasonality: day_of_week
configuration remains your best approach, but it won't completely "skip" weekends - it will just compare weekends to previous weekends. If you consistently have no data on weekends, this should prevent false positives on those days. However, this doesn't address your specific need to have
fail_on_zero: true
work only on weekdays while ignoring weekends entirely. The knowledge sources do not contain a solution for this specific requirement. You might need to consider running separate tests for weekdays and weekends, or potentially opening a feature request with the Elementary team for day-of-week specific configurations.
a
@kapa.ai So fail_on_zero defines what happens if the metric is 0 right ? Is there a way to control how it behaved when there is no training data ?
k
A message from kapa.ai
You're correct that
fail_on_zero
controls what happens when the metric value is 0 within the detection period. According to the [fail_on_zero documentation](https://docs.elementary-data.com/data-tests/anomaly-detection-configuration/fail_on_zero), "Elementary anomaly detection tests will fail if there is a zero metric value within the detection period." ## Behavior When There's No Training Data Based on the knowledge sources, when there isn't enough training data, Elementary has specific default behavior: According to a [Slack discussion](https://slack.com/archives/C02CTC89LAX/p1690997004224019): > "If there are less than 14 days in the table the tests won't fail because this is still a 'training period' for the anomaly detection." And from another [Slack conversation](https://slack.com/archives/C02CTC89LAX/p1692965164612639), a support staff member explained: > "it's supposed to pass and show in the UI that there were not enough data points to reach a decision." ## Controlling the Training Period You can control the minimum amount of training data required using the
min_training_set_size
parameter. As mentioned in a [GitHub issue](https://github.com/elementary-data/elementary/issues/1118), you can configure:
Copy code
yaml config:   elementary:     min_training_set_size: 14  # minimum number of data points required
However, the knowledge sources do not explicitly mention a way to make the test fail when there is insufficient training data - by default, it passes when there isn't enough data to make a determination. The test behavior when lacking training data appears to be designed to avoid false positives during initial setup or data gaps. If you need the test to fail when there's no training data available, this doesn't appear to be a supported configuration option based on the available documentation.
a
@kapa.ai so if I set fail_on_zero=true but I filter weekend with where_expression, when testing for weekend, it won't find data and the test will pass ?
k
A message from kapa.ai
Based on the knowledge sources, I need to clarify the behavior you're asking about. When you use
where_expression
to filter out weekends, you're filtering the data that Elementary queries, but Elementary still evaluates the time buckets within the detection period. This is a crucial distinction. ## What Actually Happens According to a [Slack discussion about fail_on_zero](https://slack.com/archives/C02CTC89LAX/p1701274524204489), when investigating why
fail_on_zero: true
wasn't working as expected, a support staff member asked: > "When you're running the test without fail_on_zero do you see rows in data_monitoring_metrics?" This suggests that Elementary creates metric entries for time buckets, and
fail_on_zero
evaluates those metric values. ## The Expected Behavior Based on the [fail_on_zero documentation](https://docs.elementary-data.com/data-tests/anomaly-detection-configuration/fail_on_zero): > "Elementary anomaly detection tests will fail if there is a zero metric value within the detection period." If you filter out weekends with
where_expression
, those weekend time buckets would have 0 rows in the filtered dataset. With
fail_on_zero: true
, the test should fail on those weekend buckets because the metric value is 0. However, I must note that the knowledge sources do not explicitly document the exact interaction between
where_expression
and
fail_on_zero
in this specific scenario. The behavior I've described is based on the general documentation of how these features work, but there may be nuances in the actual implementation that aren't covered in the available documentation. To get a definitive answer about this specific interaction, you might need to test it directly or reach out to the Elementary team.
a
@kapa.ai Can anomaly_exclude_metrics help me here ?
k
A message from kapa.ai
Based on the knowledge sources,
anomaly_exclude_metrics
won't solve your specific problem
of excluding weekends from the detection period while keeping
fail_on_zero: true
for weekdays. ## What
anomaly_exclude_metrics
Actually Does According to the [
anomaly_exclude_metrics
documentation](https://docs.elementary-data.com/data-tests/anomaly-detection-configuration/anomaly-exclude-metrics): > "By default, data points are compared to all data points in the training set. Using this param, you can exclude metrics from the training set, to improve the test accuracy." The key limitation is that
anomaly_exclude_metrics
excludes data points from the training set, not from the detection period. ## Why It Won't Help Your Use Case As explained in a [Slack discussion](https://slack.com/archives/C02CTC89LAX/p1740069258974599), when someone tried to use
anomaly_exclude_metrics
to exclude the detection date: > "I was looking at
anomaly_exclude_metrics
but when I configure this it filters out the date for both the detection and training period." And in a [GitHub issue about excluding detection periods](https://github.com/elementary-data/elementary/issues/1491), a user noted that while you can use
anomaly_exclude_metrics
to exclude the latest data point from training:
Copy code
sql anomaly_exclude_metrics: "MAX(bucket_end) OVER (...) = bucket_end"
This approach still doesn't prevent Elementary from evaluating those time buckets in the detection period - it only excludes them from training calculations. ## The Bottom Line
anomaly_exclude_metrics
is designed to exclude problematic data points (like incidents or outliers) from influencing your training data and expected ranges, but it doesn't skip time buckets in the detection period. Elementary will still evaluate weekend buckets, and with
fail_on_zero: true
, those buckets would still fail if they have 0 rows. The knowledge sources confirm that there's currently no built-in way to completely exclude specific days from being tested in the detection period.