Skip to content

Commit

Permalink
feat: add parameter BoxplotsOverTime.group_function_imports (#157)
Browse files Browse the repository at this point in the history
The parameter adds the ability to use custom imports when a custom
grouping function is used.
  • Loading branch information
mbelak-dtml authored Oct 2, 2023
1 parent be80665 commit acade1c
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions edvart/report_sections/timeseries_analysis/boxplots_over_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class BoxplotsOverTime(Section):
function must be assigned an identifier.
To pass a lambda, simply assign it to a variable and pass the variable.
If None is passed, a default grouping will be selected (see `default_nunique_max`).
grouping_function_imports: List[str], optional
Additional imports required for the grouping function.
grouping_name : str, optional
Name of grouping, will be displayed as title of the horizontal axis.
default_nunique_max : int (default = 80)
Expand All @@ -49,10 +51,12 @@ def __init__(
verbosity: Verbosity = Verbosity.LOW,
columns: Optional[List[str]] = None,
grouping_function: Callable[[Any], str] = None,
grouping_function_imports: Optional[List[str]] = None,
grouping_name: Optional[str] = None,
default_nunique_max: int = 80,
):
self.grouping_function = grouping_function
self.grouping_function_imports = grouping_function_imports
self.grouping_name = grouping_name
self.default_nunique_max = default_nunique_max
super().__init__(verbosity, columns)
Expand All @@ -71,17 +75,21 @@ def required_imports(self) -> List[str]:
e.g. ["import pandas as pd", "import numpy as np"].
"""
if self.verbosity <= Verbosity.MEDIUM:
return [
imports = [
"from edvart.report_sections.timeseries_analysis.boxplots_over_time"
" import show_boxplots_over_time"
]
return [
"from datetime import datetime",
"import matplotlib.pyplot as plt",
"import seaborn as sns",
"from IPython.display import display, Markdown",
"from edvart.data_types import is_numeric",
]
else:
imports = [
"from datetime import datetime",
"import matplotlib.pyplot as plt",
"import seaborn as sns",
"from IPython.display import display, Markdown",
"from edvart.data_types import is_numeric",
]
if self.grouping_function_imports is not None:
imports.extend(self.grouping_function_imports)
return imports

def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None:
"""Adds cells to the list of cells.
Expand Down

0 comments on commit acade1c

Please sign in to comment.