devg-humanerror 0.1.0__tar.gz
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.
- devg_humanerror-0.1.0/LICENSE.txt +21 -0
- devg_humanerror-0.1.0/PKG-INFO +43 -0
- devg_humanerror-0.1.0/README.md +32 -0
- devg_humanerror-0.1.0/README.txt +0 -0
- devg_humanerror-0.1.0/devg_humanerror/__init__.py +1 -0
- devg_humanerror-0.1.0/devg_humanerror/core.py +138 -0
- devg_humanerror-0.1.0/devg_humanerror/correctors.py +2 -0
- devg_humanerror-0.1.0/devg_humanerror/detectors.py +2 -0
- devg_humanerror-0.1.0/devg_humanerror/diagnostics.py +8 -0
- devg_humanerror-0.1.0/devg_humanerror.egg-info/PKG-INFO +43 -0
- devg_humanerror-0.1.0/devg_humanerror.egg-info/SOURCES.txt +15 -0
- devg_humanerror-0.1.0/devg_humanerror.egg-info/dependency_links.txt +1 -0
- devg_humanerror-0.1.0/devg_humanerror.egg-info/top_level.txt +1 -0
- devg_humanerror-0.1.0/pyproject.toml +13 -0
- devg_humanerror-0.1.0/setup.cfg +4 -0
- devg_humanerror-0.1.0/tests/test_core.py +12 -0
- devg_humanerror-0.1.0/tests/test_package.py +35 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dev Ganjawalla
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: devg-humanerror
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Automatic correction of human-entry errors in tabular data
|
|
5
|
+
Author: Dev Ganjawalla
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: >=3.8
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE.txt
|
|
10
|
+
Dynamic: license-file
|
|
11
|
+
|
|
12
|
+
\# devg-humanerror
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
A tiny Python library to rescue your datasets from human data-entry errors š
|
|
17
|
+
|
|
18
|
+
Created by Dev Ganjawalla because finger slips happen.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
\## Features
|
|
23
|
+
|
|
24
|
+
\- Detect repeated digits like 777 ā 77.7
|
|
25
|
+
|
|
26
|
+
\- Leading-digit corrections like 222 ā 122
|
|
27
|
+
|
|
28
|
+
\- Prechecks for symmetry, moderate spread, unimodal clusters
|
|
29
|
+
|
|
30
|
+
\- Temperature parameter to adjust aggressiveness
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
\## Installation
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
|
|
40
|
+
pip install devg-humanerror
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
\# devg-humanerror
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
A tiny Python library to rescue your datasets from human data-entry errors š
|
|
6
|
+
|
|
7
|
+
Created by Dev Ganjawalla because finger slips happen.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
\## Features
|
|
12
|
+
|
|
13
|
+
\- Detect repeated digits like 777 ā 77.7
|
|
14
|
+
|
|
15
|
+
\- Leading-digit corrections like 222 ā 122
|
|
16
|
+
|
|
17
|
+
\- Prechecks for symmetry, moderate spread, unimodal clusters
|
|
18
|
+
|
|
19
|
+
\- Temperature parameter to adjust aggressiveness
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
\## Installation
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
|
|
29
|
+
pip install devg-humanerror
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .core import SafeCorrector
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Core logic for devg_humanerror.
|
|
3
|
+
A lightweight, transparent heuristic to detect and correct likely
|
|
4
|
+
human data-entry mistakes (e.g., finger slips like 222 ā 122 or 777 ā 77.7).
|
|
5
|
+
|
|
6
|
+
This is designed for tabular numeric columns (e.g., lab values).
|
|
7
|
+
It is heuristic ā not a statistical guarantee.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import pandas as pd
|
|
11
|
+
import numpy as np
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class SafeCorrector:
|
|
15
|
+
def __init__(self, temperature: float = 1.0):
|
|
16
|
+
"""
|
|
17
|
+
Parameters
|
|
18
|
+
----------
|
|
19
|
+
temperature : float
|
|
20
|
+
Controls how aggressive the corrections are.
|
|
21
|
+
> 1.0 ā more tolerant (fewer corrections)
|
|
22
|
+
< 1.0 ā more aggressive (more corrections)
|
|
23
|
+
"""
|
|
24
|
+
self.temperature = float(temperature)
|
|
25
|
+
|
|
26
|
+
# ---------- PRECHECKS ----------
|
|
27
|
+
def _data_ok_for_correction(self, s: pd.Series) -> bool:
|
|
28
|
+
"""
|
|
29
|
+
Decide whether a column is reasonable to run human-error corrections on.
|
|
30
|
+
Returns False if data look too pathological (very skewed, multimodal, or extreme spread).
|
|
31
|
+
"""
|
|
32
|
+
s = s.dropna()
|
|
33
|
+
if len(s) < 5:
|
|
34
|
+
return False
|
|
35
|
+
|
|
36
|
+
mean = s.mean()
|
|
37
|
+
std = s.std()
|
|
38
|
+
median = s.median()
|
|
39
|
+
|
|
40
|
+
# 1) avoid near-zero means (ratios, percentages, etc.)
|
|
41
|
+
if abs(mean) < 1e-6:
|
|
42
|
+
return False
|
|
43
|
+
|
|
44
|
+
# 2) reject extremely skewed data
|
|
45
|
+
skew = s.skew()
|
|
46
|
+
if abs(skew) > 2:
|
|
47
|
+
return False
|
|
48
|
+
|
|
49
|
+
# 3) reject columns with extreme spread
|
|
50
|
+
if std > abs(mean) * 3:
|
|
51
|
+
return False
|
|
52
|
+
|
|
53
|
+
# 4) require that most values cluster around median
|
|
54
|
+
within_range = ((s >= median * 0.5) & (s <= median * 1.5)).mean()
|
|
55
|
+
if within_range < 0.6:
|
|
56
|
+
return False
|
|
57
|
+
|
|
58
|
+
return True
|
|
59
|
+
|
|
60
|
+
# ---------- CANDIDATE GENERATION ----------
|
|
61
|
+
def _candidates(self, x: float) -> list[float]:
|
|
62
|
+
"""Generate plausible human-error corrections for a single value."""
|
|
63
|
+
cands = []
|
|
64
|
+
|
|
65
|
+
# 1) divide by 10 (e.g., 222 ā 22.2)
|
|
66
|
+
cands.append(x / 10)
|
|
67
|
+
|
|
68
|
+
# 2) decrease the left-most digit by 1 (e.g., 222 ā 122)
|
|
69
|
+
s = str(int(round(x)))
|
|
70
|
+
if len(s) > 1 and s.isdigit():
|
|
71
|
+
first = str(max(0, int(s[0]) - 1))
|
|
72
|
+
cands.append(float(first + s[1:]))
|
|
73
|
+
|
|
74
|
+
# 3) increase the left-most digit by 1 (in case the error went the other way)
|
|
75
|
+
if len(s) > 1 and s.isdigit():
|
|
76
|
+
first = str(int(s[0]) + 1)
|
|
77
|
+
cands.append(float(first + s[1:]))
|
|
78
|
+
|
|
79
|
+
# 4) handle repeated digits like 777 ā 77.7
|
|
80
|
+
if len(s) >= 3 and len(set(s)) == 1:
|
|
81
|
+
cands.append(x / 10)
|
|
82
|
+
cands.append(float(s[:-1]))
|
|
83
|
+
|
|
84
|
+
return list(set(cands))
|
|
85
|
+
|
|
86
|
+
# ---------- CHOOSE BEST CANDIDATE ----------
|
|
87
|
+
def _pick_best(self, x: float, mean: float, cands: list[float]) -> float:
|
|
88
|
+
"""
|
|
89
|
+
Pick the candidate closest to the column mean.
|
|
90
|
+
Apply temperature scaling to avoid over-correction.
|
|
91
|
+
"""
|
|
92
|
+
if not cands:
|
|
93
|
+
return x
|
|
94
|
+
|
|
95
|
+
# distance to mean
|
|
96
|
+
dists = [abs(c - mean) for c in cands]
|
|
97
|
+
best = cands[int(np.argmin(dists))]
|
|
98
|
+
|
|
99
|
+
# if correction is too far from original, keep original
|
|
100
|
+
if abs(best - x) > abs(mean) * 2 * self.temperature:
|
|
101
|
+
return x
|
|
102
|
+
return best
|
|
103
|
+
|
|
104
|
+
# ---------- PUBLIC API ----------
|
|
105
|
+
def fit_transform(self, df: pd.DataFrame) -> pd.DataFrame:
|
|
106
|
+
"""
|
|
107
|
+
Apply human-error correction column-wise to numeric columns.
|
|
108
|
+
Non-numeric columns are left unchanged.
|
|
109
|
+
Returns a corrected copy of the dataframe.
|
|
110
|
+
"""
|
|
111
|
+
df = df.copy()
|
|
112
|
+
|
|
113
|
+
for col in df.columns:
|
|
114
|
+
if not pd.api.types.is_numeric_dtype(df[col]):
|
|
115
|
+
continue
|
|
116
|
+
|
|
117
|
+
s = df[col].astype(float)
|
|
118
|
+
if not self._data_ok_for_correction(s):
|
|
119
|
+
continue
|
|
120
|
+
|
|
121
|
+
mean = s.mean()
|
|
122
|
+
corrected = []
|
|
123
|
+
|
|
124
|
+
for x in s:
|
|
125
|
+
if pd.isna(x):
|
|
126
|
+
corrected.append(np.nan)
|
|
127
|
+
continue
|
|
128
|
+
|
|
129
|
+
# flag potential outlier: > 2*mean or < 0.5*mean
|
|
130
|
+
if x > 2 * mean or x < 0.5 * mean:
|
|
131
|
+
cands = self._candidates(x)
|
|
132
|
+
corrected.append(self._pick_best(x, mean, cands))
|
|
133
|
+
else:
|
|
134
|
+
corrected.append(x)
|
|
135
|
+
|
|
136
|
+
df[col] = corrected
|
|
137
|
+
|
|
138
|
+
return df
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: devg-humanerror
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Automatic correction of human-entry errors in tabular data
|
|
5
|
+
Author: Dev Ganjawalla
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: >=3.8
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE.txt
|
|
10
|
+
Dynamic: license-file
|
|
11
|
+
|
|
12
|
+
\# devg-humanerror
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
A tiny Python library to rescue your datasets from human data-entry errors š
|
|
17
|
+
|
|
18
|
+
Created by Dev Ganjawalla because finger slips happen.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
\## Features
|
|
23
|
+
|
|
24
|
+
\- Detect repeated digits like 777 ā 77.7
|
|
25
|
+
|
|
26
|
+
\- Leading-digit corrections like 222 ā 122
|
|
27
|
+
|
|
28
|
+
\- Prechecks for symmetry, moderate spread, unimodal clusters
|
|
29
|
+
|
|
30
|
+
\- Temperature parameter to adjust aggressiveness
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
\## Installation
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
|
|
40
|
+
pip install devg-humanerror
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
LICENSE.txt
|
|
2
|
+
README.md
|
|
3
|
+
README.txt
|
|
4
|
+
pyproject.toml
|
|
5
|
+
devg_humanerror/__init__.py
|
|
6
|
+
devg_humanerror/core.py
|
|
7
|
+
devg_humanerror/correctors.py
|
|
8
|
+
devg_humanerror/detectors.py
|
|
9
|
+
devg_humanerror/diagnostics.py
|
|
10
|
+
devg_humanerror.egg-info/PKG-INFO
|
|
11
|
+
devg_humanerror.egg-info/SOURCES.txt
|
|
12
|
+
devg_humanerror.egg-info/dependency_links.txt
|
|
13
|
+
devg_humanerror.egg-info/top_level.txt
|
|
14
|
+
tests/test_core.py
|
|
15
|
+
tests/test_package.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
devg_humanerror
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=42"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "devg-humanerror"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Automatic correction of human-entry errors in tabular data"
|
|
9
|
+
authors = [{name="Dev Ganjawalla"}]
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
requires-python = ">=3.8"
|
|
12
|
+
license = {text = "MIT"}
|
|
13
|
+
dependencies = []
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from devg_humanerror import safe_corrector, prechecks, candidate_fixes
|
|
2
|
+
|
|
3
|
+
# Example: call a simple function from safe_corrector
|
|
4
|
+
print(safe_corrector.example_function())
|
|
5
|
+
|
|
6
|
+
# Run a precheck
|
|
7
|
+
print(prechecks.check_all())
|
|
8
|
+
|
|
9
|
+
# Generate candidate fixes
|
|
10
|
+
fixes = candidate_fixes.generate_candidates("some error input")
|
|
11
|
+
print(fixes)
|
|
12
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# tests/test_package.py
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
# Add parent folder to path so Python can find devg_humanerror
|
|
7
|
+
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
|
8
|
+
|
|
9
|
+
# Import the function after fixing path
|
|
10
|
+
from devg_humanerror.diagnostics import generate_candidates
|
|
11
|
+
|
|
12
|
+
# --- Test functions ---
|
|
13
|
+
def test_core():
|
|
14
|
+
print("Core module is working")
|
|
15
|
+
|
|
16
|
+
def test_correctors():
|
|
17
|
+
print("Correctors module is working")
|
|
18
|
+
|
|
19
|
+
def test_detectors():
|
|
20
|
+
print("Detectors precheck OK")
|
|
21
|
+
|
|
22
|
+
def test_diagnostics():
|
|
23
|
+
try:
|
|
24
|
+
result = generate_candidates("sample input")
|
|
25
|
+
print("Diagnostics module working, output:", result)
|
|
26
|
+
except AttributeError as e:
|
|
27
|
+
print("ERROR in diagnostics:", e)
|
|
28
|
+
|
|
29
|
+
# --- Run all tests ---
|
|
30
|
+
if __name__ == "__main__":
|
|
31
|
+
test_core()
|
|
32
|
+
test_correctors()
|
|
33
|
+
test_detectors()
|
|
34
|
+
test_diagnostics()
|
|
35
|
+
print("\nā
All tests completed!")
|