Skip to content

Commit

Permalink
Lint fix and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sveinugu committed Jan 7, 2024
1 parent 3026026 commit c7d674c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 27 deletions.
23 changes: 11 additions & 12 deletions src/omnipy/data/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
Iterator,
Optional,
Type,
TypeAlias,
TypeVar)

import humanize
Expand Down Expand Up @@ -141,7 +142,7 @@ def __class_getitem__(cls, model: ModelT) -> ModelT:

return created_dataset

def __init__(
def __init__( # noqa: C901
self,
value: Mapping[str, object] | Iterable[tuple[str, object]] | UndefinedType = Undefined,
*,
Expand Down Expand Up @@ -192,7 +193,7 @@ def __init__(
self._raise_no_model_exception()

dataset_as_input = DATA_KEY in super_kwargs \
and lenient_isinstance(super_kwargs[DATA_KEY], Dataset)
and lenient_isinstance(super_kwargs[DATA_KEY], Dataset)
if dataset_as_input:
super_kwargs[DATA_KEY] = super_kwargs[DATA_KEY].to_data()

Expand Down Expand Up @@ -545,13 +546,16 @@ def _to_data_if_model(data_obj: Any):
ParamModelT = TypeVar('ParamModelT', bound=ParamModel)
ListOfParamModelT = TypeVar('ListOfParamModelT', bound=ListOfParamModel)

ParamModelSuperKwargsType: TypeAlias = \
dict[str, dict[str, ParamModelT | DataWithParams[ParamModelT, KwargValT]]]

ListOfParamModelSuperKwargsType: TypeAlias = \
dict[str, dict[str, list[ListOfParamModelT | DataWithParams[ListOfParamModelT, KwargValT]]]]


class ParamDataset(Dataset[ParamModelT | DataWithParams[ParamModelT, KwargValT]],
Generic[ParamModelT, KwargValT]):
def _init(self,
super_kwargs: dict[str,
dict[str, ParamModelT | DataWithParams[ParamModelT, KwargValT]]],
**kwargs: KwargValT) -> None:
def _init(self, super_kwargs: ParamModelSuperKwargsType, **kwargs: KwargValT) -> None:
if kwargs and DATA_KEY in super_kwargs:
super_kwargs[DATA_KEY] = {
key: DataWithParams(data=val, params=kwargs)
Expand Down Expand Up @@ -587,12 +591,7 @@ def callback_func(model: ModelT, contents: Any):

class ListOfParamModelDataset(ParamDataset[ListOfParamModelT, KwargValT],
Generic[ListOfParamModelT, KwargValT]):
def _init(self,
super_kwargs: dict[str,
dict[str,
list[ListOfParamModelT |
DataWithParams[ListOfParamModelT, KwargValT]]]],
**kwargs: KwargValT) -> None:
def _init(self, super_kwargs: ListOfParamModelSuperKwargsType, **kwargs: KwargValT) -> None:
if kwargs and DATA_KEY in super_kwargs:
super_kwargs[DATA_KEY] = {
key: [DataWithParams(data=_, params=kwargs) for _ in val]
Expand Down
1 change: 0 additions & 1 deletion src/omnipy/data/model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from abc import ABCMeta
from collections.abc import Mapping, Sequence
import functools
import inspect
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,7 +2,7 @@
from typing import Any

from omnipy.data.dataset import Dataset
from omnipy.data.model import Model, ROOT_KEY
from omnipy.data.model import Model

from . import pd

Expand Down
2 changes: 1 addition & 1 deletion tests/data/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1874,4 +1874,4 @@ def test_list_of_parametrized_model() -> None:
assert model.contents == [UpperStrModel('foo', upper=False), UpperStrModel('bar', upper=False)]

model.from_json('["foo", "bar"]', upper=True)
assert model.contents == [UpperStrModel('foo', upper=True), UpperStrModel('bar', upper=True)]
assert model.contents == [UpperStrModel('foo', upper=True), UpperStrModel('bar', upper=True)]
8 changes: 4 additions & 4 deletions tests/modules/raw/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def test_split_to_and_join_lines_models():


def test_split_to_and_join_items():
data_tab_start = "abc\t def \tghi\tjkl"
data_tab_end = "mno\t pqr \tstu\tvwx\tyz "
data_tab_start = 'abc\t def \tghi\tjkl'
data_tab_end = 'mno\t pqr \tstu\tvwx\tyz '

items_stripped_tab = SplitToItemsDataset(dict(start=data_tab_start, end=data_tab_end))
assert items_stripped_tab['start'].contents == ['abc', 'def', 'ghi', 'jkl']
Expand All @@ -105,8 +105,8 @@ def test_split_to_and_join_items():
assert items_unstripped_tab['start'][1] == ' def '
assert items_unstripped_tab['end'][-2:].contents == ['vwx', 'yz ']

data_comma_start = "abc, def, ghi, jkl"
data_comma_end = "mno, pqr, stu, vwx, yz"
data_comma_start = 'abc, def, ghi, jkl'
data_comma_end = 'mno, pqr, stu, vwx, yz'

items_stripped_comma = SplitToItemsDataset(
dict(start=data_comma_start, end=data_comma_end), delimiter=',')
Expand Down
16 changes: 8 additions & 8 deletions tests/modules/raw/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ def test_split_to_and_join_lines_models():
assert JoinLinesModel(SplitToLinesModel(data, strip=False)).contents == data


def test_split_to_and_join_items() -> None:
data_tab = "abc\t def \tghi\tjkl"
def test_split_to_and_join_items():
data_tab = 'abc\t def \tghi\tjkl'

items_stripped_tab = SplitToItemsModel(data_tab)
assert items_stripped_tab.contents == ['abc', 'def', 'ghi', 'jkl']
Expand All @@ -90,7 +90,7 @@ def test_split_to_and_join_items() -> None:
assert items_unstripped_tab[1] == ' def '
assert items_unstripped_tab[-2:].contents == ['ghi', 'jkl']

data_comma = "abc, def, ghi, jkl"
data_comma = 'abc, def, ghi, jkl'

items_stripped_comma = SplitToItemsModel(data_comma, delimiter=',')
assert items_stripped_comma.contents == ['abc', 'def', 'ghi', 'jkl']
Expand All @@ -106,7 +106,7 @@ def test_split_to_and_join_items() -> None:
assert comma_space_joined_items[1:-1].contents == 'ef, gh'


def test_split_lines_to_columns_and_join_columns_to_lines() -> None:
def test_split_lines_to_columns_and_join_columns_to_lines():
data_tab = ['abc\t def \tghi\t jkl', 'mno\t pqr\tstu\t vwx', 'yz']

cols_stripped_tab = SplitLinesToColumnsModel(data_tab)
Expand All @@ -132,13 +132,13 @@ def test_split_lines_to_columns_and_join_columns_to_lines() -> None:
assert cols_stripped_comma[1:].to_data() == [['mno', 'pqr', 'stu', 'vwx'], ['yz']]

joined_cols = JoinColumnsToLinesModel(cols_stripped_tab[1:])
assert joined_cols.contents == [JoinItemsModel('mno\tpqr\tstu\tvwx'), \
JoinItemsModel('yz')]
assert joined_cols.contents \
== [JoinItemsModel('mno\tpqr\tstu\tvwx'), JoinItemsModel('yz')]
assert joined_cols[1:].contents == [JoinItemsModel('yz')]
assert joined_cols.to_data() == ['mno\tpqr\tstu\tvwx', 'yz']

joined_cols = JoinColumnsToLinesModel(cols_stripped_comma[1:], delimiter=', ')
assert joined_cols.contents == [JoinItemsModel('mno, pqr, stu, vwx'), \
JoinItemsModel('yz')]
assert joined_cols.contents \
== [JoinItemsModel('mno, pqr, stu, vwx'), JoinItemsModel('yz')]
assert joined_cols[1:].contents == [JoinItemsModel('yz')]
assert joined_cols.to_data() == ['mno, pqr, stu, vwx', 'yz']

0 comments on commit c7d674c

Please sign in to comment.