-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #47. ### Summary of Changes * Add `__iter__` method to `Column` and `Row` to iterate over the values: * Iterating over a `Column` returns the values. * Iterating over a `Row` returns the column names, as specified in the [documenetation of `__iter__`](https://docs.python.org/3/reference/datamodel.html#object.__iter__). * Add `__len__` method to `Column` and `Row` to compute their length. * Change superclasses of exceptions as needed for [`__getitem__`](https://docs.python.org/3/reference/datamodel.html#object.__getitem__): * Change superclass of `IndexOutOfBoundsError` to `IndexError`. * Change superclass of `UnknownColumnNameError` to `KeyError`. --------- Co-authored-by: lars-reimann <[email protected]>
- Loading branch information
1 parent
c3fd3b5
commit 74eea1f
Showing
14 changed files
with
102 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import pandas as pd | ||
from safeds.data.tabular import Table | ||
from safeds.data.tabular import Column | ||
|
||
|
||
def test_count_valid() -> None: | ||
table = Table(pd.DataFrame(data={"col1": [1, 2, 3, 4, 5], "col2": [2, 3, 4, 5, 6]})) | ||
assert table.get_column("col1").count() == 5 | ||
column = Column([1, 2, 3, 4, 5], "col1") | ||
assert column.count() == 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from safeds.data.tabular import Column | ||
|
||
|
||
def test_iter() -> None: | ||
column = Column([0, "1"], "testColumn") | ||
assert list(column) == [0, "1"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from safeds.data.tabular import Column | ||
|
||
|
||
def test_count_valid() -> None: | ||
column = Column([1, 2, 3, 4, 5], "col1") | ||
assert len(column) == 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from safeds.data.tabular import Row | ||
from safeds.data.tabular.typing import IntColumnType, StringColumnType, TableSchema | ||
|
||
|
||
def test_count() -> None: | ||
row = Row( | ||
[0, "1"], | ||
TableSchema( | ||
{"testColumn1": IntColumnType(), "testColumn2": StringColumnType()} | ||
), | ||
) | ||
assert row.count() == 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from safeds.data.tabular import Row | ||
from safeds.data.tabular.typing import IntColumnType, StringColumnType, TableSchema | ||
|
||
|
||
def test_iter() -> None: | ||
row = Row( | ||
[0, "1"], | ||
TableSchema( | ||
{"testColumn1": IntColumnType(), "testColumn2": StringColumnType()} | ||
), | ||
) | ||
assert list(row) == ["testColumn1", "testColumn2"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from safeds.data.tabular import Row | ||
from safeds.data.tabular.typing import IntColumnType, StringColumnType, TableSchema | ||
|
||
|
||
def test_count() -> None: | ||
row = Row( | ||
[0, "1"], | ||
TableSchema( | ||
{"testColumn1": IntColumnType(), "testColumn2": StringColumnType()} | ||
), | ||
) | ||
assert len(row) == 2 |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.