Skip to content

Commit

Permalink
feat: replace warnings with markdown printouts (#94)
Browse files Browse the repository at this point in the history
Resolves #41
  • Loading branch information
mbelak-dtml authored Sep 4, 2023
1 parent 0bab9ca commit 7ef547b
Show file tree
Hide file tree
Showing 5 changed files with 1,721 additions and 1,672 deletions.
3,362 changes: 1,703 additions & 1,659 deletions api-example.ipynb

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions edvart/report_sections/group_analysis.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Group analysis module."""

import warnings
from typing import Any, Callable, Dict, List, Optional, Union

import colorlover as cl
Expand Down Expand Up @@ -341,7 +340,12 @@ def group_barplot(
"""
num_cat = df[column].nunique()
if num_cat > group_count_threshold:
warnings.warn(f"Too many categories ({num_cat}), not plotting distribution")
display(
Markdown(
f"Number of unique values ({num_cat}) greater than threshold."
" Not plotting distribution"
)
)
return

pivot = df.pivot_table(index=groupby, columns=column, aggfunc="size", fill_value=0)
Expand Down Expand Up @@ -577,7 +581,6 @@ def required_imports(self) -> List[str]:
"import plotly.graph_objects as go",
"from edvart.data_types import infer_data_type, DataType",
"from edvart import utils",
"import warnings",
"from typing import List, Dict, Optional, Callable",
"from plotly.subplots import make_subplots",
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Seasonal decomposition package."""

import warnings
from typing import Any, Dict, List, Optional, Tuple

import matplotlib.pyplot as plt
Expand Down Expand Up @@ -91,9 +90,13 @@ def seasonal_decomposition(
"""
df = df.interpolate(method="time")
if pd.infer_freq(df.index) is None and period is None:
warnings.warn(
"Period could not be inferred, please set the period parameter to a suitable value."
"Decomposition will not be plotted."
display(
Markdown(
"<div class='alert alert-block alert-warning'>"
"Period could not be inferred, please set the `period` parameter"
" to a suitable value. Not plotting seasonal decomposition."
"</div>"
)
)
return
if columns is None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ def required_imports(self) -> List[str]:
]
return [
"from IPython.display import display, Markdown",
"import warnings",
"import plotly",
"import plotly.graph_objects as go",
"plotly.offline.init_notebook_mode()",
Expand Down
10 changes: 5 additions & 5 deletions edvart/report_sections/univariate_analysis.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Univariate analysis package."""
import warnings
from typing import Any, Callable, Dict, List, Optional, Tuple

import matplotlib.pyplot as plt
Expand Down Expand Up @@ -174,9 +173,11 @@ def bar_plot(
Additional kwargs passed to pandas.Series.bar.
"""
if series.nunique() > plotting_threshold:
warnings.warn(
f"Number of unique values is greater than {plotting_threshold},"
" not plotting bar plot."
display(
Markdown(
f"Number of unique values is greater than {plotting_threshold},"
" not plotting bar plot."
)
)
else:
value_counts = series.value_counts()
Expand Down Expand Up @@ -308,7 +309,6 @@ def required_imports(self) -> List[str]:
"import matplotlib.pyplot as plt",
"%matplotlib inline",
"import seaborn as sns",
"import warnings",
]

def add_cells(self, cells: List[Dict[str, Any]]) -> None:
Expand Down

0 comments on commit 7ef547b

Please sign in to comment.