diff --git a/task-1/output/clean_users.json b/task-1/output/clean_users.json new file mode 100644 index 0000000..79ba976 --- /dev/null +++ b/task-1/output/clean_users.json @@ -0,0 +1,86 @@ +[ + { + "id": 1, + "name": "Alice Johnson", + "email": "alice.johnson@company.com", + "department": "Engineering", + "salary": 85000 + }, + { + "id": 2, + "name": "Bob Smith", + "email": "bob.smith@company.com", + "department": "Unknown", + "salary": 72000 + }, + { + "id": 3, + "name": "Carol Williams", + "email": "carol.williams@company.com", + "department": "Engineering", + "salary": null + }, + { + "id": 4, + "name": "David, Jr.", + "email": "david.brown@company.com", + "department": "Sales", + "salary": 68000 + }, + { + "id": 5, + "name": "Caf\u00e9 Owner", + "email": "eva@company.com", + "department": "Engineering", + "salary": 88000 + }, + { + "id": 6, + "name": "FRANK WILSON", + "email": "frank@company.com", + "department": "marketing", + "salary": 95000 + }, + { + "id": 7, + "name": "Grace Lee", + "email": "grace.lee@company.com", + "department": "Engineering", + "salary": null + }, + { + "id": 9, + "name": "Henry Davis", + "email": "henry.davis@company.com", + "department": "Sales", + "salary": 82000 + }, + { + "id": 11, + "name": "Linda Taylor", + "email": "linda.t@company.com", + "department": "HR", + "salary": 55000 + }, + { + "id": 12, + "name": "Mike Brown", + "email": "mike.b@company.com", + "department": "Sales", + "salary": 62000 + }, + { + "id": 13, + "name": "Sarah Connor", + "email": "s.connor@sky.net", + "department": "Unknown", + "salary": -1 + }, + { + "id": 15, + "name": "John Doe", + "email": "john.doe@company.net", + "department": "Engineering", + "salary": 100000 + } +] \ No newline at end of file diff --git a/task-1/src/__pycache__/cleaner.cpython-311.pyc b/task-1/src/__pycache__/cleaner.cpython-311.pyc new file mode 100644 index 0000000..399fe96 Binary files /dev/null and b/task-1/src/__pycache__/cleaner.cpython-311.pyc differ diff --git a/task-1/src/__pycache__/utils.cpython-311.pyc b/task-1/src/__pycache__/utils.cpython-311.pyc new file mode 100644 index 0000000..c3b8c85 Binary files /dev/null and b/task-1/src/__pycache__/utils.cpython-311.pyc differ diff --git a/task-1/src/__pycache__/utils.cpython-312.pyc b/task-1/src/__pycache__/utils.cpython-312.pyc new file mode 100644 index 0000000..3ed6032 Binary files /dev/null and b/task-1/src/__pycache__/utils.cpython-312.pyc differ diff --git a/task-1/src/cleaner.py b/task-1/src/cleaner.py index 98e4985..2f7f88b 100644 --- a/task-1/src/cleaner.py +++ b/task-1/src/cleaner.py @@ -16,8 +16,6 @@ from utils import clean_department, clean_email, clean_name, clean_salary -logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") -log = logging.getLogger(__name__) def clean_row(row: dict[str, str]) -> dict | None: @@ -25,10 +23,10 @@ def clean_row(row: dict[str, str]) -> dict | None: name = clean_name(row.get("name", "")) email = clean_email(row.get("email", "")) if not name: - log.warning("skipping row id=%s: missing name", row.get("id")) + print("skipping row id=%s: missing name", row.get("id")) return None if not email: - log.warning("skipping row id=%s: missing email", row.get("id")) + print("skipping row id=%s: missing email", row.get("id")) return None return { "id": int(row["id"]) if row.get("id", "").isdigit() else row.get("id"), @@ -46,7 +44,7 @@ def main(input_path: Path, output_path: Path) -> None: cleaned = [c for row in reader if (c := clean_row(row)) is not None] with output_path.open("w", encoding="utf-8") as f: json.dump(cleaned, f, indent=2) - log.info("wrote %d cleaned rows to %s", len(cleaned), output_path) + print("wrote %d cleaned rows to %s", len(cleaned), output_path) if __name__ == "__main__": @@ -57,5 +55,5 @@ def main(input_path: Path, output_path: Path) -> None: try: main(args.input, args.output) except FileNotFoundError as e: - log.error("input file not found: %s", e.filename) + print("input file not found: %s", e.filename) raise SystemExit(1) diff --git a/task-1/src/utils.py b/task-1/src/utils.py index 2762398..06ec927 100644 --- a/task-1/src/utils.py +++ b/task-1/src/utils.py @@ -6,6 +6,9 @@ """ from __future__ import annotations +import logging +from pathlib import Path + def clean_name(raw: str) -> str: @@ -13,7 +16,11 @@ def clean_name(raw: str) -> str: Returns the cleaned string. An empty input returns "". """ - raise NotImplementedError("Implement clean_name (Task 1)") + name = raw.strip() + if name == "": + + return "" + return name def clean_email(raw: str) -> str: @@ -21,7 +28,8 @@ def clean_email(raw: str) -> str: Returns the cleaned string. An empty input returns "". """ - raise NotImplementedError("Implement clean_email (Task 1)") + email = raw.strip().lower() + return email def clean_department(raw: str) -> str: @@ -29,7 +37,10 @@ def clean_department(raw: str) -> str: Strip whitespace; treat empty string as missing. """ - raise NotImplementedError("Implement clean_department (Task 1)") + department = raw.strip() + if department == "": + return "Unknown" + return department def clean_salary(raw: str) -> int | None: @@ -38,4 +49,12 @@ def clean_salary(raw: str) -> int | None: Handles inputs like "85000", " 95000", '"68,000"', "N/A", "". Returns None when the value cannot be parsed (missing or "N/A"). """ - raise NotImplementedError("Implement clean_salary (Task 1)") + try: + salary = raw.strip().replace(",", "").replace(".", "") + if salary in ("", "N/A"): + return None + return int(salary) + except ValueError: + logging.warning("skipping row with invalid salary: %s", raw) + return None + diff --git a/task-2/AI_DEBUG.md b/task-2/AI_DEBUG.md index 413b94a..22f04ef 100644 --- a/task-2/AI_DEBUG.md +++ b/task-2/AI_DEBUG.md @@ -12,18 +12,44 @@ Document one debugging session you had during Task 1 where you used an LLM +Traceback (most recent call last): + File "C:\Users\Gebruiker\c55-data-week1\task-1\src\cleaner.py", line 58, in + main(args.input, args.output) + File "C:\Users\Gebruiker\c55-data-week1\task-1\src\cleaner.py", line 46, in main + cleaned = [c for row in reader if (c := clean_row(row)) is not None] + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\Gebruiker\c55-data-week1\task-1\src\cleaner.py", line 46, in + cleaned = [c for row in reader if (c := clean_row(row)) is not None] + ^^^^^^^^^^^^^^ + File "C:\Users\Gebruiker\c55-data-week1\task-1\src\cleaner.py", line 38, in clean_row + "salary": clean_salary(row.get("salary", "")), + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\Gebruiker\c55-data-week1\task-1\src\utils.py", line 50, in clean_salary + return int(salary) + ^^^^^^^^^^^ +ValueError: invalid literal for int() with base 10: '62.000' + ## The Prompt +why do I get an error? + + + ## The Solution + +The error is very clear! The salary value '62.000' cannot be converted to an integer because it has a dot in it. + ## Reflection + +62.000 couln't be converted to an interger.Ensure to consider all probabilities of errors occuring when cleaning data diff --git a/task-3/azure_proof.png b/task-3/azure_proof.png new file mode 100644 index 0000000..cb14d59 Binary files /dev/null and b/task-3/azure_proof.png differ