Skip to content

Commit e10e6bb

Browse files
fix: handle deprecations in third-party libraries (#963)
### Summary of Changes Migrate our code, so it no longer uses deprecated API elements of third-party libraries. --------- Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com>
1 parent fa62e9b commit e10e6bb

File tree

17 files changed

+66
-59
lines changed

17 files changed

+66
-59
lines changed

src/safeds/data/tabular/containers/_table.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ def add_columns(
472472
| 3 | 6 |
473473
+-----+-----+
474474
"""
475-
import polars as pl
475+
from polars.exceptions import DuplicateError
476476

477477
if isinstance(columns, Column):
478478
columns = [columns]
@@ -484,7 +484,7 @@ def add_columns(
484484
return Table._from_polars_data_frame(
485485
self._data_frame.hstack([column._series for column in columns]),
486486
)
487-
except pl.DuplicateError:
487+
except DuplicateError:
488488
# polars already validates this, so we don't need to do it again upfront (performance)
489489
_check_columns_dont_exist(self, [column.name for column in columns])
490490
return Table() # pragma: no cover
@@ -1706,7 +1706,7 @@ def join(
17061706
left_names: str | list[str],
17071707
right_names: str | list[str],
17081708
*,
1709-
mode: Literal["inner", "left", "outer"] = "inner",
1709+
mode: Literal["inner", "left", "right", "outer"] = "inner",
17101710
) -> Table:
17111711
"""
17121712
Join a table with the current table and return the result.
@@ -1720,7 +1720,7 @@ def join(
17201720
right_names:
17211721
Name or list of names of columns from right_table on which to join the current table.
17221722
mode:
1723-
Specify which type of join you want to use. Options include 'inner', 'outer', 'left', 'right'.
1723+
Specify which type of join you want to use.
17241724
17251725
Returns
17261726
-------
@@ -1750,12 +1750,17 @@ def join(
17501750
raise ValueError("The number of columns to join on must be the same in both tables.")
17511751

17521752
# Implementation
1753+
if mode == "outer":
1754+
polars_mode = "full"
1755+
else:
1756+
polars_mode = mode
1757+
17531758
return self._from_polars_lazy_frame(
17541759
self._lazy_frame.join(
17551760
right_table._lazy_frame,
17561761
left_on=left_names,
17571762
right_on=right_names,
1758-
how=mode,
1763+
how=polars_mode,
17591764
),
17601765
)
17611766

src/safeds/data/tabular/plotting/_table_plotter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,22 @@ def box_plots(self, *, theme: Literal["dark", "light"] = "light") -> Image:
9494
axs.boxplot(
9595
column,
9696
patch_artist=True,
97-
labels=[numerical_table.column_names[i]],
97+
tick_labels=[numerical_table.column_names[i]],
9898
)
9999
break
100100

101101
if number_of_rows == 1:
102102
axs[i].boxplot(
103103
column,
104104
patch_artist=True,
105-
labels=[numerical_table.column_names[i]],
105+
tick_labels=[numerical_table.column_names[i]],
106106
)
107107

108108
else:
109109
axs[line, i % number_of_columns].boxplot(
110110
column,
111111
patch_artist=True,
112-
labels=[numerical_table.column_names[i]],
112+
tick_labels=[numerical_table.column_names[i]],
113113
)
114114

115115
# removes unused ax indices, so there wont be empty plots

src/safeds/data/tabular/transformation/_label_encoder.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def transform(self, table: Table) -> Table:
162162
_check_columns_exist(table, self._column_names)
163163

164164
columns = [
165-
pl.col(name).replace(self._mapping[name], default=None, return_dtype=pl.UInt32)
165+
pl.col(name).replace_strict(self._mapping[name], default=None, return_dtype=pl.UInt32)
166166
for name in self._column_names
167167
]
168168

@@ -208,7 +208,9 @@ def inverse_transform(self, transformed_table: Table) -> Table:
208208
operation="inverse-transform with a LabelEncoder",
209209
)
210210

211-
columns = [pl.col(name).replace(self._inverse_mapping[name], default=None) for name in self._column_names]
211+
columns = [
212+
pl.col(name).replace_strict(self._inverse_mapping[name], default=None) for name in self._column_names
213+
]
212214

213215
return Table._from_polars_lazy_frame(
214216
transformed_table._lazy_frame.with_columns(columns),

tests/safeds/data/image/containers/test_image.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
from pathlib import Path
44
from tempfile import NamedTemporaryFile
55

6-
import numpy as np
7-
import PIL.Image
86
import pytest
97
import torch
108
from syrupy import SnapshotAssertion
@@ -107,20 +105,6 @@ def test_should_write_and_load_bytes_png(self, resource_path: str | Path, device
107105
assert image == image_copy
108106

109107

110-
@pytest.mark.parametrize("device", get_devices(), ids=get_devices_ids())
111-
class TestToNumpyArray:
112-
@pytest.mark.parametrize(
113-
"resource_path",
114-
images_all(),
115-
ids=images_all_ids(),
116-
)
117-
def test_should_return_numpy_array(self, resource_path: str | Path, device: Device) -> None:
118-
configure_test_with_device(device)
119-
image_safeds = Image.from_file(resolve_resource_path(resource_path))
120-
image_np = np.array(PIL.Image.open(resolve_resource_path(resource_path)))
121-
assert np.all(np.array(image_safeds).squeeze() == image_np)
122-
123-
124108
@pytest.mark.parametrize("device", get_devices(), ids=get_devices_ids())
125109
class TestReprJpeg:
126110
@pytest.mark.parametrize(

tests/safeds/data/tabular/containers/_row/test_column_count.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
2-
from safeds.data.tabular.containers import Row, Table
2+
3+
from safeds.data.tabular.containers import Table
34
from safeds.data.tabular.containers._lazy_vectorized_row import _LazyVectorizedRow
45

56

@@ -15,5 +16,5 @@
1516
],
1617
)
1718
def test_should_return_the_number_of_columns(table: Table, expected: int) -> None:
18-
row: Row[any] = _LazyVectorizedRow(table=table)
19+
row = _LazyVectorizedRow(table=table)
1920
assert row.column_count == expected

tests/safeds/data/tabular/containers/_row/test_column_names.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
2-
from safeds.data.tabular.containers import Row, Table
2+
3+
from safeds.data.tabular.containers import Table
34
from safeds.data.tabular.containers._lazy_vectorized_row import _LazyVectorizedRow
45

56

@@ -20,5 +21,5 @@
2021
],
2122
)
2223
def test_should_return_the_column_names(table: Table, expected: list[str]) -> None:
23-
row: Row[any] = _LazyVectorizedRow(table=table)
24+
row = _LazyVectorizedRow(table=table)
2425
assert row.column_names == expected

tests/safeds/data/tabular/containers/_row/test_contains.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
2-
from safeds.data.tabular.containers import Row, Table
2+
3+
from safeds.data.tabular.containers import Table
34
from safeds.data.tabular.containers._lazy_vectorized_row import _LazyVectorizedRow
45

56

@@ -19,5 +20,5 @@
1920
],
2021
)
2122
def test_should_return_whether_the_row_has_the_column(table: Table, column_name: str, expected: bool) -> None:
22-
row: Row[any] = _LazyVectorizedRow(table=table)
23+
row = _LazyVectorizedRow(table=table)
2324
assert (column_name in row) == expected

tests/safeds/data/tabular/containers/_row/test_eq.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
2-
from safeds.data.tabular.containers import Row, Table
2+
3+
from safeds.data.tabular.containers import Table
34
from safeds.data.tabular.containers._lazy_vectorized_row import _LazyVectorizedRow
45

56

@@ -21,8 +22,8 @@
2122
],
2223
)
2324
def test_should_return_whether_two_rows_are_equal(table1: Table, table2: Table, expected: bool) -> None:
24-
row1: Row[any] = _LazyVectorizedRow(table=table1)
25-
row2: Row[any] = _LazyVectorizedRow(table=table2)
25+
row1 = _LazyVectorizedRow(table=table1)
26+
row2 = _LazyVectorizedRow(table=table2)
2627
assert (row1.__eq__(row2)) == expected
2728

2829

@@ -38,7 +39,7 @@ def test_should_return_whether_two_rows_are_equal(table1: Table, table2: Table,
3839
],
3940
)
4041
def test_should_return_true_if_rows_are_strict_equal(table: Table, expected: bool) -> None:
41-
row1: Row[any] = _LazyVectorizedRow(table=table)
42+
row1 = _LazyVectorizedRow(table=table)
4243
assert (row1.__eq__(row1)) == expected
4344

4445

@@ -54,5 +55,5 @@ def test_should_return_true_if_rows_are_strict_equal(table: Table, expected: boo
5455
],
5556
)
5657
def test_should_return_false_if_object_is_other_type(table1: Table, table2: Table) -> None:
57-
row1: Row[any] = _LazyVectorizedRow(table=table1)
58+
row1 = _LazyVectorizedRow(table=table1)
5859
assert (row1.__eq__(table2)) == NotImplemented

tests/safeds/data/tabular/containers/_row/test_get_column_type.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
2-
from safeds.data.tabular.containers import Row, Table
2+
3+
from safeds.data.tabular.containers import Table
34
from safeds.data.tabular.containers._lazy_vectorized_row import _LazyVectorizedRow
45
from safeds.data.tabular.typing import DataType
56

@@ -16,5 +17,5 @@
1617
],
1718
)
1819
def test_should_return_the_type_of_the_column(table: Table, column_name: str, expected: DataType) -> None:
19-
row: Row[any] = _LazyVectorizedRow(table=table)
20+
row = _LazyVectorizedRow(table=table)
2021
assert str(row.get_column_type(column_name)) == expected

tests/safeds/data/tabular/containers/_row/test_getitem.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import re
22

33
import pytest
4-
from safeds.data.tabular.containers import Row, Table
4+
5+
from safeds.data.tabular.containers import Table
56
from safeds.data.tabular.containers._lazy_vectorized_row import _LazyVectorizedRow
67
from safeds.exceptions import ColumnNotFoundError
7-
88
from tests.helpers import assert_row_operation_works
99

1010

@@ -41,6 +41,6 @@ def test_should_get_correct_item(table_data: dict, column_name: str, target: int
4141
],
4242
)
4343
def test_should_raise_column_not_found_error(table: Table, column_name: str) -> None:
44-
row: Row[any] = _LazyVectorizedRow(table=table)
44+
row = _LazyVectorizedRow(table=table)
4545
with pytest.raises(ColumnNotFoundError, match=re.escape(f"Could not find column(s):\n - '{column_name}'")):
4646
row[column_name]

tests/safeds/data/tabular/containers/_row/test_has_column.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
2-
from safeds.data.tabular.containers import Row, Table
2+
3+
from safeds.data.tabular.containers import Table
34
from safeds.data.tabular.containers._lazy_vectorized_row import _LazyVectorizedRow
45

56

@@ -17,5 +18,5 @@
1718
],
1819
)
1920
def test_should_have_column_name(table: Table, column_name: str, expected: bool) -> None:
20-
row: Row[any] = _LazyVectorizedRow(table=table)
21+
row = _LazyVectorizedRow(table=table)
2122
assert row.has_column(column_name) == expected

tests/safeds/data/tabular/containers/_row/test_hash.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
2-
from safeds.data.tabular.containers import Row, Table
2+
3+
from safeds.data.tabular.containers import Table
34
from safeds.data.tabular.containers._lazy_vectorized_row import _LazyVectorizedRow
45

56

@@ -19,6 +20,6 @@
1920
],
2021
)
2122
def test_should_return_consistent_hashes(table1: Table, table2: Table, expected: bool) -> None:
22-
row1: Row[any] = _LazyVectorizedRow(table=table1)
23-
row2: Row[any] = _LazyVectorizedRow(table=table2)
23+
row1 = _LazyVectorizedRow(table=table1)
24+
row2 = _LazyVectorizedRow(table=table2)
2425
assert (hash(row1) == hash(row2)) == expected

tests/safeds/data/tabular/containers/_row/test_iter.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
2-
from safeds.data.tabular.containers import Row, Table
2+
3+
from safeds.data.tabular.containers import Table
34
from safeds.data.tabular.containers._lazy_vectorized_row import _LazyVectorizedRow
45

56

@@ -17,6 +18,6 @@
1718
],
1819
)
1920
def test_should_return_same_list_of_column_name_with_iter(table: Table, expected: list) -> None:
20-
row: Row[any] = _LazyVectorizedRow(table=table)
21+
row = _LazyVectorizedRow(table=table)
2122
iterable = iter(row)
2223
assert list(iterable) == expected

tests/safeds/data/tabular/containers/_row/test_len.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
2-
from safeds.data.tabular.containers import Row, Table
2+
3+
from safeds.data.tabular.containers import Table
34
from safeds.data.tabular.containers._lazy_vectorized_row import _LazyVectorizedRow
45

56

@@ -17,5 +18,5 @@
1718
],
1819
)
1920
def test_should_have_same_length_as_number_of_columns(table: Table, expected: int) -> None:
20-
row: Row[any] = _LazyVectorizedRow(table=table)
21+
row = _LazyVectorizedRow(table=table)
2122
assert len(row) == expected

tests/safeds/data/tabular/containers/_row/test_schema.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
2-
from safeds.data.tabular.containers import Row, Table
2+
3+
from safeds.data.tabular.containers import Table
34
from safeds.data.tabular.containers._lazy_vectorized_row import _LazyVectorizedRow
45

56

@@ -17,5 +18,5 @@
1718
],
1819
)
1920
def test_should_return_same_schema(table: Table) -> None:
20-
row: Row[any] = _LazyVectorizedRow(table=table)
21+
row = _LazyVectorizedRow(table=table)
2122
assert table.schema == row.schema
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import sys
2-
from typing import TYPE_CHECKING, Any
32

43
import polars as pl
5-
from safeds.data.tabular.containers._lazy_vectorized_row import _LazyVectorizedRow
64

7-
if TYPE_CHECKING:
8-
from safeds.data.tabular.containers import Row
5+
from safeds.data.tabular.containers._lazy_vectorized_row import _LazyVectorizedRow
96

107

118
def test_should_return_size_greater_than_normal_object() -> None:
12-
cell: Row[Any] = _LazyVectorizedRow(pl.col("a"))
9+
cell = _LazyVectorizedRow(pl.col("a"))
1310
assert sys.getsizeof(cell) > sys.getsizeof(object())

tests/safeds/data/tabular/containers/_table/test_join.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Literal
22

33
import pytest
4+
45
from safeds.data.tabular.containers import Table
56
from safeds.exceptions import ColumnNotFoundError
67

@@ -24,6 +25,14 @@
2425
"left",
2526
Table({"a": [1, 2], "b": [3, 4], "e": [5, None]}),
2627
),
28+
(
29+
Table({"a": [1, 2], "b": [3, 4]}),
30+
Table({"d": [1, 5], "e": [5, 6]}),
31+
["a"],
32+
["d"],
33+
"right",
34+
Table({"b": [3, None], "d": [1, 5], "e": [5, 6]}),
35+
),
2736
(
2837
Table({"a": [1, 2], "b": [3, 4]}),
2938
Table({"d": [1, 5], "e": [5, 6]}),
@@ -55,7 +64,7 @@ def test_should_join_two_tables(
5564
table_right: Table,
5665
left_names: list[str],
5766
right_names: list[str],
58-
mode: Literal["inner", "left", "outer"],
67+
mode: Literal["inner", "left", "right", "outer"],
5968
table_expected: Table,
6069
) -> None:
6170
assert table_left.join(table_right, left_names, right_names, mode=mode) == table_expected

0 commit comments

Comments
 (0)