From 541e9333c7107da7704d7ff4bf2fb55a6cee7671 Mon Sep 17 00:00:00 2001 From: Adrian D'Alessandro Date: Wed, 4 Oct 2023 18:00:04 +0100 Subject: [PATCH] Log specific issues with DSR fields in validator --- datahub/dsr.py | 8 +++++++- datahub/main.py | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/datahub/dsr.py b/datahub/dsr.py index 2091da0..fd42b4b 100644 --- a/datahub/dsr.py +++ b/datahub/dsr.py @@ -7,6 +7,8 @@ from numpy.typing import NDArray from pydantic import BaseModel, Field +from . import log + class DSRModel(BaseModel): """Define required key values for Demand Side Response data.""" @@ -76,10 +78,14 @@ def validate_dsr_data(data: dict[str, NDArray | str]) -> None: array.dtype, np.number ): aliases.append(alias) + log.error( + f"'{alias}' has shape {array.shape}, expected {field['shape']}" + ) + if aliases: raise HTTPException( status_code=422, - detail=f"Invalid size for: {', '.join(aliases)}.", + detail=f"Invalid size or data type for: {', '.join(aliases)}.", ) diff --git a/datahub/main.py b/datahub/main.py index c41eb95..eaabd3b 100644 --- a/datahub/main.py +++ b/datahub/main.py @@ -28,7 +28,7 @@ def create_opal_data(data: OpalModel | OpalArrayData) -> dict[str, str]: Returns: A Dict of the Opal data that has just been added to the Dataframe """ # noqa: D301 - log.info("Recieved Opal data.") + log.info("Received Opal data.") raw_data = data.dict() @@ -141,7 +141,7 @@ def upload_dsr(file: UploadFile) -> dict[str, str | None]: Returns: dict[str, str]: dictionary with the filename """ # noqa: D301 - log.info("Recieved Opal data.") + log.info("Received Opal data.") data = read_dsr_file(file.file) validate_dsr_data(data)