Skip to content

Commit

Permalink
docs: Highlighting the fact, that certain methods do not work in place (
Browse files Browse the repository at this point in the history
#279)

Closes #189.

### Summary of Changes

Highlighting the fact, that fitting methods of Classifier, Regressor,
Tabletransformer and certain methods of the _table class do not work in
place.

---------

Co-authored-by: Lars Reimann <[email protected]>
Co-authored-by: megalinter-bot <[email protected]>
  • Loading branch information
3 people authored May 6, 2023
1 parent 40fb756 commit dcf2e6c
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

### Features

* `OneHotEncoder.inverse_transform` now maintains the column order from the original table ([#195](https://github.com/Safe-DS/Stdlib/issues/195)) ([3ec0041](https://github.com/Safe-DS/Stdlib/commit/3ec0041669ffe97640f96db345f3f43720d5c3f7)), closes [#109](https://github.com/Safe-DS/Stdlib/issues/109) [#109](https://github.com/Safe-DS/Stdlib/issues/109)
* `OneHotEncoder.inverse_transform` now maintains the column order from the original table ([#195](https://github.com/Safe-DS/Stdlib/issues/195)) ([3ec0041](https://github.com/Safe-DS/Stdlib/commit/3ec0041669ffe97640f96db345f3f43720d5c3f7)), closes [#109](https://github.com/Safe-DS/Stdlib/issues/109)
* add `plot_` prefix back to plotting methods ([#212](https://github.com/Safe-DS/Stdlib/issues/212)) ([e50c3b0](https://github.com/Safe-DS/Stdlib/commit/e50c3b0118825e33eef0e2a7073673603e316ee5)), closes [#211](https://github.com/Safe-DS/Stdlib/issues/211)
* adjust `Column`, `Schema` and `Table` to changes in `Row` ([#216](https://github.com/Safe-DS/Stdlib/issues/216)) ([ca3eebb](https://github.com/Safe-DS/Stdlib/commit/ca3eebbe2166f08d76cdcb89a012518ae8ff8e4e))
* back `Row` by a `polars.DataFrame` ([#214](https://github.com/Safe-DS/Stdlib/issues/214)) ([62ca34d](https://github.com/Safe-DS/Stdlib/commit/62ca34dd399da8b4e34b89bad408311707b53f41)), closes [#196](https://github.com/Safe-DS/Stdlib/issues/196) [#149](https://github.com/Safe-DS/Stdlib/issues/149)
Expand Down
62 changes: 62 additions & 0 deletions src/safeds/data/tabular/containers/_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def from_csv_file(path: str | Path) -> Table:
"""
Read data from a CSV file into a table.
This table is not modified.
Parameters
----------
path : str | Path
Expand Down Expand Up @@ -90,6 +92,8 @@ def from_excel_file(path: str | Path) -> Table:
"""
Read data from an Excel file into a table.
This table is not modified.
Parameters
----------
path : str | Path
Expand Down Expand Up @@ -117,6 +121,8 @@ def from_json_file(path: str | Path) -> Table:
"""
Read data from a JSON file into a table.
This table is not modified.
Parameters
----------
path : str | Path
Expand Down Expand Up @@ -144,6 +150,8 @@ def from_dict(data: dict[str, list[Any]]) -> Table:
"""
Create a table from a dictionary that maps column names to column values.
This table is not modified.
Parameters
----------
data : dict[str, list[Any]]
Expand Down Expand Up @@ -180,6 +188,8 @@ def from_columns(columns: list[Column]) -> Table:
"""
Return a table created from a list of columns.
This table is not modified.
Parameters
----------
columns : list[Column]
Expand Down Expand Up @@ -211,6 +221,8 @@ def from_rows(rows: list[Row]) -> Table:
"""
Return a table created from a list of rows.
This table is not modified.
Parameters
----------
rows : list[Row]
Expand Down Expand Up @@ -248,6 +260,8 @@ def _from_pandas_dataframe(data: pd.DataFrame, schema: Schema | None = None) ->
"""
Create a table from a `pandas.DataFrame`.
This table is not modified.
Parameters
----------
data : pd.DataFrame
Expand Down Expand Up @@ -483,6 +497,8 @@ def summary(self) -> Table:
"""
Return a table with a number of statistical key values.
This table is not modified.
Returns
-------
result : Table
Expand Down Expand Up @@ -528,6 +544,8 @@ def add_column(self, column: Column) -> Table:
"""
Return the original table with the provided column attached at the end.
This table is not modified.
Returns
-------
result : Table
Expand Down Expand Up @@ -557,6 +575,8 @@ def add_columns(self, columns: list[Column] | Table) -> Table:
"""
Add multiple columns to the table.
This table is not modified.
Parameters
----------
columns : list[Column] or Table
Expand Down Expand Up @@ -592,6 +612,8 @@ def add_row(self, row: Row) -> Table:
"""
Add a row to the table.
This table is not modified.
Parameters
----------
row : Row
Expand All @@ -614,6 +636,8 @@ def add_rows(self, rows: list[Row] | Table) -> Table:
"""
Add multiple rows to a table.
This table is not modified.
Parameters
----------
rows : list[Row] or Table
Expand Down Expand Up @@ -641,6 +665,8 @@ def filter_rows(self, query: Callable[[Row], bool]) -> Table:
"""
Return a table with rows filtered by Callable (e.g. lambda function).
This table is not modified.
Parameters
----------
query : lambda function
Expand All @@ -662,6 +688,8 @@ def keep_only_columns(self, column_names: list[str]) -> Table:
"""
Return a table with only the given column(s).
This table is not modified.
Parameters
----------
column_names : list[str]
Expand Down Expand Up @@ -692,6 +720,8 @@ def remove_columns(self, column_names: list[str]) -> Table:
"""
Return a table without the given column(s).
This table is not modified.
Parameters
----------
column_names : list[str]
Expand Down Expand Up @@ -722,6 +752,8 @@ def remove_columns_with_missing_values(self) -> Table:
"""
Return a table without the columns that contain missing values.
This table is not modified.
Returns
-------
table : Table
Expand All @@ -733,6 +765,8 @@ def remove_columns_with_non_numerical_values(self) -> Table:
"""
Return a table without the columns that contain non-numerical values.
This table is not modified.
Returns
-------
table : Table
Expand All @@ -745,6 +779,8 @@ def remove_duplicate_rows(self) -> Table:
"""
Return a copy of the table with every duplicate row removed.
This table is not modified.
Returns
-------
result : Table
Expand All @@ -758,6 +794,8 @@ def remove_rows_with_missing_values(self) -> Table:
"""
Return a table without the rows that contain missing values.
This table is not modified.
Returns
-------
table : Table
Expand All @@ -775,6 +813,8 @@ def remove_rows_with_outliers(self) -> Table:
Missing values are not considered outliers. They are also ignored during the calculation of the standard
deviation.
This table is not modified.
Returns
-------
new_table : Table
Expand All @@ -792,6 +832,8 @@ def rename_column(self, old_name: str, new_name: str) -> Table:
"""
Rename a single column.
This table is not modified.
Parameters
----------
old_name : str
Expand Down Expand Up @@ -826,6 +868,8 @@ def replace_column(self, old_column_name: str, new_column: Column) -> Table:
"""
Return a copy of the table with the specified old column replaced by a new column. Keeps the order of columns.
This table is not modified.
Parameters
----------
old_column_name : str
Expand Down Expand Up @@ -874,6 +918,8 @@ def shuffle_rows(self) -> Table:
"""
Shuffle the table randomly.
This table is not modified.
Returns
-------
result : Table
Expand All @@ -893,6 +939,8 @@ def slice_rows(
"""
Slice a part of the table into a new table.
This table is not modified.
Parameters
----------
start : int
Expand Down Expand Up @@ -942,6 +990,8 @@ def sort_columns(
If no comparator is given, the columns will be sorted alphabetically by their name.
This table is not modified.
Parameters
----------
comparator : Callable[[Column, Column], int]
Expand All @@ -967,6 +1017,8 @@ def sort_rows(self, comparator: Callable[[Row, Row], int]) -> Table:
* If `row1` should be ordered after `row2`, the function should return a positive number.
* If the original order of `row1` and `row2` should be kept, the function should return 0.
This table is not modified.
Parameters
----------
comparator : Callable[[Row, Row], int]
Expand All @@ -985,6 +1037,8 @@ def split(self, percentage_in_first: float) -> tuple[Table, Table]:
"""
Split the table into two new tables.
This table is not modified.
Parameters
----------
percentage_in_first : float
Expand All @@ -1009,6 +1063,8 @@ def tag_columns(self, target_name: str, feature_names: list[str] | None = None)
"""
Mark the columns of the table as target column or feature columns. The original table is not modified.
This table is not modified.
Parameters
----------
target_name : str
Expand All @@ -1029,6 +1085,8 @@ def transform_column(self, name: str, transformer: Callable[[Row], Any]) -> Tabl
"""
Transform provided column by calling provided transformer.
This table is not modified.
Returns
-------
result : Table
Expand All @@ -1050,6 +1108,8 @@ def transform_table(self, transformer: TableTransformer) -> Table:
"""
Apply a learned transformation onto this table.
This table is not modified.
Parameters
----------
transformer : TableTransformer
Expand Down Expand Up @@ -1084,6 +1144,8 @@ def inverse_transform_table(self, transformer: InvertibleTableTransformer) -> Ta
"""
Invert the transformation applied by the given transformer.
This table is not modified.
Parameters
----------
transformer : InvertibleTableTransformer
Expand Down
4 changes: 4 additions & 0 deletions src/safeds/data/tabular/transformation/_imputer.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def fit(self, table: Table, column_names: list[str] | None) -> Imputer:
"""
Learn a transformation for a set of columns in a table.
This transformer is not modified.
Parameters
----------
table : Table
Expand Down Expand Up @@ -133,6 +135,8 @@ def transform(self, table: Table) -> Table:
"""
Apply the learned transformation to a table.
The table is not modified.
Parameters
----------
table : Table
Expand Down
6 changes: 6 additions & 0 deletions src/safeds/data/tabular/transformation/_label_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def fit(self, table: Table, column_names: list[str] | None) -> LabelEncoder:
"""
Learn a transformation for a set of columns in a table.
This transformer is not modified.
Parameters
----------
table : Table
Expand Down Expand Up @@ -53,6 +55,8 @@ def transform(self, table: Table) -> Table:
"""
Apply the learned transformation to a table.
The table is not modified.
Parameters
----------
table : Table
Expand Down Expand Up @@ -86,6 +90,8 @@ def inverse_transform(self, transformed_table: Table) -> Table:
"""
Undo the learned transformation.
The table is not modified.
Parameters
----------
transformed_table : Table
Expand Down
26 changes: 17 additions & 9 deletions src/safeds/data/tabular/transformation/_one_hot_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def fit(self, table: Table, column_names: list[str] | None) -> OneHotEncoder:
"""
Learn a transformation for a set of columns in a table.
This transformer is not modified.
Parameters
----------
table : Table
Expand Down Expand Up @@ -61,6 +63,8 @@ def transform(self, table: Table) -> Table:
"""
Apply the learned transformation to a table.
The table is not modified.
Parameters
----------
table : Table
Expand Down Expand Up @@ -114,6 +118,8 @@ def inverse_transform(self, transformed_table: Table) -> Table:
"""
Undo the learned transformation.
The table is not modified.
Parameters
----------
transformed_table : Table
Expand Down Expand Up @@ -146,15 +152,17 @@ def inverse_transform(self, transformed_table: Table) -> Table:

res = Table(pd.concat([unchanged, decoded], axis=1))
column_names = [
name
if name not in [value for value_list in list(self._column_names.values()) for value in value_list]
else list(self._column_names.keys())[
[
list(self._column_names.values()).index(value)
for value in list(self._column_names.values())
if name in value
][0]
]
(
name
if name not in [value for value_list in list(self._column_names.values()) for value in value_list]
else list(self._column_names.keys())[
[
list(self._column_names.values()).index(value)
for value in list(self._column_names.values())
if name in value
][0]
]
)
for name in transformed_table.column_names
]
res = res.sort_columns(lambda col1, col2: column_names.index(col1.name) - column_names.index(col2.name))
Expand Down
Loading

0 comments on commit dcf2e6c

Please sign in to comment.