diff --git a/edvart/report.py b/edvart/report.py index 9f7dbba..e6e2915 100755 --- a/edvart/report.py +++ b/edvart/report.py @@ -145,7 +145,7 @@ def _generate_notebook( if self._table_of_contents is not None: self._table_of_contents.add_cells(self.sections, nb["cells"]) for section in self.sections: - section.add_cells(nb["cells"]) + section.add_cells(cells=nb["cells"], df=self.df) return nb diff --git a/edvart/report_sections/bivariate_analysis.py b/edvart/report_sections/bivariate_analysis.py index 002e678..0d9a5c6 100644 --- a/edvart/report_sections/bivariate_analysis.py +++ b/edvart/report_sections/bivariate_analysis.py @@ -212,7 +212,7 @@ def bivariate_analysis( for sub in bivariate_analysis.subsections: sub.show(df) - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Adds cells to the list of cells. Cells can be either code cells or markdown cells. @@ -221,6 +221,8 @@ def add_cells(self, cells: List[Dict[str, Any]]) -> None: ---------- cells : List[Dict[str, Any]] List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells """ section_header = nbfv4.new_markdown_cell(self.get_title(section_level=1)) cells.append(section_header) @@ -251,9 +253,9 @@ def add_cells(self, cells: List[Dict[str, Any]]) -> None: cells.append(nbfv4.new_code_cell(code)) for sub in self.subsections: if sub.verbosity > Verbosity.LOW: - sub.add_cells(cells) + sub.add_cells(cells=cells, df=df) else: - super().add_cells(cells) + super().add_cells(cells=cells, df=df) def required_imports(self) -> List[str]: """Returns a list of imports to be put at the top of a generated notebook. @@ -518,13 +520,15 @@ def required_imports(self) -> List[str]: "from edvart.data_types import is_numeric", ] - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Adds cells to the list of cells. Cells can be either code cells or markdown cells. Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. """ section_header = nbfv4.new_markdown_cell(self.get_title(section_level=2)) cells.append(section_header) @@ -697,13 +701,15 @@ def required_imports(self) -> List[str]: "import seaborn as sns", ] - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Adds cells to the list of cells. Cells can be either code cells or markdown cells. Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. """ section_header = nbfv4.new_markdown_cell(self.get_title(section_level=2)) cells.append(section_header) @@ -958,13 +964,15 @@ def required_imports(self) -> List[str]: "import matplotlib.pyplot as plt", ] - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Adds cells to the list of cells. Cells can be either code cells or markdown cells. Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. """ section_header = nbfv4.new_markdown_cell(self.get_title(section_level=2)) cells.append(section_header) diff --git a/edvart/report_sections/dataset_overview.py b/edvart/report_sections/dataset_overview.py index 41ec4d7..8a4f5df 100644 --- a/edvart/report_sections/dataset_overview.py +++ b/edvart/report_sections/dataset_overview.py @@ -177,7 +177,7 @@ def required_imports(self) -> List[str]: return list(imports) return super().required_imports() - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Adds cells to the list of cells. Cells can be either code cells or markdown cells. @@ -185,7 +185,9 @@ def add_cells(self, cells: List[Dict[str, Any]]) -> None: Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. """ section_header = nbfv4.new_markdown_cell(self.get_title(section_level=1)) cells.append(section_header) @@ -209,9 +211,9 @@ def add_cells(self, cells: List[Dict[str, Any]]) -> None: cells.append(nbfv4.new_code_cell(code)) for subsec in self.subsections: if subsec.verbosity > Verbosity.LOW: - subsec.add_cells(cells) + subsec.add_cells(cells, df=df) else: - super().add_cells(cells) + super().add_cells(cells, df=df) def show(self, df: pd.DataFrame) -> None: """Generates cell output of this section in the calling notebook. @@ -302,13 +304,15 @@ def required_imports(self) -> List[str]: ] return [] - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Adds cells to the list of cells. Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. """ section_header = nbfv4.new_markdown_cell(self.get_title(section_level=2)) cells.append(section_header) @@ -410,13 +414,15 @@ def required_imports(self) -> List[str]: "from IPython.display import display", ] - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Adds data type inference cells to the list of cells. Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. """ section_header = nbfv4.new_markdown_cell(self.get_title(section_level=2)) cells.append(section_header) @@ -537,13 +543,15 @@ def required_imports(self) -> List[str]: "from IPython.display import Markdown", ] - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Adds dataframe preview cells to the list of cells. Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. """ section_header = nbfv4.new_markdown_cell(self.get_title(section_level=2)) cells.append(section_header) @@ -691,13 +699,15 @@ def required_imports(self) -> List[str]: "import matplotlib.pyplot as plt", ] - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Adds code cells which calculate missing values percentage table to the list of cells. Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. """ section_header = nbfv4.new_markdown_cell(self.get_title(section_level=2)) cells.append(section_header) @@ -822,13 +832,15 @@ def required_imports(self) -> List[str]: ] return base_imports + ["from IPython.display import display"] - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Adds code cells which calculate constant occurrence table to the list of cells. Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. """ section_header = nbfv4.new_markdown_cell(self.get_title(section_level=2)) cells.append(section_header) @@ -931,13 +943,15 @@ def required_imports(self) -> List[str]: ] return ["from IPython.display import display"] - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Adds code cells which count the number of rows with missing value to the list of cells. Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. """ section_header = nbfv4.new_markdown_cell(self.get_title(section_level=2)) cells.append(section_header) @@ -1040,13 +1054,15 @@ def required_imports(self) -> List[str]: ] return ["from IPython.display import display"] - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Adds code cells which count the number of duplicated rows to the list of cells. Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. """ section_header = nbfv4.new_markdown_cell(self.get_title(section_level=2)) cells.append(section_header) diff --git a/edvart/report_sections/group_analysis.py b/edvart/report_sections/group_analysis.py index b0ec305..fe93b49 100644 --- a/edvart/report_sections/group_analysis.py +++ b/edvart/report_sections/group_analysis.py @@ -593,7 +593,9 @@ def _add_function_defs(self, cells: List[Dict[str, Any]]): Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. """ code = ( get_code(GroupAnalysis.default_group_quantile_stats) @@ -621,7 +623,9 @@ def _add_cells_numeric_col(self, cells: List[Dict[str, Any]], column_name: str): Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. column_name : str Name of column for which to generate code. """ @@ -654,7 +658,7 @@ def _add_cells_numeric_col(self, cells: List[Dict[str, Any]], column_name: str): code += f"overlaid_histograms(df=df, groupby={self.groupby}, column='{column_name}')" cells.append(nbfv4.new_code_cell(code)) - def add_cells(self, cells: List[Dict[str, Any]]): + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Add cells to the list of cells. Cells can be either code cells or markdown cells. @@ -662,7 +666,9 @@ def add_cells(self, cells: List[Dict[str, Any]]): Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. """ section_header = nbfv4.new_markdown_cell(self.get_title(section_level=1)) cells.append(section_header) diff --git a/edvart/report_sections/multivariate_analysis.py b/edvart/report_sections/multivariate_analysis.py index 4ea8096..dc0830b 100644 --- a/edvart/report_sections/multivariate_analysis.py +++ b/edvart/report_sections/multivariate_analysis.py @@ -194,7 +194,7 @@ def required_imports(self) -> List[str]: return list(imports) return super().required_imports() - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Adds cells to the list of cells. Cells can be either code cells or markdown cells. @@ -203,6 +203,8 @@ def add_cells(self, cells: List[Dict[str, Any]]) -> None: ---------- cells : List[Dict[str, Any]] List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells """ section_header = nbfv4.new_markdown_cell(self.get_title(section_level=1)) cells.append(section_header) @@ -227,9 +229,9 @@ def add_cells(self, cells: List[Dict[str, Any]]) -> None: cells.append(nbfv4.new_code_cell(code)) for sub in self.subsections: if sub.verbosity > Verbosity.LOW: - sub.add_cells(cells) + sub.add_cells(cells=cells, df=df) else: - super().add_cells(cells) + super().add_cells(cells=cells, df=df) def show(self, df: pd.DataFrame) -> None: """Generates cell output of this section in the calling notebook. @@ -434,13 +436,15 @@ def required_imports(self) -> List[str]: "from sklearn.preprocessing import StandardScaler", ] - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Adds cells to the list of cells. Cells can be either code cells or markdown cells. Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. """ section_header = nbfv4.new_markdown_cell(self.get_title(section_level=2)) cells.append(section_header) @@ -660,13 +664,15 @@ def required_imports(self) -> List[str]: "plotly.offline.init_notebook_mode()", ] - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Adds cells to the list of cells. Cells can be either code cells or markdown cells. Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. """ section_header = nbfv4.new_markdown_cell(self.get_title(section_level=2)) cells.append(section_header) @@ -846,13 +852,15 @@ def required_imports(self) -> List[str]: "plotly.offline.init_notebook_mode()", ] - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Adds cells to the list of cells. Cells can be either code cells or markdown cells. Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. """ section_header = nbfv4.new_markdown_cell(self.get_title(section_level=2)) cells.append(section_header) diff --git a/edvart/report_sections/section_base.py b/edvart/report_sections/section_base.py index 346ee9e..3947b37 100644 --- a/edvart/report_sections/section_base.py +++ b/edvart/report_sections/section_base.py @@ -117,7 +117,7 @@ def required_imports(self) -> List[str]: """ @abstractmethod - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Adds cells to the list of cells. Cells can be either code cells or markdown cells. @@ -125,7 +125,9 @@ def add_cells(self, cells: List[Dict[str, Any]]) -> None: Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. The dictionaries can be generated with nbformat.v4.new_code_cell() and/or nbformat.v4.new_markdown_cell(). """ @@ -181,7 +183,7 @@ def required_imports(self) -> List[str]: return list(imports_set) - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Adds cells to the list of cells. Cells can be either code cells or markdown cells. @@ -189,10 +191,12 @@ def add_cells(self, cells: List[Dict[str, Any]]) -> None: Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. """ for subsec in self.subsections: - subsec.add_cells(cells) + subsec.add_cells(cells=cells, df=df) def show(self, df: pd.DataFrame) -> None: """Generates cell output of this section in the calling notebook. diff --git a/edvart/report_sections/table_of_contents.py b/edvart/report_sections/table_of_contents.py index 4aeea73..7a73e69 100644 --- a/edvart/report_sections/table_of_contents.py +++ b/edvart/report_sections/table_of_contents.py @@ -71,7 +71,7 @@ def _add_section_lines( for subsection in section.subsections: self._add_section_lines(subsection, section_level + 1, lines, True) - # pylint: disable=arguments-differ + # pylint: disable=arguments-renamed def add_cells(self, sections: List[Section], cells: List[Dict[str, Any]]) -> None: """Adds table of contents cells to the list of cells. The subsections won't be included. diff --git a/edvart/report_sections/timeseries_analysis/autocorrelation.py b/edvart/report_sections/timeseries_analysis/autocorrelation.py index dac6d01..8d7fd39 100644 --- a/edvart/report_sections/timeseries_analysis/autocorrelation.py +++ b/edvart/report_sections/timeseries_analysis/autocorrelation.py @@ -182,7 +182,7 @@ def required_imports(self) -> List[str]: "from edvart.data_types import is_numeric", ] - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Adds cells to the list of cells. Cells can be either code cells or markdown cells. @@ -190,7 +190,9 @@ def add_cells(self, cells: List[Dict[str, Any]]) -> None: Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. """ if self.verbosity == Verbosity.LOW: section_header = nbfv4.new_markdown_cell(self.get_title(section_level=2)) diff --git a/edvart/report_sections/timeseries_analysis/boxplots_over_time.py b/edvart/report_sections/timeseries_analysis/boxplots_over_time.py index 7638227..42c1fce 100644 --- a/edvart/report_sections/timeseries_analysis/boxplots_over_time.py +++ b/edvart/report_sections/timeseries_analysis/boxplots_over_time.py @@ -213,7 +213,7 @@ def required_imports(self) -> List[str]: "from edvart.data_types import is_numeric", ] - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Adds cells to the list of cells. Cells can be either code cells or markdown cells. @@ -221,7 +221,9 @@ def add_cells(self, cells: List[Dict[str, Any]]) -> None: Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. """ section_header = nbfv4.new_markdown_cell(self.get_title(section_level=2)) cells.append(section_header) diff --git a/edvart/report_sections/timeseries_analysis/fourier_transform.py b/edvart/report_sections/timeseries_analysis/fourier_transform.py index 6d80704..3e26c48 100644 --- a/edvart/report_sections/timeseries_analysis/fourier_transform.py +++ b/edvart/report_sections/timeseries_analysis/fourier_transform.py @@ -136,7 +136,7 @@ def required_imports(self) -> List[str]: "from edvart.data_types import is_numeric", ] - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Adds cells to the list of cells. Cells can be either code cells or markdown cells. @@ -144,7 +144,9 @@ def add_cells(self, cells: List[Dict[str, Any]]) -> None: Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. """ section_header = nbfv4.new_markdown_cell(self.get_title(section_level=2)) cells.append(section_header) diff --git a/edvart/report_sections/timeseries_analysis/rolling_statistics.py b/edvart/report_sections/timeseries_analysis/rolling_statistics.py index 367d3ea..f0d3815 100644 --- a/edvart/report_sections/timeseries_analysis/rolling_statistics.py +++ b/edvart/report_sections/timeseries_analysis/rolling_statistics.py @@ -188,7 +188,7 @@ def required_imports(self) -> List[str]: "from edvart.data_types import is_numeric", ] - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Adds cells to the list of cells. Cells can be either code cells or markdown cells. @@ -196,7 +196,9 @@ def add_cells(self, cells: List[Dict[str, Any]]) -> None: Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. """ section_header = nbfv4.new_markdown_cell(self.get_title(section_level=2)) cells.append(section_header) diff --git a/edvart/report_sections/timeseries_analysis/seasonal_decomposition.py b/edvart/report_sections/timeseries_analysis/seasonal_decomposition.py index c148160..45fa5a9 100644 --- a/edvart/report_sections/timeseries_analysis/seasonal_decomposition.py +++ b/edvart/report_sections/timeseries_analysis/seasonal_decomposition.py @@ -139,7 +139,7 @@ def required_imports(self) -> List[str]: "from edvart.data_types import is_numeric", ] - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Adds cells to the list of cells. Cells can be either code cells or markdown cells. @@ -147,7 +147,9 @@ def add_cells(self, cells: List[Dict[str, Any]]) -> None: Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. """ section_header = nbfv4.new_markdown_cell(self.get_title(section_level=2)) cells.append(section_header) diff --git a/edvart/report_sections/timeseries_analysis/short_time_ft.py b/edvart/report_sections/timeseries_analysis/short_time_ft.py index e722bde..b38a82c 100644 --- a/edvart/report_sections/timeseries_analysis/short_time_ft.py +++ b/edvart/report_sections/timeseries_analysis/short_time_ft.py @@ -171,7 +171,7 @@ def required_imports(self) -> List[str]: "from scipy import signal", ] - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Adds cells to the list of cells. Cells can be either code cells or markdown cells. @@ -179,7 +179,9 @@ def add_cells(self, cells: List[Dict[str, Any]]) -> None: Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. """ section_header = nbfv4.new_markdown_cell(self.get_title(section_level=2)) cells.append(section_header) diff --git a/edvart/report_sections/timeseries_analysis/stationarity_tests.py b/edvart/report_sections/timeseries_analysis/stationarity_tests.py index 8a7ab08..b1a6cc3 100644 --- a/edvart/report_sections/timeseries_analysis/stationarity_tests.py +++ b/edvart/report_sections/timeseries_analysis/stationarity_tests.py @@ -145,7 +145,7 @@ def required_imports(self) -> List[str]: "from edvart.pandas_formatting import format_number", ] - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Adds cells to the list of cells. Cells can be either code cells or markdown cells. @@ -153,7 +153,9 @@ def add_cells(self, cells: List[Dict[str, Any]]) -> None: Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. """ section_header = nbfv4.new_markdown_cell(self.get_title(section_level=2)) cells.append(section_header) diff --git a/edvart/report_sections/timeseries_analysis/time_series_line_plot.py b/edvart/report_sections/timeseries_analysis/time_series_line_plot.py index 4752b11..081da26 100644 --- a/edvart/report_sections/timeseries_analysis/time_series_line_plot.py +++ b/edvart/report_sections/timeseries_analysis/time_series_line_plot.py @@ -159,7 +159,7 @@ def required_imports(self) -> List[str]: "from edvart.data_types import is_numeric", ] - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Adds cells to the list of cells. Cells can be either code cells or markdown cells. @@ -167,7 +167,9 @@ def add_cells(self, cells: List[Dict[str, Any]]) -> None: Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. """ section_header = nbfv4.new_markdown_cell(self.get_title(section_level=2)) cells.append(section_header) diff --git a/edvart/report_sections/timeseries_analysis/timeseries_analysis.py b/edvart/report_sections/timeseries_analysis/timeseries_analysis.py index 675a121..ea0d0bc 100644 --- a/edvart/report_sections/timeseries_analysis/timeseries_analysis.py +++ b/edvart/report_sections/timeseries_analysis/timeseries_analysis.py @@ -221,7 +221,7 @@ def timeseries_analysis( for sub in timeseries_analysis.subsections: sub.show(df) - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Add cells to the list of cells. Cells can be either code cells or markdown cells. @@ -230,6 +230,8 @@ def add_cells(self, cells: List[Dict[str, Any]]) -> None: ---------- cells : List[Dict[str, Any]] List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells """ section_header = nbfv4.new_markdown_cell(self.get_title(section_level=1)) cells.append(section_header) @@ -264,9 +266,9 @@ def add_cells(self, cells: List[Dict[str, Any]]) -> None: for sub in self.subsections: if sub.verbosity > Verbosity.LOW: - sub.add_cells(cells) + sub.add_cells(cells=cells, df=df) else: - super().add_cells(cells) + super().add_cells(cells, df=df) def required_imports(self) -> List[str]: """Returns a list of imports to be put at the top of a generated notebook. diff --git a/edvart/report_sections/umap.py b/edvart/report_sections/umap.py index ee6523b..a268e55 100644 --- a/edvart/report_sections/umap.py +++ b/edvart/report_sections/umap.py @@ -197,13 +197,15 @@ def required_imports(self) -> List[str]: "from edvart.data_types import is_numeric", ] - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Adds cells to the list of cells. Cells can be either code cells or markdown cells. Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. """ section_header = nbfv4.new_markdown_cell(self.get_title(section_level=2)) cells.append(section_header) diff --git a/edvart/report_sections/univariate_analysis.py b/edvart/report_sections/univariate_analysis.py index cb25884..625fee9 100644 --- a/edvart/report_sections/univariate_analysis.py +++ b/edvart/report_sections/univariate_analysis.py @@ -309,13 +309,15 @@ def required_imports(self) -> List[str]: "import seaborn as sns", ] - def add_cells(self, cells: List[Dict[str, Any]]) -> None: + def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: """Adds univariate analysis cells to the list of cells. Parameters ---------- cells : List[Dict[str, Any]] - List of generated notebook cells which are represented as dictionaries. + List of generated notebook cells which are represented as dictionaries + df: pd.DataFrame + Data for which to add the cells. """ if self.columns is not None: self.df = self.df[self.columns] diff --git a/tests/test_bivariate_analysis.py b/tests/test_bivariate_analysis.py index d7d550e..93f9197 100644 --- a/tests/test_bivariate_analysis.py +++ b/tests/test_bivariate_analysis.py @@ -123,7 +123,7 @@ def test_code_export_verbosity_low(): bivariate_section = bivariate_analysis.BivariateAnalysis(verbosity=Verbosity.LOW) # Export code exported_cells = [] - bivariate_section.add_cells(exported_cells) + bivariate_section.add_cells(exported_cells, df=pd.DataFrame()) # Remove markdown and other cells and get code strings exported_code = [cell["source"] for cell in exported_cells if cell["cell_type"] == "code"] # Define expected code @@ -143,7 +143,7 @@ def test_code_export_verbosity_low_with_subsections(): ) # Export code exported_cells = [] - bivariate_section.add_cells(exported_cells) + bivariate_section.add_cells(exported_cells, df=pd.DataFrame()) # Remove markdown and other cells and get code strings exported_code = [cell["source"] for cell in exported_cells if cell["cell_type"] == "code"] # Define expected code @@ -172,7 +172,7 @@ def test_generated_code_verbosity_low_columns(): ) # Export code exported_cells = [] - bivariate_section.add_cells(exported_cells) + bivariate_section.add_cells(exported_cells, df=pd.DataFrame()) # Remove markdown and other cells and get code strings exported_code = [cell["source"] for cell in exported_cells if cell["cell_type"] == "code"] # Define expected code @@ -196,7 +196,7 @@ def test_generated_code_verbosity_medium(): ) exported_cells = [] - bivariate_section.add_cells(exported_cells) + bivariate_section.add_cells(exported_cells, df=pd.DataFrame()) exported_code = [cell["source"] for cell in exported_cells if cell["cell_type"] == "code"] expected_code = [ @@ -226,7 +226,7 @@ def test_generated_code_verbosity_medium_columns_x_y(): ) exported_cells = [] - bivariate_section.add_cells(exported_cells) + bivariate_section.add_cells(exported_cells, df=pd.DataFrame()) exported_code = [cell["source"] for cell in exported_cells if cell["cell_type"] == "code"] expected_code = [ @@ -255,7 +255,7 @@ def test_generated_code_verbosity_medium_columns_pairs(): ) exported_cells = [] - bivariate_section.add_cells(exported_cells) + bivariate_section.add_cells(exported_cells, df=pd.DataFrame()) exported_code = [cell["source"] for cell in exported_cells if cell["cell_type"] == "code"] expected_code = [ @@ -280,7 +280,7 @@ def test_generated_code_verbosity_high(): ) pairplot_cells = [] - bivariate_section.add_cells(pairplot_cells) + bivariate_section.add_cells(pairplot_cells, df=pd.DataFrame()) exported_code = [cell["source"] for cell in pairplot_cells if cell["cell_type"] == "code"] expected_code = [ @@ -328,7 +328,7 @@ def test_verbosity_low_different_subsection_verbosities(): ) bivariate_cells = [] - bivariate_section.add_cells(bivariate_cells) + bivariate_section.add_cells(bivariate_cells, df=pd.DataFrame()) exported_code = [cell["source"] for cell in bivariate_cells if cell["cell_type"] == "code"] expected_code = [ diff --git a/tests/test_group_analysis.py b/tests/test_group_analysis.py index 8a40449..5a919f9 100644 --- a/tests/test_group_analysis.py +++ b/tests/test_group_analysis.py @@ -81,7 +81,7 @@ def test_code_export_verbosity_low(): # Export code exported_cells = [] - group_section.add_cells(exported_cells) + group_section.add_cells(exported_cells, df=df) # Remove markdown and other cells and get code strings exported_code = [cell["source"] for cell in exported_cells if cell["cell_type"] == "code"] # Define expected code @@ -97,7 +97,7 @@ def test_code_export_verbosity_medium(): # Export code exported_cells = [] - group_section.add_cells(exported_cells) + group_section.add_cells(exported_cells, df=df) # Remove markdown and other cells and get code strings exported_code = [cell["source"] for cell in exported_cells if cell["cell_type"] == "code"] # Define expected code @@ -123,7 +123,7 @@ def test_code_export_verbosity_high(): # Export code exported_cells = [] - group_section.add_cells(exported_cells) + group_section.add_cells(exported_cells, df=df) # Remove markdown and other cells and get code strings exported_code = [cell["source"] for cell in exported_cells if cell["cell_type"] == "code"] # Define expected code @@ -183,7 +183,7 @@ def test_columns_parameter(): assert ga.groupby == ["A"] assert ga.columns is None ga.show(df) - ga.add_cells([]) + ga.add_cells([], df=df) assert ga.groupby == ["A"] assert ga.columns is None diff --git a/tests/test_multivariate_analysis.py b/tests/test_multivariate_analysis.py index db24707..ff53643 100644 --- a/tests/test_multivariate_analysis.py +++ b/tests/test_multivariate_analysis.py @@ -126,12 +126,13 @@ def test_section_adding(): def test_code_export_verbosity_low(): + df = get_test_df() multivariate_section = multivariate_analysis.MultivariateAnalysis( - df=get_test_df(), verbosity=Verbosity.LOW + df=df, verbosity=Verbosity.LOW ) # Export code exported_cells = [] - multivariate_section.add_cells(exported_cells) + multivariate_section.add_cells(exported_cells, df=df) # Remove markdown and other cells and get code strings exported_code = [cell["source"] for cell in exported_cells if cell["cell_type"] == "code"] # Define expected code @@ -146,13 +147,14 @@ def test_code_export_verbosity_low_with_subsections(): subsections = [subsec.ParallelCategories, subsec.PCA, subsec.ParallelCoordinates, subsec.PCA] if UMAP_AVAILABLE: subsections.append(subsec.UMAP) + df = get_test_df() multivariate_section = multivariate_analysis.MultivariateAnalysis( - df=get_test_df(), subsections=subsections, verbosity=Verbosity.LOW + df=df, subsections=subsections, verbosity=Verbosity.LOW ) # Export code exported_cells = [] - multivariate_section.add_cells(exported_cells) + multivariate_section.add_cells(exported_cells, df=df) # Remove markdown and other cells and get code strings exported_code = [cell["source"] for cell in exported_cells if cell["cell_type"] == "code"] if UMAP_AVAILABLE: @@ -191,7 +193,7 @@ def test_code_export_verbosity_medium_all_cols_valid(): ) exported_cells = [] - multivariate_section.add_cells(exported_cells) + multivariate_section.add_cells(exported_cells, df=all_numeric_df) exported_code = [cell["source"] for cell in exported_cells if cell["cell_type"] == "code"] expected_code = [ @@ -206,12 +208,13 @@ def test_code_export_verbosity_medium_all_cols_valid(): def test_generated_code_verbosity_1(): + df = get_test_df() multivariate_section = multivariate_analysis.MultivariateAnalysis( df=get_test_df(), verbosity=Verbosity.MEDIUM ) exported_cells = [] - multivariate_section.add_cells(exported_cells) + multivariate_section.add_cells(exported_cells, df=df) exported_code = [cell["source"] for cell in exported_cells if cell["cell_type"] == "code"] if UMAP_AVAILABLE: expected_code = [ @@ -244,12 +247,13 @@ def test_generated_code_verbosity_1(): def test_generated_code_verbosity_2(): + df = get_test_df() multivariate_section = multivariate_analysis.MultivariateAnalysis( - df=get_test_df(), verbosity=Verbosity.HIGH + df=df, verbosity=Verbosity.HIGH ) multivariate_cells = [] - multivariate_section.add_cells(multivariate_cells) + multivariate_section.add_cells(multivariate_cells, df=df) exported_code = [cell["source"] for cell in multivariate_cells if cell["cell_type"] == "code"] expected_code = [ "\n\n".join( @@ -313,7 +317,7 @@ def test_verbosity_medium_non_categorical_col(): ) multivariate_cells = [] - multivariate_section.add_cells(multivariate_cells) + multivariate_section.add_cells(multivariate_cells, df=random_df) exported_code = [cell["source"] for cell in multivariate_cells if cell["cell_type"] == "code"] expected_code = ["parallel_categories(df=df, columns=[])"] @@ -332,8 +336,9 @@ def test_verbosity_low_different_subsection_verbosities(): ] if UMAP_AVAILABLE: subsections.insert(2, MultivariateAnalysis.MultivariateAnalysisSubsection.UMAP) + df = get_test_df() multivariate_section = MultivariateAnalysis( - df=get_test_df(), + df=df, verbosity=Verbosity.LOW, subsections=subsections, verbosity_parallel_categories=Verbosity.MEDIUM, @@ -341,7 +346,7 @@ def test_verbosity_low_different_subsection_verbosities(): ) multivariate_cells = [] - multivariate_section.add_cells(multivariate_cells) + multivariate_section.add_cells(multivariate_cells, df=df) exported_code = [cell["source"] for cell in multivariate_cells if cell["cell_type"] == "code"] expected_subsections = [ "MultivariateAnalysis.MultivariateAnalysisSubsection.PCA", diff --git a/tests/test_overview_section.py b/tests/test_overview_section.py index 68de0a9..a2094f1 100644 --- a/tests/test_overview_section.py +++ b/tests/test_overview_section.py @@ -126,7 +126,7 @@ def test_code_export_verbosity_low(): overview_section = Overview(verbosity=Verbosity.LOW) # Export code exported_cells = [] - overview_section.add_cells(exported_cells) + overview_section.add_cells(exported_cells, df=pd.DataFrame()) # Remove markdown and other cells and get code strings exported_code = [cell["source"] for cell in exported_cells if cell["cell_type"] == "code"] # Define expected code @@ -145,7 +145,7 @@ def test_code_export_verbosity_low_with_subsections(): ) # Export code exported_cells = [] - overview_section.add_cells(exported_cells) + overview_section.add_cells(exported_cells, df=pd.DataFrame()) # Remove markdown and other cells and get code strings exported_code = [cell["source"] for cell in exported_cells if cell["cell_type"] == "code"] # Define expected code @@ -173,7 +173,7 @@ def test_code_export_verbosity_medium(): ) # Export code exported_cells = [] - overview_section.add_cells(exported_cells) + overview_section.add_cells(exported_cells, df=pd.DataFrame()) # Remove markdown and other cells and get code strings exported_code = [cell["source"] for cell in exported_cells if cell["cell_type"] == "code"] # Define expected code @@ -207,7 +207,7 @@ def test_code_export_verbosity_high(): ) # Export code exported_cells = [] - overview_section.add_cells(exported_cells) + overview_section.add_cells(exported_cells, df=pd.DataFrame()) # Remove markdown and other cells and get code strings exported_code = [cell["source"] for cell in exported_cells if cell["cell_type"] == "code"] # Define expected code @@ -275,7 +275,7 @@ def test_verbosity_low_different_subsection_verbosities(): ) overview_cells = [] - overview_section.add_cells(overview_cells) + overview_section.add_cells(overview_cells, df=pd.DataFrame()) exported_code = [cell["source"] for cell in overview_cells if cell["cell_type"] == "code"] expected_code = [ diff --git a/tests/test_timeseries_analysis.py b/tests/test_timeseries_analysis.py index b79faf0..a3d43b3 100644 --- a/tests/test_timeseries_analysis.py +++ b/tests/test_timeseries_analysis.py @@ -2,6 +2,7 @@ import warnings from contextlib import redirect_stdout +import pandas as pd import pytest import edvart @@ -170,7 +171,7 @@ def test_code_export_verbosity_low(): ts_section = TimeseriesAnalysis(verbosity=Verbosity.LOW) # Export code exported_cells = [] - ts_section.add_cells(exported_cells) + ts_section.add_cells(exported_cells, df=pd.DataFrame()) # Remove markdown and other cells and get code strings exported_code = [cell["source"] for cell in exported_cells if cell["cell_type"] == "code"] # Define expected code @@ -190,7 +191,7 @@ def test_code_export_verbosity_low_with_subsections(): ) # Export code exported_cells = [] - ts_section.add_cells(exported_cells) + ts_section.add_cells(exported_cells, df=pd.DataFrame()) # Remove markdown and other cells and get code strings exported_code = [cell["source"] for cell in exported_cells if cell["cell_type"] == "code"] # Define expected code @@ -216,7 +217,7 @@ def test_code_export_verbosity_low_with_fft_stft(): ) # Export code exported_cells = [] - ts_section.add_cells(exported_cells) + ts_section.add_cells(exported_cells, df=pd.DataFrame()) # Remove markdown and other cells and get code strings exported_code = [cell["source"] for cell in exported_cells if cell["cell_type"] == "code"] # Define expected code @@ -235,7 +236,7 @@ def test_generated_code_verbosity_medium(): ts_section = TimeseriesAnalysis(verbosity=Verbosity.MEDIUM) exported_cells = [] - ts_section.add_cells(exported_cells) + ts_section.add_cells(exported_cells, df=pd.DataFrame()) exported_code = [cell["source"] for cell in exported_cells if cell["cell_type"] == "code"] expected_code = [ @@ -257,7 +258,7 @@ def test_generated_code_verbosity_high(): ts_section = TimeseriesAnalysis(verbosity=Verbosity.HIGH, sampling_rate=1, stft_window_size=1) pairplot_cells = [] - ts_section.add_cells(pairplot_cells) + ts_section.add_cells(pairplot_cells, df=pd.DataFrame()) exported_code = [cell["source"] for cell in pairplot_cells if cell["cell_type"] == "code"] expected_code = [ @@ -350,7 +351,7 @@ def test_verbosity_low_different_subsection_verbosities(): ) ts_cells = [] - ts_section.add_cells(ts_cells) + ts_section.add_cells(ts_cells, df=pd.DataFrame()) exported_code = [cell["source"] for cell in ts_cells if cell["cell_type"] == "code"] expected_code = [ @@ -379,7 +380,7 @@ def month_func(x: datetime.datetime) -> str: boxplots_sub = BoxplotsOverTime(grouping_name="Month", grouping_function=month_func) # Export code exported_cells = [] - boxplots_sub.add_cells(exported_cells) + boxplots_sub.add_cells(exported_cells, df=pd.DataFrame()) # Remove markdown and other cells and get code strings exported_code = [cell["source"] for cell in exported_cells if cell["cell_type"] == "code"] @@ -400,7 +401,7 @@ def test_boxplots_over_time_lambda(): # Export code exported_cells = [] - boxplots_sub.add_cells(exported_cells) + boxplots_sub.add_cells(exported_cells, df=pd.DataFrame()) # Remove markdown and other cells and get code strings exported_code = [cell["source"] for cell in exported_cells if cell["cell_type"] == "code"] diff --git a/tests/test_univariate_analysis_section.py b/tests/test_univariate_analysis_section.py index bfd9986..ba3b1d5 100644 --- a/tests/test_univariate_analysis_section.py +++ b/tests/test_univariate_analysis_section.py @@ -28,7 +28,7 @@ def test_code_export_verbosity_low(): univariate_section = univariate_analysis.UnivariateAnalysis(df=test_df, verbosity=Verbosity.LOW) # Export code exported_cells = [] - univariate_section.add_cells(exported_cells) + univariate_section.add_cells(exported_cells, df=test_df) # Remove markdown and other cells and get code strings exported_code = [cell["source"] for cell in exported_cells if cell["cell_type"] == "code"] # Define expected code @@ -45,7 +45,7 @@ def test_code_export_verbosity_medium(): ) # Export code exported_cells = [] - univariate_section.add_cells(exported_cells) + univariate_section.add_cells(exported_cells, df=test_df) # Remove markdown and other cells and get code strings exported_code = [cell["source"] for cell in exported_cells if cell["cell_type"] == "code"] # Define expected code @@ -66,7 +66,7 @@ def test_code_export_verbosity_high(): ) # Export code exported_cells = [] - univariate_section.add_cells(exported_cells) + univariate_section.add_cells(exported_cells, df=test_df) # Remove markdown and other cells and get code strings exported_code = [cell["source"] for cell in exported_cells if cell["cell_type"] == "code"] # Define expected code