From 367a51bd734270a969ea48fa37cfdfd0e4da93a9 Mon Sep 17 00:00:00 2001 From: David Michaels Date: Mon, 11 Dec 2023 13:11:24 -0500 Subject: [PATCH] minor updates based on pr-294 --- dcicutils/data_readers.py | 6 +++--- dcicutils/misc_utils.py | 2 +- dcicutils/structured_data.py | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dcicutils/data_readers.py b/dcicutils/data_readers.py index 8fd6d9a10..f569857c5 100644 --- a/dcicutils/data_readers.py +++ b/dcicutils/data_readers.py @@ -2,7 +2,7 @@ import csv import openpyxl from typing import Any, Generator, Iterator, List, Optional, Type, Tuple, Union -from dcicutils.misc_utils import create_object, right_trim +from dcicutils.misc_utils import create_dict, right_trim # Forward type references for type hints. Excel = Type["Excel"] @@ -59,11 +59,11 @@ def file(self) -> Optional[str]: def warnings(self) -> List[str]: warnings = [] if self._warning_empty_headers: - warnings.append({"src": create_object(file=self.file), + warnings.append({"src": create_dict(file=self.file), "warning": "Empty header column encountered; ignoring it and all subsequent columns."}) if self._warning_extra_values: for row_number in self._warning_extra_values: - warnings.append({"src": create_object(file=self.file, row=row_number), + warnings.append({"src": create_dict(file=self.file, row=row_number), "warning": f"Extra row column values."}) return warnings diff --git a/dcicutils/misc_utils.py b/dcicutils/misc_utils.py index 752fc91e7..baecf97c6 100644 --- a/dcicutils/misc_utils.py +++ b/dcicutils/misc_utils.py @@ -1501,7 +1501,7 @@ def right_trim(list_or_tuple: Union[List[Any], Tuple[Any]], return list_or_tuple[:i + 1] -def create_object(**kwargs) -> dict: +def create_dict(**kwargs) -> dict: result = {} for name in kwargs: if kwargs[name]: diff --git a/dcicutils/structured_data.py b/dcicutils/structured_data.py index bd641e0ee..de25ef114 100644 --- a/dcicutils/structured_data.py +++ b/dcicutils/structured_data.py @@ -10,7 +10,7 @@ from webtest.app import TestApp from dcicutils.common import OrchestratedApp from dcicutils.data_readers import CsvReader, Excel, RowReader -from dcicutils.misc_utils import (create_object, load_json_if, merge_objects, remove_empty_properties, right_trim, +from dcicutils.misc_utils import (create_dict, load_json_if, merge_objects, remove_empty_properties, right_trim, split_string, to_boolean, to_enum, to_float, to_integer, VirtualApp) from dcicutils.portal_utils import Portal as PortalBase from dcicutils.zip_utils import unpack_gz_file_to_temporary_file, unpack_files @@ -71,7 +71,7 @@ def validate(self, force: bool = False) -> None: row_number += 1 if (validation_errors := schema.validate(data)) is not None: for validation_error in validation_errors: - self._note_error({"src": create_object(type=schema.name, row=row_number), + self._note_error({"src": create_dict(type=schema.name, row=row_number), "error": validation_error}, "validation") @property @@ -204,8 +204,8 @@ def create_row(self) -> dict: def set_value(self, data: dict, column_name: str, value: str, file: Optional[str], row_number: int = -1) -> None: if (set_value_function := self._set_value_functions.get(column_name)): - src = create_object(type=self._schema.name if self._schema else None, - column=column_name, file=file, row=row_number) + src = create_dict(type=self._schema.name if self._schema else None, + column=column_name, file=file, row=row_number) set_value_function(data, value, src) def _create_row_template(self, column_names: List[str]) -> dict: # Surprisingly tricky code here.