Skip to content

Commit 92622fb

Browse files
refactor: extract column name and out of bounds checks (#758)
Closes #407 Closes #637 ### Summary of Changes * New internal function `_check_bounds` to check whether a value is in some interval or raise an `OutofBoundsError`. Now, bounds only need to be specified once instead of twice (if + when raising). * New internal function `_check_columns_exist` to check whether a column with a given name exists or raise an `ColumnNotFoundError`. Now, we get consistent error messages with suggestions of similar column names. --------- Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com>
1 parent e72339e commit 92622fb

File tree

96 files changed

+994
-1513
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+994
-1513
lines changed

benchmarks/metrics/classification.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
from __future__ import annotations
22

33
from timeit import timeit
4-
from typing import TYPE_CHECKING
54

65
import polars as pl
76

87
from benchmarks.table.utils import create_synthetic_table
98
from safeds.data.tabular.containers import Table
109
from safeds.ml.metrics import ClassificationMetrics
1110

12-
1311
REPETITIONS = 10
1412

1513

@@ -32,9 +30,7 @@ def _run_recall() -> None:
3230
if __name__ == "__main__":
3331
# Create a synthetic Table
3432
table = (
35-
create_synthetic_table(10000, 2)
36-
.rename_column("column_0", "predicted")
37-
.rename_column("column_1", "expected")
33+
create_synthetic_table(10000, 2).rename_column("column_0", "predicted").rename_column("column_1", "expected")
3834
)
3935

4036
# Run the benchmarks

docs/tutorials/classification.ipynb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
{
2424
"cell_type": "code",
2525
"execution_count": null,
26-
"outputs": [],
2726
"source": [
2827
"from safeds.data.tabular.containers import Table\n",
2928
"\n",
@@ -33,7 +32,8 @@
3332
],
3433
"metadata": {
3534
"collapsed": false
36-
}
35+
},
36+
"outputs": []
3737
},
3838
{
3939
"cell_type": "markdown",
@@ -48,15 +48,15 @@
4848
{
4949
"cell_type": "code",
5050
"execution_count": null,
51-
"outputs": [],
5251
"source": [
5352
"train_table, testing_table = titanic.split_rows(0.6)\n",
5453
"\n",
5554
"test_table = testing_table.remove_columns([\"survived\"]).shuffle_rows()"
5655
],
5756
"metadata": {
5857
"collapsed": false
59-
}
58+
},
59+
"outputs": []
6060
},
6161
{
6262
"cell_type": "markdown",
@@ -73,15 +73,15 @@
7373
{
7474
"cell_type": "code",
7575
"execution_count": null,
76-
"outputs": [],
7776
"source": [
7877
"from safeds.data.tabular.transformation import OneHotEncoder\n",
7978
"\n",
8079
"encoder = OneHotEncoder().fit(train_table, [\"sex\"])"
8180
],
8281
"metadata": {
8382
"collapsed": false
84-
}
83+
},
84+
"outputs": []
8585
},
8686
{
8787
"cell_type": "markdown",
@@ -95,11 +95,11 @@
9595
{
9696
"cell_type": "code",
9797
"execution_count": null,
98-
"outputs": [],
9998
"source": "transformed_table = encoder.transform(train_table)",
10099
"metadata": {
101100
"collapsed": false
102-
}
101+
},
102+
"outputs": []
103103
},
104104
{
105105
"cell_type": "markdown",
@@ -111,15 +111,15 @@
111111
{
112112
"cell_type": "code",
113113
"execution_count": null,
114-
"outputs": [],
115114
"source": [
116115
"extra_names = [\"id\", \"name\", \"ticket\", \"cabin\", \"port_embarked\", \"age\", \"fare\"]\n",
117116
"\n",
118117
"train_tabular_dataset = transformed_table.to_tabular_dataset(\"survived\", extra_names)"
119118
],
120119
"metadata": {
121120
"collapsed": false
122-
}
121+
},
122+
"outputs": []
123123
},
124124
{
125125
"cell_type": "markdown",
@@ -131,7 +131,6 @@
131131
{
132132
"cell_type": "code",
133133
"execution_count": null,
134-
"outputs": [],
135134
"source": [
136135
"from safeds.ml.classical.classification import RandomForestClassifier\n",
137136
"\n",
@@ -140,7 +139,8 @@
140139
],
141140
"metadata": {
142141
"collapsed": false
143-
}
142+
},
143+
"outputs": []
144144
},
145145
{
146146
"cell_type": "markdown",
@@ -155,7 +155,6 @@
155155
{
156156
"cell_type": "code",
157157
"execution_count": null,
158-
"outputs": [],
159158
"source": [
160159
"encoder = OneHotEncoder().fit(test_table, [\"sex\"])\n",
161160
"transformed_test_table = encoder.transform(test_table)\n",
@@ -168,7 +167,8 @@
168167
],
169168
"metadata": {
170169
"collapsed": false
171-
}
170+
},
171+
"outputs": []
172172
},
173173
{
174174
"cell_type": "markdown",
@@ -182,7 +182,6 @@
182182
{
183183
"cell_type": "code",
184184
"execution_count": null,
185-
"outputs": [],
186185
"source": [
187186
"encoder = OneHotEncoder().fit(test_table, [\"sex\"])\n",
188187
"testing_table = encoder.transform(testing_table)\n",
@@ -192,7 +191,8 @@
192191
],
193192
"metadata": {
194193
"collapsed": false
195-
}
194+
},
195+
"outputs": []
196196
}
197197
],
198198
"metadata": {

docs/tutorials/regression.ipynb

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
{
2424
"cell_type": "code",
2525
"execution_count": null,
26-
"outputs": [],
2726
"source": [
2827
"from safeds.data.tabular.containers import Table\n",
2928
"\n",
@@ -33,7 +32,8 @@
3332
],
3433
"metadata": {
3534
"collapsed": false
36-
}
35+
},
36+
"outputs": []
3737
},
3838
{
3939
"cell_type": "markdown",
@@ -48,15 +48,15 @@
4848
{
4949
"cell_type": "code",
5050
"execution_count": null,
51-
"outputs": [],
5251
"source": [
5352
"train_table, testing_table = pricing.split_rows(0.60)\n",
5453
"\n",
5554
"test_table = testing_table.remove_columns([\"price\"]).shuffle_rows()"
5655
],
5756
"metadata": {
5857
"collapsed": false
59-
}
58+
},
59+
"outputs": []
6060
},
6161
{
6262
"cell_type": "markdown",
@@ -68,15 +68,15 @@
6868
{
6969
"cell_type": "code",
7070
"execution_count": null,
71-
"outputs": [],
7271
"source": [
7372
"extra_names = [\"id\"]\n",
7473
"\n",
7574
"train_tabular_dataset = train_table.to_tabular_dataset(\"price\", extra_names)\n"
7675
],
7776
"metadata": {
7877
"collapsed": false
79-
}
78+
},
79+
"outputs": []
8080
},
8181
{
8282
"cell_type": "markdown",
@@ -88,7 +88,6 @@
8888
{
8989
"cell_type": "code",
9090
"execution_count": null,
91-
"outputs": [],
9291
"source": [
9392
"from safeds.ml.classical.regression import DecisionTreeRegressor\n",
9493
"\n",
@@ -97,7 +96,8 @@
9796
],
9897
"metadata": {
9998
"collapsed": false
100-
}
99+
},
100+
"outputs": []
101101
},
102102
{
103103
"cell_type": "markdown",
@@ -111,7 +111,6 @@
111111
{
112112
"cell_type": "code",
113113
"execution_count": null,
114-
"outputs": [],
115114
"source": [
116115
"prediction = fitted_model.predict(\n",
117116
" test_table\n",
@@ -121,7 +120,8 @@
121120
],
122121
"metadata": {
123122
"collapsed": false
124-
}
123+
},
124+
"outputs": []
125125
},
126126
{
127127
"cell_type": "markdown",
@@ -135,24 +135,15 @@
135135
{
136136
"cell_type": "code",
137137
"execution_count": null,
138-
"outputs": [
139-
{
140-
"data": {
141-
"text/plain": "105595.6001735107"
142-
},
143-
"execution_count": null,
144-
"metadata": {},
145-
"output_type": "execute_result"
146-
}
147-
],
148138
"source": [
149139
"test_tabular_dataset = testing_table.to_tabular_dataset(\"price\", extra_names)\n",
150140
"\n",
151141
"fitted_model.mean_absolute_error(test_tabular_dataset)\n"
152142
],
153143
"metadata": {
154144
"collapsed": false
155-
}
145+
},
146+
"outputs": []
156147
}
157148
],
158149
"metadata": {

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ plugins:
8787
- search
8888
- mkdocs-jupyter:
8989
include: ["*.ipynb"]
90-
execute: true
90+
execute: false # TODO: Enable execution
9191
allow_errors: false
9292
- exclude:
9393
glob:

0 commit comments

Comments
 (0)