@@ -797,6 +797,22 @@ def summary(self) -> Table:
797
797
# Transformations
798
798
# ------------------------------------------------------------------------------------------------------------------
799
799
800
+ # This method is meant as a way to "cast" instances of subclasses of `Table` to a proper `Table`, dropping any
801
+ # additional constraints that might have to hold in the subclass.
802
+ # Override accordingly in subclasses.
803
+ def _as_table (self : Table ) -> Table :
804
+ """
805
+ Transform the table to an instance of the Table class.
806
+
807
+ The original table is not modified.
808
+
809
+ Returns
810
+ -------
811
+ table: Table
812
+ The table, as an instance of the Table class.
813
+ """
814
+ return self
815
+
800
816
def add_column (self , column : Column ) -> Table :
801
817
"""
802
818
Return the original table with the provided column attached at the end.
@@ -888,8 +904,9 @@ def add_row(self, row: Row) -> Table:
888
904
"""
889
905
Add a row to the table.
890
906
907
+ If the table happens to be empty beforehand, respective columns will be added automatically.
908
+
891
909
This table is not modified.
892
- If the table happens to be empty beforehand, respective features will be added automatically.
893
910
894
911
Parameters
895
912
----------
@@ -1077,6 +1094,8 @@ def keep_only_columns(self, column_names: list[str]) -> Table:
1077
1094
------
1078
1095
UnknownColumnNameError
1079
1096
If any of the given columns does not exist.
1097
+ IllegalSchemaModificationError
1098
+ If removing the columns would violate an invariant in the subclass.
1080
1099
1081
1100
Examples
1082
1101
--------
@@ -1120,6 +1139,8 @@ def remove_columns(self, column_names: list[str]) -> Table:
1120
1139
------
1121
1140
UnknownColumnNameError
1122
1141
If any of the given columns does not exist.
1142
+ IllegalSchemaModificationError
1143
+ If removing the columns would violate an invariant in the subclass.
1123
1144
1124
1145
Examples
1125
1146
--------
@@ -1158,6 +1179,11 @@ def remove_columns_with_missing_values(self) -> Table:
1158
1179
table : Table
1159
1180
A table without the columns that contain missing values.
1160
1181
1182
+ Raises
1183
+ ------
1184
+ IllegalSchemaModificationError
1185
+ If removing the columns would violate an invariant in the subclass.
1186
+
1161
1187
Examples
1162
1188
--------
1163
1189
>>> from safeds.data.tabular.containers import Table
@@ -1182,6 +1208,11 @@ def remove_columns_with_non_numerical_values(self) -> Table:
1182
1208
table : Table
1183
1209
A table without the columns that contain non-numerical values.
1184
1210
1211
+ Raises
1212
+ ------
1213
+ IllegalSchemaModificationError
1214
+ If removing the columns would violate an invariant in the subclass.
1215
+
1185
1216
Examples
1186
1217
--------
1187
1218
>>> from safeds.data.tabular.containers import Table
@@ -1331,7 +1362,9 @@ def rename_column(self, old_name: str, new_name: str) -> Table:
1331
1362
1332
1363
def replace_column (self , old_column_name : str , new_columns : list [Column ]) -> Table :
1333
1364
"""
1334
- Return a copy of the table with the specified old column replaced by a list of new columns. Keeps the order of columns.
1365
+ Return a copy of the table with the specified old column replaced by a list of new columns.
1366
+
1367
+ The order of columns is kept.
1335
1368
1336
1369
This table is not modified.
1337
1370
@@ -1352,12 +1385,12 @@ def replace_column(self, old_column_name: str, new_columns: list[Column]) -> Tab
1352
1385
------
1353
1386
UnknownColumnNameError
1354
1387
If the old column does not exist.
1355
-
1356
1388
DuplicateColumnNameError
1357
1389
If at least one of the new columns already exists and the existing column is not affected by the replacement.
1358
-
1359
1390
ColumnSizeError
1360
1391
If the size of at least one of the new columns does not match the amount of rows.
1392
+ IllegalSchemaModificationError
1393
+ If replacing the column would violate an invariant in the subclass.
1361
1394
1362
1395
Examples
1363
1396
--------
@@ -1475,7 +1508,7 @@ def sort_columns(
1475
1508
"""
1476
1509
Sort the columns of a `Table` with the given comparator and return a new `Table`.
1477
1510
1478
- The original table is not modified. The comparator is a function that takes two columns `col1` and `col2` and
1511
+ The comparator is a function that takes two columns `col1` and `col2` and
1479
1512
returns an integer:
1480
1513
1481
1514
* If `col1` should be ordered before `col2`, the function should return a negative number.
@@ -1519,7 +1552,7 @@ def sort_rows(self, comparator: Callable[[Row, Row], int]) -> Table:
1519
1552
"""
1520
1553
Sort the rows of a `Table` with the given comparator and return a new `Table`.
1521
1554
1522
- The original table is not modified. The comparator is a function that takes two rows `row1` and `row2` and
1555
+ The comparator is a function that takes two rows `row1` and `row2` and
1523
1556
returns an integer:
1524
1557
1525
1558
* If `row1` should be ordered before `row2`, the function should return a negative number.
@@ -1695,6 +1728,8 @@ def transform_table(self, transformer: TableTransformer) -> Table:
1695
1728
------
1696
1729
TransformerNotFittedError
1697
1730
If the transformer has not been fitted yet.
1731
+ IllegalSchemaModificationError
1732
+ If replacing the column would violate an invariant in the subclass.
1698
1733
1699
1734
Examples
1700
1735
--------
0 commit comments