Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/tutorials/data_processing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"execution_count": null,
"outputs": [],
"source": [
"titanic_slice = titanic.slice(end=10)\n",
"titanic_slice = titanic.slice_rows(end=10)\n",
"\n",
"titanic_slice # just to show the output"
],
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/data_visualization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"execution_count": null,
"outputs": [],
"source": [
"titanic.slice(end=10)"
"titanic.slice_rows(end=10)"
],
"metadata": {
"collapsed": false,
Expand Down
1 change: 0 additions & 1 deletion docs/tutorials/machine_learning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"execution_count": null,
"outputs": [],
"source": [
"from safeds.data.tabular.containers import TaggedTable\n",
"from safeds.data.tabular.containers import Table\n",
"\n",
"training_set = Table({\n",
Expand Down
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 @@ -783,7 +783,7 @@ def shuffle_rows(self) -> Table:
new_df.columns = self._schema.get_column_names()
return Table(new_df)

def slice(
def slice_rows(
self,
start: Optional[int] = None,
end: Optional[int] = None,
Expand Down Expand Up @@ -901,8 +901,8 @@ def split(self, percentage_in_first: float) -> tuple[Table, Table]:
if percentage_in_first <= 0 or percentage_in_first >= 1:
raise ValueError("the given percentage is not in range")
return (
self.slice(0, round(percentage_in_first * self.count_rows())),
self.slice(round(percentage_in_first * self.count_rows())),
self.slice_rows(0, round(percentage_in_first * self.count_rows())),
self.slice_rows(round(percentage_in_first * self.count_rows())),
)

def tag_columns(self, target_name: str, feature_names: Optional[list[str]] = None) -> TaggedTable:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@
from safeds.data.tabular.containers import Table


def test_slice_valid() -> None:
def test_slice_rows_valid() -> None:
table = Table(pd.DataFrame(data={"col1": [1, 2, 1], "col2": [1, 2, 4]}))
test_table = Table(pd.DataFrame(data={"col1": [1, 2], "col2": [1, 2]}))
second_test_table = Table(pd.DataFrame(data={"col1": [1, 1], "col2": [1, 4]}))
new_table = table.slice(0, 2, 1)
second_new_table = table.slice(0, 3, 2)
third_new_table = table.slice()
new_table = table.slice_rows(0, 2, 1)
second_new_table = table.slice_rows(0, 3, 2)
third_new_table = table.slice_rows()
assert new_table == test_table
assert second_new_table == second_test_table
assert third_new_table == table


def test_slice_invalid() -> None:
def test_slice_rows_invalid() -> None:
table = Table(pd.DataFrame(data={"col1": [1, 2, 1], "col2": [1, 2, 4]}))

with pytest.raises(ValueError):
table.slice(3, 2, 1)
table.slice_rows(3, 2, 1)
with pytest.raises(ValueError):
table.slice(4, 0, 1)
table.slice_rows(4, 0, 1)

with pytest.raises(ValueError):
table.slice(0, 4, 1)
table.slice_rows(0, 4, 1)

with pytest.raises(ValueError):
table.slice(-4, 0, 1)
table.slice_rows(-4, 0, 1)

with pytest.raises(ValueError):
table.slice(0, -4, 1)
table.slice_rows(0, -4, 1)