Skip to content

Commit

Permalink
Misc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sveinugu committed Sep 15, 2024
1 parent 1645654 commit feb5277
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/omnipy/modules/json/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/omnipy/modules/pandas/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion src/omnipy/modules/raw/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 10 additions & 6 deletions src/omnipy/modules/tables/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down

0 comments on commit feb5277

Please sign in to comment.