unique-sheetreview 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.
- unique_sheetreview-0.1.0/LICENSE +21 -0
- unique_sheetreview-0.1.0/PKG-INFO +81 -0
- unique_sheetreview-0.1.0/README.md +66 -0
- unique_sheetreview-0.1.0/pyproject.toml +20 -0
- unique_sheetreview-0.1.0/setup.cfg +4 -0
- unique_sheetreview-0.1.0/tests/test_scan.py +49 -0
- unique_sheetreview-0.1.0/unique_sheetreview/__init__.py +159 -0
- unique_sheetreview-0.1.0/unique_sheetreview.egg-info/PKG-INFO +81 -0
- unique_sheetreview-0.1.0/unique_sheetreview.egg-info/SOURCES.txt +10 -0
- unique_sheetreview-0.1.0/unique_sheetreview.egg-info/dependency_links.txt +1 -0
- unique_sheetreview-0.1.0/unique_sheetreview.egg-info/requires.txt +2 -0
- unique_sheetreview-0.1.0/unique_sheetreview.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Unique50101
|
|
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,81 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: unique-sheetreview
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Scan CSV and Excel files and mark data quality issues directly on a review copy.
|
|
5
|
+
Author: Unique50101
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Repository, https://github.com/Unique50101/unique-sheetreview
|
|
8
|
+
Project-URL: Issues, https://github.com/Unique50101/unique-sheetreview/issues
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: openpyxl<4,>=3.1.5
|
|
13
|
+
Requires-Dist: defusedxml>=0.7.1
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# SheetReview
|
|
17
|
+
|
|
18
|
+
Give SheetReview a CSV or Excel file and get a list of data-quality issues with the sheet, cell, priority, and suggested fix. Export the findings as an Excel copy with highlighted cells and comments for the person who supplied the data.
|
|
19
|
+
|
|
20
|
+
## Quick start
|
|
21
|
+
|
|
22
|
+
Requires Python 3.10 or later.
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
python -m pip install unique-sheetreview
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from unique_sheetreview import scan
|
|
30
|
+
|
|
31
|
+
report = scan("orders.xlsx")
|
|
32
|
+
print(report)
|
|
33
|
+
report.save_review_copy("orders_review.xlsx")
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Try the sample
|
|
37
|
+
|
|
38
|
+
From the repository root, use the included [orders.csv](examples/orders.csv). For this example, each row must have a distinct order ID.
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from unique_sheetreview import scan
|
|
42
|
+
|
|
43
|
+
report = scan("examples/orders.csv", required=["OrderID"], unique=["OrderID"])
|
|
44
|
+
print(report)
|
|
45
|
+
report.save_review_copy("orders_review.xlsx")
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The sample produces **3 High, 1 Moderate, and 1 Low** findings.
|
|
49
|
+
|
|
50
|
+
| Priority | Cells | Finding |
|
|
51
|
+
| --- | --- | --- |
|
|
52
|
+
| High | A2, A3 | Order ID 101 occurs twice. |
|
|
53
|
+
| High | A4 | A required order ID is missing. |
|
|
54
|
+
| Moderate | B2 | 04/05/2026 has two possible day/month interpretations. |
|
|
55
|
+
| Low | C2 | The name has a leading space. |
|
|
56
|
+
|
|
57
|
+
## Checks
|
|
58
|
+
|
|
59
|
+
| Priority | What the scanner checks |
|
|
60
|
+
| --- | --- |
|
|
61
|
+
| High | Missing or duplicate headers, absent rule columns, empty required values, repeated values in declared unique columns, stored Excel error cells |
|
|
62
|
+
| Moderate | Ambiguous slash dates, numeric text in Excel amount, price, cost, quantity, total, revenue, or balance columns |
|
|
63
|
+
| Low | Blank rows and surrounding whitespace in text values |
|
|
64
|
+
|
|
65
|
+
Use `report.findings` to integrate with an upload form. Each finding has `severity`, `sheet`, `cell`, `code`, and `message`. Use `scan(path, sheet="Orders")` to restrict an Excel scan to one worksheet. By default the scanner runs on all worksheets, applying the same rules to each. Header rule names ignore case and surrounding spaces. Unique checks compare typed values exactly and skip blanks. Add a required rule when blanks should also be reported.
|
|
66
|
+
|
|
67
|
+
## Input and export behavior
|
|
68
|
+
|
|
69
|
+
- Supports comma-delimited UTF-8 CSV (including BOM) and ordinary .xlsx workbooks with headers in row one. Files are processed locally in memory.
|
|
70
|
+
- CSV identifiers keep their leading zeros. CSV values beginning with an equals sign remain literal text in the review workbook.
|
|
71
|
+
- The review copy uses a new .xlsx path and retains cell values. Review copies of complex workbooks are subject to openpyxl's format support. Formulas are preserved and are not evaluated.
|
|
72
|
+
- Review labels are based on the checks above. Business-specific rules, additional layouts, and large streaming inputs are outside this release.
|
|
73
|
+
|
|
74
|
+
## Development
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
python -m pip install -e .
|
|
78
|
+
python -m unittest discover -s tests -v
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Released under the [MIT license](LICENSE).
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# SheetReview
|
|
2
|
+
|
|
3
|
+
Give SheetReview a CSV or Excel file and get a list of data-quality issues with the sheet, cell, priority, and suggested fix. Export the findings as an Excel copy with highlighted cells and comments for the person who supplied the data.
|
|
4
|
+
|
|
5
|
+
## Quick start
|
|
6
|
+
|
|
7
|
+
Requires Python 3.10 or later.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
python -m pip install unique-sheetreview
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from unique_sheetreview import scan
|
|
15
|
+
|
|
16
|
+
report = scan("orders.xlsx")
|
|
17
|
+
print(report)
|
|
18
|
+
report.save_review_copy("orders_review.xlsx")
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Try the sample
|
|
22
|
+
|
|
23
|
+
From the repository root, use the included [orders.csv](examples/orders.csv). For this example, each row must have a distinct order ID.
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from unique_sheetreview import scan
|
|
27
|
+
|
|
28
|
+
report = scan("examples/orders.csv", required=["OrderID"], unique=["OrderID"])
|
|
29
|
+
print(report)
|
|
30
|
+
report.save_review_copy("orders_review.xlsx")
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The sample produces **3 High, 1 Moderate, and 1 Low** findings.
|
|
34
|
+
|
|
35
|
+
| Priority | Cells | Finding |
|
|
36
|
+
| --- | --- | --- |
|
|
37
|
+
| High | A2, A3 | Order ID 101 occurs twice. |
|
|
38
|
+
| High | A4 | A required order ID is missing. |
|
|
39
|
+
| Moderate | B2 | 04/05/2026 has two possible day/month interpretations. |
|
|
40
|
+
| Low | C2 | The name has a leading space. |
|
|
41
|
+
|
|
42
|
+
## Checks
|
|
43
|
+
|
|
44
|
+
| Priority | What the scanner checks |
|
|
45
|
+
| --- | --- |
|
|
46
|
+
| High | Missing or duplicate headers, absent rule columns, empty required values, repeated values in declared unique columns, stored Excel error cells |
|
|
47
|
+
| Moderate | Ambiguous slash dates, numeric text in Excel amount, price, cost, quantity, total, revenue, or balance columns |
|
|
48
|
+
| Low | Blank rows and surrounding whitespace in text values |
|
|
49
|
+
|
|
50
|
+
Use `report.findings` to integrate with an upload form. Each finding has `severity`, `sheet`, `cell`, `code`, and `message`. Use `scan(path, sheet="Orders")` to restrict an Excel scan to one worksheet. By default the scanner runs on all worksheets, applying the same rules to each. Header rule names ignore case and surrounding spaces. Unique checks compare typed values exactly and skip blanks. Add a required rule when blanks should also be reported.
|
|
51
|
+
|
|
52
|
+
## Input and export behavior
|
|
53
|
+
|
|
54
|
+
- Supports comma-delimited UTF-8 CSV (including BOM) and ordinary .xlsx workbooks with headers in row one. Files are processed locally in memory.
|
|
55
|
+
- CSV identifiers keep their leading zeros. CSV values beginning with an equals sign remain literal text in the review workbook.
|
|
56
|
+
- The review copy uses a new .xlsx path and retains cell values. Review copies of complex workbooks are subject to openpyxl's format support. Formulas are preserved and are not evaluated.
|
|
57
|
+
- Review labels are based on the checks above. Business-specific rules, additional layouts, and large streaming inputs are outside this release.
|
|
58
|
+
|
|
59
|
+
## Development
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
python -m pip install -e .
|
|
63
|
+
python -m unittest discover -s tests -v
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Released under the [MIT license](LICENSE).
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "unique-sheetreview"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Scan CSV and Excel files and mark data quality issues directly on a review copy."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [{name = "Unique50101"}]
|
|
13
|
+
dependencies = ["openpyxl>=3.1.5,<4", "defusedxml>=0.7.1"]
|
|
14
|
+
|
|
15
|
+
[project.urls]
|
|
16
|
+
Repository = "https://github.com/Unique50101/unique-sheetreview"
|
|
17
|
+
Issues = "https://github.com/Unique50101/unique-sheetreview/issues"
|
|
18
|
+
|
|
19
|
+
[tool.setuptools]
|
|
20
|
+
packages = ["unique_sheetreview"]
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import tempfile
|
|
2
|
+
import unittest
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from openpyxl import Workbook, load_workbook
|
|
6
|
+
from unique_sheetreview import scan
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ScanTests(unittest.TestCase):
|
|
10
|
+
def setUp(self):
|
|
11
|
+
tmp = tempfile.TemporaryDirectory()
|
|
12
|
+
self.addCleanup(tmp.cleanup)
|
|
13
|
+
self.folder = Path(tmp.name)
|
|
14
|
+
|
|
15
|
+
def test_csv(self):
|
|
16
|
+
path = self.folder / "data.csv"
|
|
17
|
+
path.write_text("ID,Date,Name\n001,04/05/2026, Pat\n001,2026-01-01,=literal\n,,Ann\n")
|
|
18
|
+
report = scan(path, required="ID", unique="ID")
|
|
19
|
+
self.assertCountEqual([f.code for f in report.findings],
|
|
20
|
+
["unique", "unique", "required", "ambiguous_date", "whitespace"])
|
|
21
|
+
out = report.save_review_copy(self.folder / "review.xlsx")
|
|
22
|
+
ws = load_workbook(out).active
|
|
23
|
+
self.assertEqual(ws["A2"].value, "001")
|
|
24
|
+
self.assertEqual(ws["C3"].data_type, "s")
|
|
25
|
+
self.assertIn("Moderate", ws["B2"].comment.text)
|
|
26
|
+
with self.assertRaises(FileExistsError):
|
|
27
|
+
report.save_review_copy(out)
|
|
28
|
+
|
|
29
|
+
def test_xlsx(self):
|
|
30
|
+
book = Workbook()
|
|
31
|
+
ws = book.active
|
|
32
|
+
ws.append(["Amount", "Amount", "Name"])
|
|
33
|
+
ws.append(["1.75", 2, "Bob"])
|
|
34
|
+
ws.merge_cells("C1:D1")
|
|
35
|
+
path = self.folder / "sample.xlsx"
|
|
36
|
+
book.save(path)
|
|
37
|
+
report = scan(path, required=["Code"])
|
|
38
|
+
self.assertCountEqual([f.code for f in report.findings],
|
|
39
|
+
["duplicate_header", "duplicate_header", "empty_header", "missing_column", "numeric_text"])
|
|
40
|
+
with self.assertRaises(ValueError):
|
|
41
|
+
report.save_review_copy(path)
|
|
42
|
+
ws = load_workbook(report.save_review_copy(self.folder / "marked.xlsx")).active
|
|
43
|
+
self.assertIn("D1", ws["C1"].comment.text)
|
|
44
|
+
self.assertIsNone(load_workbook(path).active["A2"].comment)
|
|
45
|
+
|
|
46
|
+
def test_clean(self):
|
|
47
|
+
path = self.folder / "clean.csv"
|
|
48
|
+
path.write_text("ID,Total\n001,42\n")
|
|
49
|
+
self.assertEqual(scan(path).findings, [])
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"""Scan a spreadsheet and annotate its data quality findings."""
|
|
2
|
+
import csv
|
|
3
|
+
import re
|
|
4
|
+
from collections import Counter, defaultdict
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from tempfile import TemporaryFile
|
|
8
|
+
from shutil import copyfileobj
|
|
9
|
+
|
|
10
|
+
from openpyxl import Workbook, load_workbook
|
|
11
|
+
from openpyxl.comments import Comment
|
|
12
|
+
from openpyxl.cell.cell import MergedCell
|
|
13
|
+
from openpyxl.styles import PatternFill
|
|
14
|
+
|
|
15
|
+
COLORS = {"High": "FFC7CE", "Moderate": "FFEB9C", "Low": "DDEBF7"}
|
|
16
|
+
DATE = re.compile(r"(\d{1,2})/(\d{1,2})/(\d{4})")
|
|
17
|
+
NUMBER = re.compile(r"[+-]?(?:0|[1-9]\d*)(?:\.\d+)?")
|
|
18
|
+
AMOUNT = re.compile(r"amount|price|cost|quantity|total|revenue|balance", re.I)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@dataclass(frozen=True)
|
|
22
|
+
class Finding:
|
|
23
|
+
severity: str
|
|
24
|
+
sheet: str
|
|
25
|
+
cell: str
|
|
26
|
+
code: str
|
|
27
|
+
message: str
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass
|
|
31
|
+
class Report:
|
|
32
|
+
findings: list[Finding]
|
|
33
|
+
_book: Workbook = field(repr=False)
|
|
34
|
+
_source: Path = field(repr=False)
|
|
35
|
+
|
|
36
|
+
def __str__(self):
|
|
37
|
+
counts = Counter(f.severity for f in self.findings)
|
|
38
|
+
lines = [" | ".join(f"{s}: {counts[s]}" for s in COLORS)]
|
|
39
|
+
lines.extend(f"[{f.severity}] {f.sheet}!{f.cell} — {f.message}" for f in self.findings)
|
|
40
|
+
return "\n".join(lines)
|
|
41
|
+
|
|
42
|
+
def save_review_copy(self, path):
|
|
43
|
+
"""Create a new .xlsx review workbook. Existing files are protected."""
|
|
44
|
+
target = Path(path)
|
|
45
|
+
if target.suffix.lower() != ".xlsx" or target.resolve() == self._source:
|
|
46
|
+
raise ValueError("Choose a new .xlsx output path.")
|
|
47
|
+
if target.exists():
|
|
48
|
+
raise FileExistsError(target)
|
|
49
|
+
grouped = defaultdict(list)
|
|
50
|
+
for finding in self.findings:
|
|
51
|
+
ws = self._book[finding.sheet]
|
|
52
|
+
address = finding.cell
|
|
53
|
+
if isinstance(ws[address], MergedCell):
|
|
54
|
+
area = next(r for r in ws.merged_cells.ranges if address in r)
|
|
55
|
+
address = ws.cell(area.min_row, area.min_col).coordinate
|
|
56
|
+
grouped[finding.sheet, address].append(finding)
|
|
57
|
+
# Clone the scan snapshot so multiple exports never accumulate comments.
|
|
58
|
+
with TemporaryFile() as snapshot:
|
|
59
|
+
self._book.save(snapshot)
|
|
60
|
+
snapshot.seek(0)
|
|
61
|
+
book = load_workbook(snapshot)
|
|
62
|
+
for (sheet, address), issues in grouped.items():
|
|
63
|
+
cell = book[sheet][address]
|
|
64
|
+
severity = next(s for s in COLORS if any(i.severity == s for i in issues))
|
|
65
|
+
cell.fill = PatternFill("solid", fgColor=COLORS[severity])
|
|
66
|
+
notes = [f"[{i.severity}] {i.cell}: {i.message}" for i in issues]
|
|
67
|
+
if cell.comment:
|
|
68
|
+
notes.insert(0, f"{cell.comment.author}: {cell.comment.text}")
|
|
69
|
+
cell.comment = Comment("\n".join(notes), "SheetReview")
|
|
70
|
+
with TemporaryFile() as output:
|
|
71
|
+
book.save(output)
|
|
72
|
+
output.seek(0)
|
|
73
|
+
with target.open("xb") as dest:
|
|
74
|
+
copyfileobj(output, dest)
|
|
75
|
+
return target
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _open(path):
|
|
79
|
+
if path.suffix.lower() == ".xlsx":
|
|
80
|
+
return load_workbook(path)
|
|
81
|
+
if path.suffix.lower() != ".csv":
|
|
82
|
+
raise ValueError("Supported formats are .csv and .xlsx.")
|
|
83
|
+
book = Workbook()
|
|
84
|
+
ws = book.active
|
|
85
|
+
ws.title = "Data"
|
|
86
|
+
with path.open(encoding="utf-8-sig", newline="") as stream:
|
|
87
|
+
for row_no, row in enumerate(csv.reader(stream, strict=True), 1):
|
|
88
|
+
if len(row) > 16384 or row_no > 1048576:
|
|
89
|
+
raise ValueError("CSV exceeds Excel worksheet limits.")
|
|
90
|
+
for col, value in enumerate(row, 1):
|
|
91
|
+
if len(value) > 32767:
|
|
92
|
+
raise ValueError(f"Value exceeds Excel cell limit on row {row_no}.")
|
|
93
|
+
cell = ws.cell(row_no, col, value)
|
|
94
|
+
cell.data_type = "s" # Preserve IDs and literal text, including leading '='.
|
|
95
|
+
return book
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def _names(names):
|
|
99
|
+
if isinstance(names, str):
|
|
100
|
+
names = [names]
|
|
101
|
+
return {name.strip().casefold() for name in names}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def scan(path, *, required=(), unique=(), sheet=None):
|
|
105
|
+
"""Inspect row-one headers and subsequent records, optionally on one sheet."""
|
|
106
|
+
source = Path(path)
|
|
107
|
+
book = _open(source)
|
|
108
|
+
required, unique = _names(required), _names(unique)
|
|
109
|
+
findings = []
|
|
110
|
+
for ws in ([book[sheet]] if sheet is not None else book.worksheets):
|
|
111
|
+
def flag(cell, severity, code, message):
|
|
112
|
+
findings.append(Finding(severity, ws.title, cell.coordinate, code, message))
|
|
113
|
+
|
|
114
|
+
headers = next(ws.iter_rows(min_row=1, max_row=1))
|
|
115
|
+
names = [str(c.value).strip().casefold() if c.value is not None else "" for c in headers]
|
|
116
|
+
counts = Counter(names)
|
|
117
|
+
for c, name in zip(headers, names):
|
|
118
|
+
if not name:
|
|
119
|
+
flag(c, "High", "empty_header", "Give this column a name.")
|
|
120
|
+
elif counts[name] > 1:
|
|
121
|
+
flag(c, "High", "duplicate_header", "Give each column a distinct name.")
|
|
122
|
+
for missing in sorted((required | unique) - set(names)):
|
|
123
|
+
flag(headers[0], "High", "missing_column", f"Add the expected column '{missing}'.")
|
|
124
|
+
seen = defaultdict(dict)
|
|
125
|
+
repeated = set()
|
|
126
|
+
for row in ws.iter_rows(min_row=2):
|
|
127
|
+
if all(c.value is None or c.value == "" for c in row):
|
|
128
|
+
flag(row[0], "Low", "blank_row", "Review this empty row before import.")
|
|
129
|
+
continue
|
|
130
|
+
for c, name in zip(row, names):
|
|
131
|
+
value = c.value
|
|
132
|
+
if value is None or (isinstance(value, str) and not value.strip()):
|
|
133
|
+
if name in required:
|
|
134
|
+
flag(c, "High", "required", "Enter the required value.")
|
|
135
|
+
continue
|
|
136
|
+
if name in unique:
|
|
137
|
+
key = (type(value), value)
|
|
138
|
+
previous = seen[c.column].setdefault(key, c)
|
|
139
|
+
if previous != c:
|
|
140
|
+
msg = "This value repeats in a column declared unique."
|
|
141
|
+
if previous.coordinate not in repeated:
|
|
142
|
+
flag(previous, "High", "unique", msg)
|
|
143
|
+
repeated.add(previous.coordinate)
|
|
144
|
+
flag(c, "High", "unique", msg)
|
|
145
|
+
if c.data_type == "e":
|
|
146
|
+
flag(c, "High", "excel_error", "Resolve the Excel error before import.")
|
|
147
|
+
if not isinstance(value, str) or c.data_type == "f":
|
|
148
|
+
continue
|
|
149
|
+
clean = value.strip()
|
|
150
|
+
if clean != value:
|
|
151
|
+
flag(c, "Low", "whitespace", "Trim leading or trailing whitespace.")
|
|
152
|
+
date = DATE.fullmatch(clean)
|
|
153
|
+
if date:
|
|
154
|
+
a, b = map(int, date.groups()[:2])
|
|
155
|
+
if a != b and 1 <= a <= 12 and 1 <= b <= 12:
|
|
156
|
+
flag(c, "Moderate", "ambiguous_date", "Confirm day/month order or use YYYY-MM-DD.")
|
|
157
|
+
if source.suffix.lower() == ".xlsx" and AMOUNT.search(name) and NUMBER.fullmatch(clean):
|
|
158
|
+
flag(c, "Moderate", "numeric_text", "Review this numeric text and convert to a number if appropriate.")
|
|
159
|
+
return Report(findings, book, source.resolve())
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: unique-sheetreview
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Scan CSV and Excel files and mark data quality issues directly on a review copy.
|
|
5
|
+
Author: Unique50101
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Repository, https://github.com/Unique50101/unique-sheetreview
|
|
8
|
+
Project-URL: Issues, https://github.com/Unique50101/unique-sheetreview/issues
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: openpyxl<4,>=3.1.5
|
|
13
|
+
Requires-Dist: defusedxml>=0.7.1
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# SheetReview
|
|
17
|
+
|
|
18
|
+
Give SheetReview a CSV or Excel file and get a list of data-quality issues with the sheet, cell, priority, and suggested fix. Export the findings as an Excel copy with highlighted cells and comments for the person who supplied the data.
|
|
19
|
+
|
|
20
|
+
## Quick start
|
|
21
|
+
|
|
22
|
+
Requires Python 3.10 or later.
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
python -m pip install unique-sheetreview
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from unique_sheetreview import scan
|
|
30
|
+
|
|
31
|
+
report = scan("orders.xlsx")
|
|
32
|
+
print(report)
|
|
33
|
+
report.save_review_copy("orders_review.xlsx")
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Try the sample
|
|
37
|
+
|
|
38
|
+
From the repository root, use the included [orders.csv](examples/orders.csv). For this example, each row must have a distinct order ID.
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from unique_sheetreview import scan
|
|
42
|
+
|
|
43
|
+
report = scan("examples/orders.csv", required=["OrderID"], unique=["OrderID"])
|
|
44
|
+
print(report)
|
|
45
|
+
report.save_review_copy("orders_review.xlsx")
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The sample produces **3 High, 1 Moderate, and 1 Low** findings.
|
|
49
|
+
|
|
50
|
+
| Priority | Cells | Finding |
|
|
51
|
+
| --- | --- | --- |
|
|
52
|
+
| High | A2, A3 | Order ID 101 occurs twice. |
|
|
53
|
+
| High | A4 | A required order ID is missing. |
|
|
54
|
+
| Moderate | B2 | 04/05/2026 has two possible day/month interpretations. |
|
|
55
|
+
| Low | C2 | The name has a leading space. |
|
|
56
|
+
|
|
57
|
+
## Checks
|
|
58
|
+
|
|
59
|
+
| Priority | What the scanner checks |
|
|
60
|
+
| --- | --- |
|
|
61
|
+
| High | Missing or duplicate headers, absent rule columns, empty required values, repeated values in declared unique columns, stored Excel error cells |
|
|
62
|
+
| Moderate | Ambiguous slash dates, numeric text in Excel amount, price, cost, quantity, total, revenue, or balance columns |
|
|
63
|
+
| Low | Blank rows and surrounding whitespace in text values |
|
|
64
|
+
|
|
65
|
+
Use `report.findings` to integrate with an upload form. Each finding has `severity`, `sheet`, `cell`, `code`, and `message`. Use `scan(path, sheet="Orders")` to restrict an Excel scan to one worksheet. By default the scanner runs on all worksheets, applying the same rules to each. Header rule names ignore case and surrounding spaces. Unique checks compare typed values exactly and skip blanks. Add a required rule when blanks should also be reported.
|
|
66
|
+
|
|
67
|
+
## Input and export behavior
|
|
68
|
+
|
|
69
|
+
- Supports comma-delimited UTF-8 CSV (including BOM) and ordinary .xlsx workbooks with headers in row one. Files are processed locally in memory.
|
|
70
|
+
- CSV identifiers keep their leading zeros. CSV values beginning with an equals sign remain literal text in the review workbook.
|
|
71
|
+
- The review copy uses a new .xlsx path and retains cell values. Review copies of complex workbooks are subject to openpyxl's format support. Formulas are preserved and are not evaluated.
|
|
72
|
+
- Review labels are based on the checks above. Business-specific rules, additional layouts, and large streaming inputs are outside this release.
|
|
73
|
+
|
|
74
|
+
## Development
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
python -m pip install -e .
|
|
78
|
+
python -m unittest discover -s tests -v
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Released under the [MIT license](LICENSE).
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
tests/test_scan.py
|
|
5
|
+
unique_sheetreview/__init__.py
|
|
6
|
+
unique_sheetreview.egg-info/PKG-INFO
|
|
7
|
+
unique_sheetreview.egg-info/SOURCES.txt
|
|
8
|
+
unique_sheetreview.egg-info/dependency_links.txt
|
|
9
|
+
unique_sheetreview.egg-info/requires.txt
|
|
10
|
+
unique_sheetreview.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
unique_sheetreview
|