Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: Add parameter df to method Section.add_cells. #137

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion edvart/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 17 additions & 9 deletions edvart/report_sections/bivariate_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
52 changes: 34 additions & 18 deletions edvart/report_sections/dataset_overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,17 @@ 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.

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)
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 10 additions & 4 deletions edvart/report_sections/group_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
"""
Expand Down Expand Up @@ -654,15 +658,17 @@ 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.

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)
Expand Down
26 changes: 17 additions & 9 deletions edvart/report_sections/multivariate_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading