|
1 | 1 | """Tests for dynamic validator."""
|
2 |
| -from datetime import date, datetime |
| 2 | +from datetime import date, datetime, timedelta |
3 | 3 | import numpy as np
|
4 | 4 | import pandas as pd
|
5 | 5 |
|
@@ -465,3 +465,32 @@ def test_source_api_overlap(self):
|
465 | 465 |
|
466 | 466 | assert len(report.raised_warnings) == 2
|
467 | 467 | assert report.raised_warnings[0].check_name == "check_positive_negative_spikes"
|
| 468 | + |
| 469 | +class TestDateComparison: |
| 470 | + params = { |
| 471 | + "common": { |
| 472 | + "data_source": "", |
| 473 | + "span_length": 1, |
| 474 | + "end_date": "2020-09-02" |
| 475 | + } |
| 476 | + } |
| 477 | + |
| 478 | + def test_date_comparison_by_type(self): |
| 479 | + validator = DynamicValidator(self.params) |
| 480 | + report = ValidationReport([]) |
| 481 | + |
| 482 | + ref_val = [30, 30, 30] |
| 483 | + test_val = [100, 100, 100] |
| 484 | + |
| 485 | + START = datetime.strptime("2020-10-01", "%Y-%m-%d") |
| 486 | + ref_data = pd.DataFrame({"val": ref_val, "se": [np.nan] * len(ref_val), |
| 487 | + "sample_size": [np.nan] * len(ref_val), "geo_id": ["1"] * len(ref_val), |
| 488 | + # datetime64 type |
| 489 | + "time_value": pd.date_range(start=START, end=START + timedelta(days=len(ref_val) - 1))}) |
| 490 | + test_data = pd.DataFrame({"val": test_val, "se": [np.nan] * len(test_val), |
| 491 | + "sample_size": [np.nan] * len(test_val), "geo_id": ["1"] * len(test_val), |
| 492 | + # datetime.date type |
| 493 | + "time_value": datetime.strptime("2020-10-26", "%Y-%m-%d").date()}) |
| 494 | + |
| 495 | + # This should run without raising any errors. |
| 496 | + validator.check_max_date_vs_reference(test_data, ref_data, "date", "state", "signal", report) |
0 commit comments