-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: polars implementation of table (#744)
Closes #638 Closes #641 Closes #649 Closes #712 ### Summary of Changes Implement our table using polars as backend. --------- Co-authored-by: megalinter-bot <[email protected]>
- Loading branch information
1 parent
0564b52
commit fc49895
Showing
63 changed files
with
5,011 additions
and
465 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from timeit import timeit | ||
|
||
from safeds.data.tabular.containers import ExperimentalTable | ||
|
||
from benchmarks.table.utils import create_synthetic_table_polars | ||
|
||
REPETITIONS = 10 | ||
|
||
|
||
def _run_remove_columns_with_missing_values() -> None: | ||
table.remove_columns_with_missing_values()._lazy_frame.collect() | ||
|
||
|
||
def _run_remove_non_numeric_columns() -> None: | ||
table.remove_non_numeric_columns()._lazy_frame.collect() | ||
|
||
|
||
def _run_summarize_statistics() -> None: | ||
table.summarize_statistics()._lazy_frame.collect() | ||
|
||
|
||
if __name__ == "__main__": | ||
# Create a synthetic Table | ||
table = create_synthetic_table_polars(100, 5000) | ||
|
||
# Run the benchmarks | ||
timings: dict[str, float] = { | ||
"remove_columns_with_missing_values": timeit( | ||
_run_remove_columns_with_missing_values, | ||
number=REPETITIONS, | ||
), | ||
"remove_non_numeric_columns": timeit( | ||
_run_remove_non_numeric_columns, | ||
number=REPETITIONS, | ||
), | ||
"summarize_statistics": timeit( | ||
_run_summarize_statistics, | ||
number=REPETITIONS, | ||
), | ||
} | ||
|
||
# Print the timings | ||
print( | ||
ExperimentalTable( | ||
{ | ||
"method": list(timings.keys()), | ||
"timing": list(timings.values()), | ||
} | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"columns": [ | ||
{ "name": "a", "datatype": "Int64", "bit_settings": "", "values": [1, 2, 3] }, | ||
{ "name": "b", "datatype": "Int64", "bit_settings": "", "values": [4, 5, 6] } | ||
] | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"columns": [ | ||
{ "name": "a", "datatype": "Int64", "bit_settings": "", "values": [1, 2, 3] }, | ||
{ "name": "b", "datatype": "Int64", "bit_settings": "", "values": [4, 5, 6] } | ||
] | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
import polars as pl | ||
|
||
|
||
def _get_polars_config() -> pl.Config: | ||
import polars as pl | ||
|
||
return pl.Config( | ||
float_precision=5, | ||
tbl_cell_numeric_alignment="RIGHT", | ||
tbl_formatting="ASCII_FULL_CONDENSED", | ||
tbl_hide_dataframe_shape=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from __future__ import annotations | ||
|
||
import io | ||
from typing import TYPE_CHECKING | ||
|
||
from safeds.data.image.containers import Image | ||
|
||
if TYPE_CHECKING: | ||
import matplotlib.pyplot as plt | ||
|
||
|
||
def _figure_to_image(figure: plt.Figure) -> Image: | ||
""" | ||
Store the figure as an image and closes it. | ||
Parameters | ||
---------- | ||
figure: | ||
The figure to store. | ||
Returns | ||
------- | ||
image: | ||
The figure as an image. | ||
""" | ||
import matplotlib.pyplot as plt | ||
|
||
buffer = io.BytesIO() | ||
figure.savefig(buffer, format="png") | ||
plt.close(figure) # Prevents the figure from being displayed directly | ||
buffer.seek(0) | ||
return Image.from_bytes(buffer.read()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.