Skip to content

Commit

Permalink
style: apply automated linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
megalinter-bot committed Jun 2, 2023
1 parent 74045d7 commit e4c5882
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/safeds/data/tabular/containers/_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ def filter_rows(self, query: Callable[[Row], bool]) -> Table:
result_table = self.from_rows(rows)
return result_table

_T = TypeVar('_T')
_T = TypeVar("_T")

def group_by(self, key_selector: Callable[[Row], _T]) -> dict[_T, Table]:
"""
Expand All @@ -735,9 +735,9 @@ def group_by(self, key_selector: Callable[[Row], _T]) -> dict[_T, Table]:
dictionary : dict
A dictionary containing the new tables as values and the selected keys as keys.
"""
dictionary: dict[Table._T, Table] = dict()
dictionary: dict[Table._T, Table] = {}
for row in self.to_rows():
if key_selector(row) in dictionary.keys():
if key_selector(row) in dictionary:
dictionary[key_selector(row)] = dictionary[key_selector(row)].add_row(row)
else:
dictionary[key_selector(row)] = Table.from_rows([row])
Expand Down
32 changes: 14 additions & 18 deletions tests/safeds/data/tabular/containers/_table/test_group_by.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Callable
from collections.abc import Callable

import pytest

from safeds.data.tabular.containers import Table


Expand All @@ -11,29 +10,26 @@
(
Table({"col1": [1, 1, 2, 2, 3], "col2": ["a", "b", "c", "d", "e"]}),
lambda row: row["col1"],
{1: Table({"col1": [1, 1], "col2": ["a", "b"]}), 2: Table({"col1": [2, 2], "col2": ["c", "d"]}),
3: Table({"col1": [3], "col2": ["e"]})}
{
1: Table({"col1": [1, 1], "col2": ["a", "b"]}),
2: Table({"col1": [2, 2], "col2": ["c", "d"]}),
3: Table({"col1": [3], "col2": ["e"]}),
},
),
(
Table({"col1": [1, 1, 2, 2, 3], "col2": ["a", "b", "c", "d", 2]}),
lambda row: row["col1"],
{1: Table({"col1": [1, 1], "col2": ["a", "b"]}), 2: Table({"col1": [2, 2], "col2": ["c", "d"]}),
3: Table({"col1": [3], "col2": [2]})}
),
(
Table(),
lambda row: row["col1"],
{}
{
1: Table({"col1": [1, 1], "col2": ["a", "b"]}),
2: Table({"col1": [2, 2], "col2": ["c", "d"]}),
3: Table({"col1": [3], "col2": [2]}),
},
),
(
Table({"col1": [], "col2": []}),
lambda row: row["col1"],
{}
)
(Table(), lambda row: row["col1"], {}),
(Table({"col1": [], "col2": []}), lambda row: row["col1"], {}),
],
ids=["select by row1", "different types in column", "empty table", "table with no rows"]
ids=["select by row1", "different types in column", "empty table", "table with no rows"],
)
def test_group_by(table: Table, selector: Callable, expected: dict) -> None:
out = table.group_by(selector)
assert out == expected

0 comments on commit e4c5882

Please sign in to comment.