Skip to content

Commit

Permalink
Fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jr-hartono committed Dec 22, 2023
1 parent 87ec917 commit 96c9126
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
25 changes: 15 additions & 10 deletions ensysmod/core/file_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,7 @@ def process_excel_file(
If as_matrix is true, the file is read as a matrix, otherwise it is read per column.
"""
try:
if isinstance(file, UploadFile):
file_path = file.filename if file.filename is not None else ""
content = file.file.read()
df: pd.DataFrame = pd.read_excel(content, engine="openpyxl")
elif isinstance(file, tuple):
zip_archive, file_path= file
with zip_archive.open(file_path) as content:
df: pd.DataFrame = pd.read_excel(content, engine="openpyxl")
else:
raise TypeError("Unknown file type.")
file_path, df = read_excel_file(file)

if as_matrix:
# determine the labels (region and region_to) of rows and columns
Expand Down Expand Up @@ -265,3 +256,17 @@ def process_excel_file(

except Exception as e:
return FileUploadResult(status=FileStatus.ERROR, file=file_path, message=str(e))


def read_excel_file(file: UploadFile | tuple[ZipFile, str]) -> tuple[str, pd.DataFrame]:
if isinstance(file, UploadFile):
file_path = file.filename if file.filename is not None else ""
content = file.file.read()
df: pd.DataFrame = pd.read_excel(content, engine="openpyxl")
elif isinstance(file, tuple):
zip_archive, file_path = file
with zip_archive.open(file_path) as content:
df: pd.DataFrame = pd.read_excel(content, engine="openpyxl")
else:
raise TypeError(f"Unknown file type: {type(file)}")

Check warning on line 271 in ensysmod/core/file_upload.py

View check run for this annotation

Codecov / codecov/patch

ensysmod/core/file_upload.py#L271

Added line #L271 was not covered by tests
return file_path, df
2 changes: 1 addition & 1 deletion ensysmod/schemas/transmission_distance.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pydantic import BaseModel, Field, NonNegativeFloat, validator
from pydantic import BaseModel, Field, validator

from ensysmod.schemas.base_ref_component_region import RefCRBase, RefCRBaseBase, RefCRBaseCreate, RefCRBaseUpdate
from ensysmod.schemas.region import Region
Expand Down
2 changes: 0 additions & 2 deletions ensysmod/schemas/yearly_full_load_hours_min.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ class YearlyFullLoadHoursMinCreate(YearlyFullLoadHoursMinBase, RefCRBaseCreate):
"""



class YearlyFullLoadHoursMinUpdate(YearlyFullLoadHoursMinBase, RefCRBaseUpdate):
"""
Attributes to receive via API on update of a YearlyFullLoadHoursMin entry.
"""



class YearlyFullLoadHoursMin(YearlyFullLoadHoursMinBase, RefCRBase):
"""
Attributes to return via API for a YearlyFullLoadHoursMin entry.
Expand Down
1 change: 1 addition & 0 deletions tests/utils/data_generator/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def dataset_create(
)
return crud.dataset.create(db=db, obj_in=create_request)


@contextmanager
def get_dataset_zip(folder_name: str) -> Generator[Path, None, None]:
"""
Expand Down

0 comments on commit 96c9126

Please sign in to comment.