eazydatafix 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- eazydatafix/__init__.py +53 -0
- eazydatafix/assessment/__init__.py +0 -0
- eazydatafix/assessment/checks/__init__.py +0 -0
- eazydatafix/assessment/checks/accuracy/__init__.py +0 -0
- eazydatafix/assessment/checks/accuracy/engine.py +32 -0
- eazydatafix/assessment/checks/accuracy/numeric_range_check.py +70 -0
- eazydatafix/assessment/checks/completeness.py +40 -0
- eazydatafix/assessment/checks/consistency/__init__.py +0 -0
- eazydatafix/assessment/checks/consistency/case_consistency_check.py +65 -0
- eazydatafix/assessment/checks/consistency/duplicate_text_check.py +58 -0
- eazydatafix/assessment/checks/consistency/engine.py +40 -0
- eazydatafix/assessment/checks/consistency/whitespace_consistency_check.py +57 -0
- eazydatafix/assessment/checks/timeliness/__init__.py +0 -0
- eazydatafix/assessment/checks/timeliness/engine.py +36 -0
- eazydatafix/assessment/checks/timeliness/future_date_check.py +63 -0
- eazydatafix/assessment/checks/timeliness/stale_data_check.py +68 -0
- eazydatafix/assessment/checks/uniqueness.py +42 -0
- eazydatafix/assessment/checks/validity/__init__.py +0 -0
- eazydatafix/assessment/checks/validity/aadhaar_check.py +63 -0
- eazydatafix/assessment/checks/validity/credit_card_check.py +91 -0
- eazydatafix/assessment/checks/validity/date_check.py +65 -0
- eazydatafix/assessment/checks/validity/email_check.py +60 -0
- eazydatafix/assessment/checks/validity/engine.py +48 -0
- eazydatafix/assessment/checks/validity/gstin_check.py +65 -0
- eazydatafix/assessment/checks/validity/ip_address_check.py +63 -0
- eazydatafix/assessment/checks/validity/pan_check.py +62 -0
- eazydatafix/assessment/checks/validity/phone_check.py +66 -0
- eazydatafix/assessment/checks/validity/pincode_check.py +65 -0
- eazydatafix/assessment/checks/validity/url_check.py +66 -0
- eazydatafix/assessment/engine.py +135 -0
- eazydatafix/assessment/engines/__init__.py +0 -0
- eazydatafix/assessment/profiler.py +35 -0
- eazydatafix/console_report.py +171 -0
- eazydatafix/contracts/__init__.py +0 -0
- eazydatafix/contracts/check.py +24 -0
- eazydatafix/contracts/fix_step.py +23 -0
- eazydatafix/contracts/fix_strategy.py +27 -0
- eazydatafix/core/column_profiler.py +150 -0
- eazydatafix/core/dataset_loader.py +12 -0
- eazydatafix/core/score_calculator.py +57 -0
- eazydatafix/core/type_mapper.py +34 -0
- eazydatafix/datasources/__init__.py +41 -0
- eazydatafix/datasources/base.py +46 -0
- eazydatafix/datasources/csv.py +29 -0
- eazydatafix/datasources/dataframe.py +23 -0
- eazydatafix/datasources/excel.py +29 -0
- eazydatafix/datasources/json.py +29 -0
- eazydatafix/datasources/loader.py +95 -0
- eazydatafix/datasources/parquet.py +41 -0
- eazydatafix/datasources/registry.py +49 -0
- eazydatafix/diagnosis/__init__.py +0 -0
- eazydatafix/diagnosis/engine.py +41 -0
- eazydatafix/diagnosis/report.py +0 -0
- eazydatafix/enums/__init__.py +0 -0
- eazydatafix/enums/data_type.py +17 -0
- eazydatafix/exceptions.py +16 -0
- eazydatafix/fix/__init__.py +0 -0
- eazydatafix/fix/column_normalizer.py +47 -0
- eazydatafix/fix/datatype_converter.py +57 -0
- eazydatafix/fix/duplicate_remover.py +32 -0
- eazydatafix/fix/empty_column_remover.py +34 -0
- eazydatafix/fix/empty_row_remover.py +33 -0
- eazydatafix/fix/engine.py +86 -0
- eazydatafix/fix/strategies/__init__.py +0 -0
- eazydatafix/fix/strategies/base.py +20 -0
- eazydatafix/fix/strategies/drop.py +37 -0
- eazydatafix/fix/strategies/factory.py +32 -0
- eazydatafix/fix/strategies/mean.py +44 -0
- eazydatafix/fix/strategies/median.py +44 -0
- eazydatafix/fix/strategies/mode.py +35 -0
- eazydatafix/fix/strategies/register.py +53 -0
- eazydatafix/fix/strategies/smart.py +102 -0
- eazydatafix/fix/strategies.py +0 -0
- eazydatafix/fix/whitespace_trimmer.py +33 -0
- eazydatafix/models/__init__.py +0 -0
- eazydatafix/models/assessment_report.py +102 -0
- eazydatafix/models/comparison_report.py +38 -0
- eazydatafix/models/dataset_info.py +13 -0
- eazydatafix/models/dataset_profile.py +23 -0
- eazydatafix/models/diagnosis_issue.py +14 -0
- eazydatafix/models/diagnosis_report.py +56 -0
- eazydatafix/models/fix_config.py +18 -0
- eazydatafix/models/fix_result.py +57 -0
- eazydatafix/models/quality_dimensions.py +30 -0
- eazydatafix/models/quality_score.py +11 -0
- eazydatafix/models/recommendation.py +14 -0
- eazydatafix/models/validation_result.py +13 -0
- eazydatafix/plugins/__init__.py +17 -0
- eazydatafix/plugins/base.py +24 -0
- eazydatafix/plugins/defaults.py +32 -0
- eazydatafix/plugins/registry.py +60 -0
- eazydatafix/prepare/__init__.py +0 -0
- eazydatafix/prepare/engine.py +153 -0
- eazydatafix/prepare/steps/__init__.py +0 -0
- eazydatafix/prepare/steps/optimize_dtypes.py +0 -0
- eazydatafix/recommendations/__init__.py +0 -0
- eazydatafix/recommendations/engine.py +157 -0
- eazydatafix/rendering/__init__.py +0 -0
- eazydatafix/rendering/console.py +69 -0
- eazydatafix/reporting/__init__.py +0 -0
- eazydatafix/reporting/csv_report.py +159 -0
- eazydatafix/reporting/excel_report.py +225 -0
- eazydatafix/reporting/html_report.py +131 -0
- eazydatafix/reporting/json_report.py +65 -0
- eazydatafix/reporting/markdown_report.py +126 -0
- eazydatafix/reporting/pdf_report.py +270 -0
- eazydatafix/reporting/templates/report.html +272 -0
- eazydatafix/validation/__init__.py +0 -0
- eazydatafix/validation/engine.py +48 -0
- eazydatafix-0.2.0.dist-info/METADATA +257 -0
- eazydatafix-0.2.0.dist-info/RECORD +114 -0
- eazydatafix-0.2.0.dist-info/WHEEL +5 -0
- eazydatafix-0.2.0.dist-info/licenses/LICENSE +21 -0
- eazydatafix-0.2.0.dist-info/top_level.txt +1 -0
eazydatafix/__init__.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
from .assessment.engine import AssessmentEngine
|
|
2
|
+
from .assessment.profiler import DatasetProfiler
|
|
3
|
+
from .console_report import Report
|
|
4
|
+
from .fix.engine import FixEngine
|
|
5
|
+
from .models.fix_config import FixConfig
|
|
6
|
+
from .prepare.engine import PrepareEngine
|
|
7
|
+
|
|
8
|
+
__version__ = "0.2.0"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def profile(dataset):
|
|
12
|
+
"""
|
|
13
|
+
Generate a structural profile for a dataset.
|
|
14
|
+
"""
|
|
15
|
+
profiler = DatasetProfiler()
|
|
16
|
+
return profiler.profile(dataset)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def assess(dataset):
|
|
20
|
+
"""
|
|
21
|
+
Assess the quality of a dataset.
|
|
22
|
+
"""
|
|
23
|
+
engine = AssessmentEngine()
|
|
24
|
+
return engine.assess(dataset)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def fix(dataset, config: FixConfig | None = None):
|
|
28
|
+
"""
|
|
29
|
+
Automatically clean a dataset.
|
|
30
|
+
"""
|
|
31
|
+
engine = FixEngine()
|
|
32
|
+
return engine.fix(dataset, config)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def analysis_ready(
|
|
36
|
+
dataset,
|
|
37
|
+
config: FixConfig | None = None,
|
|
38
|
+
):
|
|
39
|
+
"""
|
|
40
|
+
Clean and prepare a dataset for exploratory
|
|
41
|
+
data analysis (EDA).
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
cleaned = fix(
|
|
45
|
+
dataset,
|
|
46
|
+
config=config,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
engine = PrepareEngine()
|
|
50
|
+
|
|
51
|
+
return engine.prepare(
|
|
52
|
+
cleaned.dataframe,
|
|
53
|
+
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
|
|
3
|
+
from eazydatafix.assessment.checks.accuracy.numeric_range_check import (
|
|
4
|
+
NumericRangeCheck,
|
|
5
|
+
)
|
|
6
|
+
from eazydatafix.models.validation_result import ValidationResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class AccuracyEngine:
|
|
10
|
+
"""
|
|
11
|
+
Runs all accuracy checks.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
def __init__(self) -> None:
|
|
15
|
+
|
|
16
|
+
self._checks = [
|
|
17
|
+
NumericRangeCheck(),
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
def evaluate(
|
|
21
|
+
self,
|
|
22
|
+
df: pd.DataFrame,
|
|
23
|
+
) -> list[ValidationResult]:
|
|
24
|
+
|
|
25
|
+
results: list[ValidationResult] = []
|
|
26
|
+
|
|
27
|
+
for check in self._checks:
|
|
28
|
+
results.extend(
|
|
29
|
+
check.evaluate(df)
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
return results
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
|
|
3
|
+
from eazydatafix.models.validation_result import ValidationResult
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class NumericRangeCheck:
|
|
7
|
+
"""
|
|
8
|
+
Detects numeric values outside acceptable ranges.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
DEFAULT_RANGES = {
|
|
12
|
+
"age": (0, 120),
|
|
13
|
+
"salary": (0, 1_000_000_000),
|
|
14
|
+
"marks": (0, 100),
|
|
15
|
+
"percentage": (0, 100),
|
|
16
|
+
"score": (0, 100),
|
|
17
|
+
"rating": (0, 5),
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
def evaluate(
|
|
21
|
+
self,
|
|
22
|
+
df: pd.DataFrame,
|
|
23
|
+
) -> list[ValidationResult]:
|
|
24
|
+
|
|
25
|
+
results: list[ValidationResult] = []
|
|
26
|
+
|
|
27
|
+
for column in df.columns:
|
|
28
|
+
|
|
29
|
+
column_name = column.lower()
|
|
30
|
+
|
|
31
|
+
if column_name not in self.DEFAULT_RANGES:
|
|
32
|
+
continue
|
|
33
|
+
|
|
34
|
+
minimum, maximum = self.DEFAULT_RANGES[column_name]
|
|
35
|
+
|
|
36
|
+
invalid = 0
|
|
37
|
+
|
|
38
|
+
numeric_values = pd.to_numeric(
|
|
39
|
+
df[column],
|
|
40
|
+
errors="coerce",
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
for value in numeric_values.dropna():
|
|
44
|
+
|
|
45
|
+
if value < minimum or value > maximum:
|
|
46
|
+
invalid += 1
|
|
47
|
+
|
|
48
|
+
if invalid == 0:
|
|
49
|
+
|
|
50
|
+
results.append(
|
|
51
|
+
ValidationResult(
|
|
52
|
+
rule="Numeric Range",
|
|
53
|
+
column=column,
|
|
54
|
+
passed=True,
|
|
55
|
+
message="All values are within the expected range.",
|
|
56
|
+
)
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
else:
|
|
60
|
+
|
|
61
|
+
results.append(
|
|
62
|
+
ValidationResult(
|
|
63
|
+
rule="Numeric Range",
|
|
64
|
+
column=column,
|
|
65
|
+
passed=False,
|
|
66
|
+
message=f"{invalid} value(s) outside the expected range.",
|
|
67
|
+
)
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
return results
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
|
|
3
|
+
import pandas as pd
|
|
4
|
+
|
|
5
|
+
from eazydatafix.contracts.check import Check
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass(slots=True)
|
|
9
|
+
class CompletenessResult:
|
|
10
|
+
"""
|
|
11
|
+
Represents the completeness assessment result.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
total_missing_values: int
|
|
15
|
+
completeness_score: float
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class CompletenessCheck(Check):
|
|
19
|
+
"""
|
|
20
|
+
Evaluates dataset completeness.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
@property
|
|
24
|
+
def name(self) -> str:
|
|
25
|
+
return "Completeness"
|
|
26
|
+
|
|
27
|
+
def evaluate(self, df: pd.DataFrame) -> CompletenessResult:
|
|
28
|
+
total_cells = df.shape[0] * df.shape[1]
|
|
29
|
+
missing_values = int(df.isna().sum().sum())
|
|
30
|
+
|
|
31
|
+
score = (
|
|
32
|
+
100.0
|
|
33
|
+
if total_cells == 0
|
|
34
|
+
else ((total_cells - missing_values) / total_cells) * 100
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
return CompletenessResult(
|
|
38
|
+
total_missing_values=missing_values,
|
|
39
|
+
completeness_score=round(score, 2),
|
|
40
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
|
|
3
|
+
from eazydatafix.models.validation_result import ValidationResult
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class CaseConsistencyCheck:
|
|
7
|
+
"""
|
|
8
|
+
Detects inconsistent text casing.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
def evaluate(
|
|
12
|
+
self,
|
|
13
|
+
df: pd.DataFrame,
|
|
14
|
+
) -> list[ValidationResult]:
|
|
15
|
+
|
|
16
|
+
results: list[ValidationResult] = []
|
|
17
|
+
|
|
18
|
+
for column in df.columns:
|
|
19
|
+
|
|
20
|
+
if not (
|
|
21
|
+
pd.api.types.is_object_dtype(df[column])
|
|
22
|
+
or pd.api.types.is_string_dtype(df[column])
|
|
23
|
+
):
|
|
24
|
+
continue
|
|
25
|
+
|
|
26
|
+
values = (
|
|
27
|
+
df[column]
|
|
28
|
+
.dropna()
|
|
29
|
+
.astype(str)
|
|
30
|
+
.str.strip()
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
if values.empty:
|
|
34
|
+
continue
|
|
35
|
+
|
|
36
|
+
original = set(values)
|
|
37
|
+
|
|
38
|
+
normalized = {
|
|
39
|
+
value.lower()
|
|
40
|
+
for value in original
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if len(original) != len(normalized):
|
|
44
|
+
|
|
45
|
+
results.append(
|
|
46
|
+
ValidationResult(
|
|
47
|
+
rule="Case Consistency",
|
|
48
|
+
column=column,
|
|
49
|
+
passed=False,
|
|
50
|
+
message="Mixed letter casing detected.",
|
|
51
|
+
)
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
else:
|
|
55
|
+
|
|
56
|
+
results.append(
|
|
57
|
+
ValidationResult(
|
|
58
|
+
rule="Case Consistency",
|
|
59
|
+
column=column,
|
|
60
|
+
passed=True,
|
|
61
|
+
message="Consistent letter casing.",
|
|
62
|
+
)
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
return results
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
|
|
3
|
+
from eazydatafix.models.validation_result import ValidationResult
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class DuplicateTextCheck:
|
|
7
|
+
"""
|
|
8
|
+
Detects duplicate text values in string columns.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
def evaluate(
|
|
12
|
+
self,
|
|
13
|
+
df: pd.DataFrame,
|
|
14
|
+
) -> list[ValidationResult]:
|
|
15
|
+
|
|
16
|
+
results: list[ValidationResult] = []
|
|
17
|
+
|
|
18
|
+
for column in df.columns:
|
|
19
|
+
|
|
20
|
+
if not (
|
|
21
|
+
pd.api.types.is_object_dtype(df[column])
|
|
22
|
+
or pd.api.types.is_string_dtype(df[column])
|
|
23
|
+
):
|
|
24
|
+
continue
|
|
25
|
+
|
|
26
|
+
values = (
|
|
27
|
+
df[column]
|
|
28
|
+
.dropna()
|
|
29
|
+
.astype(str)
|
|
30
|
+
.str.strip()
|
|
31
|
+
.str.lower()
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
duplicate_count = int(values.duplicated().sum())
|
|
35
|
+
|
|
36
|
+
if duplicate_count == 0:
|
|
37
|
+
|
|
38
|
+
results.append(
|
|
39
|
+
ValidationResult(
|
|
40
|
+
rule="Duplicate Text",
|
|
41
|
+
column=column,
|
|
42
|
+
passed=True,
|
|
43
|
+
message="No duplicate text values found.",
|
|
44
|
+
)
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
else:
|
|
48
|
+
|
|
49
|
+
results.append(
|
|
50
|
+
ValidationResult(
|
|
51
|
+
rule="Duplicate Text",
|
|
52
|
+
column=column,
|
|
53
|
+
passed=False,
|
|
54
|
+
message=f"{duplicate_count} duplicate value(s) found.",
|
|
55
|
+
)
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
return results
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
|
|
3
|
+
from eazydatafix.assessment.checks.consistency.case_consistency_check import (
|
|
4
|
+
CaseConsistencyCheck,
|
|
5
|
+
)
|
|
6
|
+
from eazydatafix.assessment.checks.consistency.duplicate_text_check import (
|
|
7
|
+
DuplicateTextCheck,
|
|
8
|
+
)
|
|
9
|
+
from eazydatafix.assessment.checks.consistency.whitespace_consistency_check import (
|
|
10
|
+
WhitespaceConsistencyCheck,
|
|
11
|
+
)
|
|
12
|
+
from eazydatafix.models.validation_result import ValidationResult
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class ConsistencyEngine:
|
|
16
|
+
"""
|
|
17
|
+
Runs all consistency checks.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
def __init__(self) -> None:
|
|
21
|
+
|
|
22
|
+
self._checks = [
|
|
23
|
+
CaseConsistencyCheck(),
|
|
24
|
+
WhitespaceConsistencyCheck(),
|
|
25
|
+
DuplicateTextCheck(),
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
def evaluate(
|
|
29
|
+
self,
|
|
30
|
+
df: pd.DataFrame,
|
|
31
|
+
) -> list[ValidationResult]:
|
|
32
|
+
|
|
33
|
+
results: list[ValidationResult] = []
|
|
34
|
+
|
|
35
|
+
for check in self._checks:
|
|
36
|
+
results.extend(
|
|
37
|
+
check.evaluate(df)
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
return results
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
|
|
3
|
+
from eazydatafix.models.validation_result import ValidationResult
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class WhitespaceConsistencyCheck:
|
|
7
|
+
"""
|
|
8
|
+
Detects leading/trailing whitespaces in text columns.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
def evaluate(
|
|
12
|
+
self,
|
|
13
|
+
df: pd.DataFrame,
|
|
14
|
+
) -> list[ValidationResult]:
|
|
15
|
+
|
|
16
|
+
results: list[ValidationResult] = []
|
|
17
|
+
|
|
18
|
+
for column in df.columns:
|
|
19
|
+
|
|
20
|
+
if not (
|
|
21
|
+
pd.api.types.is_object_dtype(df[column])
|
|
22
|
+
or pd.api.types.is_string_dtype(df[column])
|
|
23
|
+
):
|
|
24
|
+
continue
|
|
25
|
+
|
|
26
|
+
whitespace_count = 0
|
|
27
|
+
|
|
28
|
+
for value in df[column].dropna():
|
|
29
|
+
|
|
30
|
+
value = str(value)
|
|
31
|
+
|
|
32
|
+
if value != value.strip():
|
|
33
|
+
whitespace_count += 1
|
|
34
|
+
|
|
35
|
+
if whitespace_count == 0:
|
|
36
|
+
|
|
37
|
+
results.append(
|
|
38
|
+
ValidationResult(
|
|
39
|
+
rule="Whitespace Consistency",
|
|
40
|
+
column=column,
|
|
41
|
+
passed=True,
|
|
42
|
+
message="No leading/trailing whitespaces found.",
|
|
43
|
+
)
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
else:
|
|
47
|
+
|
|
48
|
+
results.append(
|
|
49
|
+
ValidationResult(
|
|
50
|
+
rule="Whitespace Consistency",
|
|
51
|
+
column=column,
|
|
52
|
+
passed=False,
|
|
53
|
+
message=f"{whitespace_count} value(s) contain leading/trailing whitespaces.",
|
|
54
|
+
)
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
return results
|
|
File without changes
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
|
|
3
|
+
from eazydatafix.assessment.checks.timeliness.future_date_check import (
|
|
4
|
+
FutureDateCheck,
|
|
5
|
+
)
|
|
6
|
+
from eazydatafix.assessment.checks.timeliness.stale_data_check import (
|
|
7
|
+
StaleDataCheck,
|
|
8
|
+
)
|
|
9
|
+
from eazydatafix.models.validation_result import ValidationResult
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class TimelinessEngine:
|
|
13
|
+
"""
|
|
14
|
+
Runs all timeliness checks.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def __init__(self) -> None:
|
|
18
|
+
|
|
19
|
+
self._checks = [
|
|
20
|
+
FutureDateCheck(),
|
|
21
|
+
StaleDataCheck(),
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
def evaluate(
|
|
25
|
+
self,
|
|
26
|
+
df: pd.DataFrame,
|
|
27
|
+
) -> list[ValidationResult]:
|
|
28
|
+
|
|
29
|
+
results: list[ValidationResult] = []
|
|
30
|
+
|
|
31
|
+
for check in self._checks:
|
|
32
|
+
results.extend(
|
|
33
|
+
check.evaluate(df)
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
return results
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
|
|
3
|
+
import pandas as pd
|
|
4
|
+
|
|
5
|
+
from eazydatafix.models.validation_result import ValidationResult
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class FutureDateCheck:
|
|
9
|
+
"""
|
|
10
|
+
Detects dates that occur in the future.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
def evaluate(
|
|
14
|
+
self,
|
|
15
|
+
df: pd.DataFrame,
|
|
16
|
+
) -> list[ValidationResult]:
|
|
17
|
+
|
|
18
|
+
results: list[ValidationResult] = []
|
|
19
|
+
|
|
20
|
+
today = pd.Timestamp(datetime.today().date())
|
|
21
|
+
|
|
22
|
+
for column in df.columns:
|
|
23
|
+
|
|
24
|
+
column_name = column.lower()
|
|
25
|
+
|
|
26
|
+
if (
|
|
27
|
+
"date" not in column_name
|
|
28
|
+
and "joining" not in column_name
|
|
29
|
+
and "dob" not in column_name
|
|
30
|
+
and "birth" not in column_name
|
|
31
|
+
):
|
|
32
|
+
continue
|
|
33
|
+
|
|
34
|
+
dates = pd.to_datetime(
|
|
35
|
+
df[column],
|
|
36
|
+
errors="coerce",
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
future_count = int((dates > today).sum())
|
|
40
|
+
|
|
41
|
+
if future_count == 0:
|
|
42
|
+
|
|
43
|
+
results.append(
|
|
44
|
+
ValidationResult(
|
|
45
|
+
rule="Future Date",
|
|
46
|
+
column=column,
|
|
47
|
+
passed=True,
|
|
48
|
+
message="No future dates found.",
|
|
49
|
+
)
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
else:
|
|
53
|
+
|
|
54
|
+
results.append(
|
|
55
|
+
ValidationResult(
|
|
56
|
+
rule="Future Date",
|
|
57
|
+
column=column,
|
|
58
|
+
passed=False,
|
|
59
|
+
message=f"{future_count} future date(s) found.",
|
|
60
|
+
)
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
return results
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
|
|
3
|
+
import pandas as pd
|
|
4
|
+
|
|
5
|
+
from eazydatafix.models.validation_result import ValidationResult
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class StaleDataCheck:
|
|
9
|
+
"""
|
|
10
|
+
Detects stale data based on configurable age.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
def evaluate(
|
|
14
|
+
self,
|
|
15
|
+
df: pd.DataFrame,
|
|
16
|
+
threshold_days: int = 365,
|
|
17
|
+
) -> list[ValidationResult]:
|
|
18
|
+
|
|
19
|
+
results: list[ValidationResult] = []
|
|
20
|
+
|
|
21
|
+
today = pd.Timestamp(datetime.today().date())
|
|
22
|
+
|
|
23
|
+
for column in df.columns:
|
|
24
|
+
|
|
25
|
+
column_name = column.lower()
|
|
26
|
+
|
|
27
|
+
if not (
|
|
28
|
+
"updated" in column_name
|
|
29
|
+
or "modified" in column_name
|
|
30
|
+
or "last_updated" in column_name
|
|
31
|
+
or "lastmodified" in column_name
|
|
32
|
+
):
|
|
33
|
+
continue
|
|
34
|
+
|
|
35
|
+
dates = pd.to_datetime(
|
|
36
|
+
df[column],
|
|
37
|
+
errors="coerce",
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
stale_count = int(
|
|
41
|
+
(
|
|
42
|
+
(today - dates).dt.days > threshold_days
|
|
43
|
+
).sum()
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
if stale_count == 0:
|
|
47
|
+
|
|
48
|
+
results.append(
|
|
49
|
+
ValidationResult(
|
|
50
|
+
rule="Stale Data",
|
|
51
|
+
column=column,
|
|
52
|
+
passed=True,
|
|
53
|
+
message="No stale records found.",
|
|
54
|
+
)
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
else:
|
|
58
|
+
|
|
59
|
+
results.append(
|
|
60
|
+
ValidationResult(
|
|
61
|
+
rule="Stale Data",
|
|
62
|
+
column=column,
|
|
63
|
+
passed=False,
|
|
64
|
+
message=f"{stale_count} stale record(s) found.",
|
|
65
|
+
)
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
return results
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
|
|
3
|
+
import pandas as pd
|
|
4
|
+
|
|
5
|
+
from eazydatafix.contracts.check import Check
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass(slots=True)
|
|
9
|
+
class UniquenessResult:
|
|
10
|
+
"""
|
|
11
|
+
Represents the uniqueness assessment result.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
total_rows: int
|
|
15
|
+
duplicate_rows: int
|
|
16
|
+
uniqueness_score: float
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class UniquenessCheck(Check):
|
|
20
|
+
"""
|
|
21
|
+
Evaluates dataset uniqueness.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
@property
|
|
25
|
+
def name(self) -> str:
|
|
26
|
+
return "Uniqueness"
|
|
27
|
+
|
|
28
|
+
def evaluate(self, df: pd.DataFrame) -> UniquenessResult:
|
|
29
|
+
total_rows = len(df)
|
|
30
|
+
duplicate_rows = int(df.duplicated().sum())
|
|
31
|
+
|
|
32
|
+
score = (
|
|
33
|
+
100.0
|
|
34
|
+
if total_rows == 0
|
|
35
|
+
else ((total_rows - duplicate_rows) / total_rows) * 100
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
return UniquenessResult(
|
|
39
|
+
total_rows=total_rows,
|
|
40
|
+
duplicate_rows=duplicate_rows,
|
|
41
|
+
uniqueness_score=round(score, 2),
|
|
42
|
+
)
|
|
File without changes
|