Skip to content

Commit

Permalink
Feature t minus check (#116)
Browse files Browse the repository at this point in the history
* Added new checks for date validation

* Added test cases for t-minus check
  • Loading branch information
canimus authored Sep 9, 2023
1 parent 3fe9307 commit cdfb6e7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ Check | Description | DataType
`is_inside_interquartile_range` | Verifies column values reside inside limits of interquartile range `Q1 <= col <= Q3` used on anomalies. | _numeric_
`is_in_millions` | `col >= 1e6` | _numeric_
`is_in_billions` | `col >= 1e9` | _numeric_
`is_t_minus_1` | For date fields confirms 1 day ago `t-1` | _date_
`is_t_minus_2` | For date fields confirms 2 days ago `t-2` | _date_
`is_t_minus_3` | For date fields confirms 3 days ago `t-3` | _date_
`is_t_minus_n` | For date fields confirms n days ago `t-n` | _date_
`is_today` | For date fields confirms day is current date `t-0` | _date_
`is_yesterday` | For date fields confirms 1 day ago `t-1` | _date_
`is_on_weekday` | For date fields confirms day is between `Mon-Fri` | _date_
`is_on_weekend` | For date fields confirms day is between `Sat-Sun` | _date_
`is_on_monday` | For date fields confirms day is `Mon` | _date_
Expand Down
27 changes: 26 additions & 1 deletion cuallee/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import operator
from collections import Counter
from dataclasses import dataclass, field
from datetime import datetime
from datetime import datetime, timedelta
from types import ModuleType
from typing import Any, Dict, List, Literal, Optional, Protocol, Tuple, Union
from numbers import Number
Expand Down Expand Up @@ -363,6 +363,31 @@ def is_contained_in(
def is_in(self, column: str, value: Tuple[str, int, float], pct: float = 1.0):
"""Vaidation of column value in set of given values"""
return self.is_contained_in(column, value, pct)

def is_t_minus_n(self, column: str, value: int, pct: float = 1.0):
"""Validate that date is yesterday"""
yesterday = datetime.utcnow() - timedelta(days=value)
return self.is_in(column, tuple([yesterday.strftime("%Y-%m-%d")]), pct)

def is_t_minus_1(self, column: str, pct: float = 1.0):
"""Validate that date is yesterday"""
return self.is_t_minus_n(column, 1, pct)

def is_t_minus_2(self, column: str, pct: float = 1.0):
"""Validate that date is 2 days ago"""
return self.is_t_minus_n(column, 2, pct)

def is_t_minus_3(self, column: str, pct: float = 1.0):
"""Validate that date is 3 days ago"""
return self.is_t_minus_n(column, 3, pct)

def is_yesterday(self, column: str, pct: float = 1.0):
"""Validate that date is yesterday"""
return self.is_t_minus_1(column, pct)

def is_today(self, column: str, pct: float = 1.0):
"""Validate that date is today"""
return self.is_t_minus_n(column, 0, pct)

def has_percentile(
self, column: str, value: float, percentile: float, precision: int = 10000
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "cuallee"
version = "0.5.0"
version = "0.5.1"
authors = [
{ name="Virginie Grosboillot", email="[email protected]" },
{ name="Herminio Vazquez", email="[email protected]"}
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[metadata]
name = cuallee
version = 0.5.0
version = 0.5.1
[options]
packages = find:

0 comments on commit cdfb6e7

Please sign in to comment.