Skip to content
This repository has been archived by the owner on Nov 23, 2024. It is now read-only.

Commit

Permalink
docs: adjust to API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-reimann committed Jun 17, 2024
1 parent c3575ce commit 0afba49
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 54 deletions.
2 changes: 2 additions & 0 deletions docs/datasets/disable_warnings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Disable output of warnings."""

from __future__ import annotations

import logging
import warnings

Expand Down
44 changes: 14 additions & 30 deletions docs/datasets/display_column_description.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,29 @@
"""Display column descriptions."""

import pandas as pd
from IPython.core.display_functions import DisplayHandle
from IPython.display import display
from __future__ import annotations

from IPython.core.display import DisplayObject
from IPython.display import Markdown
from safeds.data.tabular.containers import Table


def display_column_descriptions(column_descriptions: Table) -> DisplayHandle:
def display_column_descriptions(column_descriptions: Table) -> DisplayObject:
"""
Display a Table containing the column descriptions.
Parameters
----------
column_descriptions : Table
column_descriptions:
The column descriptions.
Returns
-------
DisplayHandle
The display handle.
display_object:
The display object.
"""
# Remember the current value of the max_colwidth option
max_colwidth = pd.get_option("max_colwidth")

# Don't cut off the column descriptions
pd.set_option("max_colwidth", None)

# Create a DisplayHandle that displays the column descriptions nicely
styler = (
column_descriptions._data.style.relabel_index(["Name", "Description"], axis="columns")
.hide(axis="index")
.set_properties(
**{
"text-align": "left",
"white-space": "pre-wrap",
},
)
)
result = display(styler)

# Restore the max_colwidth option
pd.set_option("max_colwidth", max_colwidth)

return result
result = ""

for name, description in column_descriptions._data_frame.iter_rows():
result += f"- **{name}:** {description}\n"

return Markdown(result)
16 changes: 5 additions & 11 deletions docs/datasets/house_sales.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"house_sales.slice_rows(end=10)"
],
"source": "house_sales.data.slice_rows(length=10)",
"metadata": {
"collapsed": false
}
Expand All @@ -73,9 +71,7 @@
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"print(str(house_sales.schema))"
],
"source": "print(str(house_sales.data.schema))",
"metadata": {
"collapsed": false
}
Expand All @@ -93,9 +89,7 @@
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"house_sales.summarize_statistics()"
],
"source": "house_sales.data.summarize_statistics()",
"metadata": {
"collapsed": false
}
Expand All @@ -114,7 +108,7 @@
"execution_count": null,
"outputs": [],
"source": [
"house_sales_correlation = house_sales.remove_columns([\n",
"house_sales_correlation = house_sales.data.remove_columns([\n",
" \"id\",\n",
" \"year\",\n",
" \"month\",\n",
Expand All @@ -123,7 +117,7 @@
" \"latitude\",\n",
" \"longitude\"\n",
"])\n",
"house_sales_correlation.plot_correlation_heatmap()"
"house_sales_correlation.plot.correlation_heatmap()"
],
"metadata": {
"collapsed": false
Expand Down
16 changes: 5 additions & 11 deletions docs/datasets/titanic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"titanic.slice_rows(end=10)"
],
"source": "titanic.data.slice_rows(length=10)",
"metadata": {
"collapsed": false
}
Expand All @@ -73,9 +71,7 @@
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"print(str(titanic.schema))"
],
"source": "print(str(titanic.data.schema))",
"metadata": {
"collapsed": false
}
Expand All @@ -93,9 +89,7 @@
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"titanic.summarize_statistics()"
],
"source": "titanic.data.summarize_statistics()",
"metadata": {
"collapsed": false
}
Expand All @@ -114,15 +108,15 @@
"execution_count": null,
"outputs": [],
"source": [
"titanic_correlation = titanic.keep_only_columns([\n",
"titanic_correlation = titanic.data.remove_columns_except([\n",
" \"age\",\n",
" \"siblings_spouses\",\n",
" \"parents_children\",\n",
" \"travel_class\",\n",
" \"fare\",\n",
" \"survived\"\n",
"])\n",
"titanic_correlation.plot_correlation_heatmap()"
"titanic_correlation.plot.correlation_heatmap()"
],
"metadata": {
"collapsed": false
Expand Down
4 changes: 2 additions & 2 deletions src/safeds_datasets/tabular/_house_sales/_house_sales.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def load_house_sales() -> TableWithDescriptions:
"floors": "Number of floors",
"bedrooms": "Number of bedrooms",
"bathrooms": (
"Number of bathrooms.\n\n"
"Number of bathrooms. "
"Fractional values indicate that components (toilet/sink/shower/bathtub) are missing."
),
"waterfront": "Whether the building overlooks a waterfront (0 = no, 1 = yes)",
Expand All @@ -42,7 +42,7 @@ def load_house_sales() -> TableWithDescriptions:
"grade": "Rating of building construction and design (1 to 13, higher is better)",
"year_built": "Year the house was built",
"year_renovated": (
"Year the house was last renovated.\n\nA value of 0 indicates that it was never renovated."
"Year the house was last renovated. A value of 0 indicates that it was never renovated."
),
"sqft_lot_15nn": "Lot area of the 15 nearest neighbors in square feet",
"sqft_living_15nn": "Interior living space of the 15 nearest neighbors in square feet",
Expand Down

0 comments on commit 0afba49

Please sign in to comment.