feat(add-data): Add general config and utilities for data prep
This commit is contained in:
7
data_preparation/config.py
Normal file
7
data_preparation/config.py
Normal file
@@ -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"
|
||||||
34
data_preparation/data_utils.py
Normal file
34
data_preparation/data_utils.py
Normal file
@@ -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)
|
||||||
Reference in New Issue
Block a user