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 @@ -184,7 +184,7 @@
"execution_count": null,
"outputs": [],
"source": [
"titanic_slice.keep_columns([\"name\", \"survived\"])"
"titanic_slice.keep_only_columns([\"name\", \"survived\"])"
],
"metadata": {
"collapsed": false
Expand Down
2 changes: 1 addition & 1 deletion src/safeds/data/tabular/containers/_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ def filter_rows(self, query: Callable[[Row], bool]) -> Table:
result_table = self.from_rows(rows)
return result_table

def keep_columns(self, column_names: list[str]) -> Table:
def keep_only_columns(self, column_names: list[str]) -> Table:
"""
Return a table with only the given column(s).

Expand Down
2 changes: 1 addition & 1 deletion src/safeds/data/tabular/transformation/_label_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def fit(self, table: Table, column: str) -> None:
If the model fitting was unsuccessful.
"""
try:
self._le.fit(table.keep_columns([column])._data)
self._le.fit(table.keep_only_columns([column])._data)
except exceptions.NotFittedError as exc:
raise LearningError("") from exc

Expand Down
6 changes: 3 additions & 3 deletions src/safeds/data/tabular/transformation/_one_hot_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def fit(self, table: Table, columns: list[str]) -> None:
If there was an error during fitting.
"""
try:
table_k_columns = table.keep_columns(column_names=columns)
table_k_columns = table.keep_only_columns(column_names=columns)
df = table_k_columns._data
df.columns = table_k_columns.schema.get_column_names()
self._encoder.fit(df)
Expand All @@ -57,7 +57,7 @@ def transform(self, table: Table) -> Table:
If the encoder wasn't fitted before transforming.
"""
try:
table_k_columns = table.keep_columns(self._encoder.feature_names_in_)
table_k_columns = table.keep_only_columns(self._encoder.feature_names_in_)
df_k_columns = table_k_columns._data
df_k_columns.columns = table_k_columns.schema.get_column_names()
df_new = pd.DataFrame(self._encoder.transform(df_k_columns).toarray())
Expand Down Expand Up @@ -113,7 +113,7 @@ def inverse_transform(self, table: Table) -> Table:
"""
try:
data = self._encoder.inverse_transform(
table.keep_columns(self._encoder.get_feature_names_out())._data
table.keep_only_columns(self._encoder.get_feature_names_out())._data
)
df = pd.DataFrame(data)
df.columns = self._encoder.feature_names_in_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
from tests.fixtures import resolve_resource_path


def test_table_column_keep() -> None:
def test_keep_columns() -> None:
table = Table.from_csv(resolve_resource_path("test_table_read_csv.csv"))
transformed_table = table.keep_columns(["A"])
transformed_table = table.keep_only_columns(["A"])
assert transformed_table.schema.has_column(
"A"
) and not transformed_table.schema.has_column("B")


def test_table_column_keep_warning() -> None:
def test_keep_columns_warning() -> None:
table = Table.from_csv(resolve_resource_path("test_table_read_csv.csv"))
with pytest.raises(UnknownColumnNameError):
table.keep_columns(["C"])
table.keep_only_columns(["C"])