Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions task-1/output/clean_users.json
Original file line number Diff line number Diff line change
@@ -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
}
]
Binary file added task-1/src/__pycache__/cleaner.cpython-311.pyc
Binary file not shown.
Binary file added task-1/src/__pycache__/utils.cpython-311.pyc
Binary file not shown.
Binary file added task-1/src/__pycache__/utils.cpython-312.pyc
Binary file not shown.
10 changes: 4 additions & 6 deletions task-1/src/cleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@

from utils import clean_department, clean_email, clean_name, clean_salary

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please undo this change as the grader runs this, and .utils does not work here as you're not importing a module from a package


logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")
log = logging.getLogger(__name__)


def clean_row(row: dict[str, str]) -> dict | None:
"""Clean a single CSV row. Return None to skip the row (validation failed)."""
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"),
Expand All @@ -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__":
Expand All @@ -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)
27 changes: 23 additions & 4 deletions task-1/src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,41 @@
"""

from __future__ import annotations
import logging
from pathlib import Path



def clean_name(raw: str) -> str:
"""Strip leading/trailing whitespace from a name.

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:
"""Lowercase the email, strip surrounding whitespace.

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:
"""Return the department, or 'Unknown' if missing/empty.

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:
Expand All @@ -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

26 changes: 26 additions & 0 deletions task-2/AI_DEBUG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,44 @@ Document one debugging session you had during Task 1 where you used an LLM
<!-- Paste the full traceback or describe the wrong behaviour. Include the
exact error message and the line of your code that triggered it. -->

Traceback (most recent call last):
File "C:\Users\Gebruiker\c55-data-week1\task-1\src\cleaner.py", line 58, in <module>
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 <listcomp>
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

<!-- The exact text you sent to the LLM. Include the code you pasted with
it. -->

why do I get an error?



## The Solution

<!-- What did the LLM suggest? Did it work on the first try, or did you
need a follow-up? -->


The error is very clear! The salary value '62.000' cannot be converted to an integer because it has a dot in it.

## Reflection

<!-- A few sentences on: did you understand WHY the original code was
broken, or did you just accept the fix? What would you do differently next
time? -->

62.000 couln't be converted to an interger.Ensure to consider all probabilities of errors occuring when cleaning data
Binary file added task-3/azure_proof.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.