diff --git a/data_preparation/config.py b/data_preparation/config.py new file mode 100644 index 0000000..0a42729 --- /dev/null +++ b/data_preparation/config.py @@ -0,0 +1,7 @@ +"""Global configuration for data preprocessing.""" + +from pathlib import Path + +BASE_DIR = Path(__file__).resolve().parent.parent +DATA_DIR = BASE_DIR / "data" +APP_DIR = BASE_DIR / "app" diff --git a/data_preparation/data_utils.py b/data_preparation/data_utils.py new file mode 100644 index 0000000..39477e7 --- /dev/null +++ b/data_preparation/data_utils.py @@ -0,0 +1,34 @@ +import json +from datetime import datetime +from typing import Any + + +class DateTimeEncoder(json.JSONEncoder): + """A custom JSON encoder that handles datetime objects. + + This encoder extends the json.JSONEncoder class to provide serialization + support for datetime objects, converting them to ISO format strings. + + Methods + ------- + default(obj: Any) -> str + Encode datetime objects as ISO format strings. + """ + + def default(self, obj: Any) -> str: + """Encode the given object as a JSON-serializable type. + + Parameters + ---------- + obj : Any + The object to encode. + + Returns + ------- + str + The ISO format string if the object is a datetime, otherwise + delegates to the superclass encoder. + """ + if isinstance(obj, datetime): + return obj.isoformat() + return super().default(obj)