Skip to content

Commit

Permalink
feat: replace warnings with markdown printouts
Browse files Browse the repository at this point in the history
Resolves #41
  • Loading branch information
mbelak-dtml committed Aug 16, 2023
1 parent cfd6124 commit c89eccf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
8 changes: 5 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,11 @@ 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 +580,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,11 @@ 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(
"Period could not be inferred, please set the period parameter to a suitable value."
" Decomposition will not be plotted."
)
)
return
if columns is None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Time analysis interactive plot package."""

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

import nbformat.v4 as nbfv4
Expand Down Expand Up @@ -115,8 +114,6 @@ def _time_analysis_colored_plot(df, columns=None, color_col=None):
layout = dict(xaxis_rangeslider_visible=True)
if not utils.is_categorical(df[color_col]):
raise ValueError(f"Cannot color by non-categorical column `{color_col}`")
if df[color_col].nunique() > 20:
warnings.warn("Coloring by categorical column with many unique values!")
df_color_shifted = df[color_col].shift(-1)
for col in columns:
data = [
Expand Down Expand Up @@ -155,7 +152,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 c89eccf

Please sign in to comment.