diff --git a/src/omnipy/modules/json/tasks.py b/src/omnipy/modules/json/tasks.py index fb76be8e..935be6ce 100644 --- a/src/omnipy/modules/json/tasks.py +++ b/src/omnipy/modules/json/tasks.py @@ -4,9 +4,9 @@ from omnipy.compute.task import TaskTemplate from omnipy.compute.typing import mypy_fix_task_template from omnipy.data.dataset import Dataset +from omnipy.data.helpers import obj_or_model_contents_isinstance from omnipy.data.model import Model -from ...data.helpers import obj_or_model_contents_isinstance from .datasets import (JsonDataset, JsonDictDataset, JsonListDataset, diff --git a/src/omnipy/modules/pandas/models.py b/src/omnipy/modules/pandas/models.py index bacc0592..25000b35 100644 --- a/src/omnipy/modules/pandas/models.py +++ b/src/omnipy/modules/pandas/models.py @@ -2,10 +2,10 @@ from typing import Any from omnipy.data.dataset import Dataset +from omnipy.data.helpers import is_model_instance from omnipy.data.model import Model from . import pd -from ...data.helpers import is_model_instance from ..tables.models import TableListOfDictsOfJsonScalarsModel diff --git a/src/omnipy/modules/raw/tasks.py b/src/omnipy/modules/raw/tasks.py index fe430117..fa596b77 100644 --- a/src/omnipy/modules/raw/tasks.py +++ b/src/omnipy/modules/raw/tasks.py @@ -12,8 +12,8 @@ from omnipy.compute.task import TaskTemplate from omnipy.compute.typing import mypy_fix_task_template from omnipy.data.dataset import Dataset, Model +from omnipy.util.setdeque import SetDeque -from ...util.setdeque import SetDeque from .datasets import StrDataset from .protocols import IsModifyAllLinesCallable, IsModifyContentsCallable, IsModifyEachLineCallable diff --git a/src/omnipy/modules/tables/models.py b/src/omnipy/modules/tables/models.py index 8748b6c9..f5892cd8 100644 --- a/src/omnipy/modules/tables/models.py +++ b/src/omnipy/modules/tables/models.py @@ -37,19 +37,23 @@ def _parse_data( if isinstance(data[0], list): # type: ignore[index] first_row_as_colnames = Model[list[str]](data[0]) # type: ignore[index] first_row_as_colnames_data: list[str] = \ - first_row_as_colnames.to_data() + first_row_as_colnames.to_data() # type: ignore[assignment] - return [{ - col_name: row[i] if i < len(row) else None for i, - col_name in enumerate(first_row_as_colnames_data) - } for j, - row in enumerate(data) if j > 0] + return cls._convert_list_of_lists_to_list_of_dicts(data, first_row_as_colnames_data) else: assert isinstance(data[0], dict) # type: ignore[index] return cast(TableListOfDictsOfJsonScalarsModel, data) return cast(TableListOfDictsOfJsonScalarsModel, data) + @classmethod + def _convert_list_of_lists_to_list_of_dicts(cls, data, first_row_as_colnames_data): + return [{ + col_name: row[i] if i < len(row) else None for i, + col_name in enumerate(first_row_as_colnames_data) + } for j, + row in enumerate(data) if j > 0] + @property def col_names(self) -> tuple[str]: col_names = {}