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

fix: fix imports when non-default subsections are specified #151

Merged
merged 1 commit into from
Sep 29, 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
16 changes: 9 additions & 7 deletions edvart/report_sections/bivariate_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ def __init__(
self.subsections_to_show = self._DEFAULT_SUBSECTIONS_TO_SHOW
else:
self.subsections_to_show = subsections
self.subsections_to_show_with_low_verbosity = [
sub
for sub in self.subsections_to_show
if self.subsection_verbosities[sub] == Verbosity.LOW
]

if (columns_x is None) != (columns_y is None):
raise ValueError("Either both or neither of columns_x, columns_y must be specified.")
Expand Down Expand Up @@ -170,15 +175,10 @@ def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None:
cells.append(section_header)
if self.verbosity == Verbosity.LOW:
code = "show_bivariate_analysis(df=df"
subsections_to_show_with_low_verbosity = [
sub
for sub in self.subsections_to_show
if self.subsection_verbosities[sub] == Verbosity.LOW
]
if subsections_to_show_with_low_verbosity != self._DEFAULT_SUBSECTIONS_TO_SHOW:
if self.subsections_to_show_with_low_verbosity != self._DEFAULT_SUBSECTIONS_TO_SHOW:
arg_subsections_names = [
f"BivariateAnalysis.BivariateAnalysisSubsection.{str(sub)}"
for sub in subsections_to_show_with_low_verbosity
for sub in self.subsections_to_show_with_low_verbosity
]

code += f", subsections={arg_subsections_names}".replace("'", "")
Expand Down Expand Up @@ -212,6 +212,8 @@ def required_imports(self) -> List[str]:
return super().required_imports()

imports = {"from edvart.report_sections.bivariate_analysis import show_bivariate_analysis"}
if self.subsections_to_show_with_low_verbosity != self._DEFAULT_SUBSECTIONS_TO_SHOW:
imports.add("from edvart.report_sections.bivariate_analysis import BivariateAnalysis")
for subsec in self.subsections:
if subsec.verbosity > Verbosity.LOW:
imports.update(subsec.required_imports())
Expand Down
18 changes: 11 additions & 7 deletions edvart/report_sections/dataset_overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ def __init__(
else:
self.subsections_to_show = subsections

self.subsections_to_show_with_low_verbosity = [
sub
for sub in self.subsections_to_show
if self.subsection_verbosities[sub] == Verbosity.LOW
]

# Construct objects that implement subsections
enum_to_implementation = {
subsec.QuickInfo: QuickInfo(verbosity_quick_info, columns),
Expand Down Expand Up @@ -146,6 +152,9 @@ def required_imports(self) -> List[str]:
"""
if self.verbosity == Verbosity.LOW:
imports = {"from edvart.report_sections.dataset_overview import show_overview"}
if self.subsections_to_show_with_low_verbosity != self._DEFAULT_SUBSECTIONS_TO_SHOW:
imports.add("from edvart.report_sections.dataset_overview import Overview")

for subsec in self.subsections:
if subsec.verbosity > Verbosity.LOW:
imports.update(subsec.required_imports())
Expand All @@ -170,15 +179,10 @@ def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None:

if self.verbosity == Verbosity.LOW:
code = "show_overview(df=df"
subsections_to_show_with_low_verbosity = [
sub
for sub in self.subsections_to_show
if self.subsection_verbosities[sub] == Verbosity.LOW
]
if subsections_to_show_with_low_verbosity != self._DEFAULT_SUBSECTIONS_TO_SHOW:
if self.subsections_to_show_with_low_verbosity != self._DEFAULT_SUBSECTIONS_TO_SHOW:
arg_subsections_names = [
f"Overview.OverviewSubsection.{str(sub)}"
for sub in subsections_to_show_with_low_verbosity
for sub in self.subsections_to_show_with_low_verbosity
]
code += f", subsections={arg_subsections_names}".replace("'", "")
if self.columns is not None:
Expand Down
19 changes: 12 additions & 7 deletions edvart/report_sections/multivariate_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ def __init__(
else:
self.subsections_to_show = subsections

self.subsections_to_show_with_low_verbosity = [
sub
for sub in self.subsections_to_show
if self.subsection_verbosities[sub] == Verbosity.LOW
]

enum_to_implementation = {
subsec.PCA: PCA(verbosity_pca, columns, color_col=color_col),
subsec.ParallelCoordinates: ParallelCoordinates(
Expand Down Expand Up @@ -146,6 +152,10 @@ def required_imports(self) -> List[str]:
"from edvart.report_sections.multivariate_analysis import"
" show_multivariate_analysis"
}
if self.subsections_to_show_with_low_verbosity != self._DEFAULT_SUBSECTIONS_TO_SHOW:
imports.add(
"from edvart.report_sections.multivariate_analysis import MultivariateAnalysis"
)
for subsec in self.subsections:
if subsec.verbosity > Verbosity.LOW:
imports.update(subsec.required_imports())
Expand All @@ -169,15 +179,10 @@ def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None:
cells.append(section_header)
if self.verbosity == Verbosity.LOW:
code = "show_multivariate_analysis(df=df"
subsections_to_show_with_low_verbosity = [
sub
for sub in self.subsections_to_show
if self.subsection_verbosities[sub] == Verbosity.LOW
]
if subsections_to_show_with_low_verbosity != self._DEFAULT_SUBSECTIONS_TO_SHOW:
if self.subsections_to_show_with_low_verbosity != self._DEFAULT_SUBSECTIONS_TO_SHOW:
arg_subsections_names = [
f"MultivariateAnalysis.MultivariateAnalysisSubsection.{str(sub)}"
for sub in subsections_to_show_with_low_verbosity
for sub in self.subsections_to_show_with_low_verbosity
]
code += f", subsections={arg_subsections_names}".replace("'", "")
if self.columns is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ def __init__(
else:
self.subsections_to_show = subsections

self.subsections_to_show_with_low_verbosity = [
sub
for sub in self.subsections_to_show
if self.subsection_verbosities[sub] == Verbosity.LOW
]

subsections_implementations = [
enum_to_implementation[sub] for sub in self.subsections_to_show
]
Expand Down Expand Up @@ -191,20 +197,16 @@ def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None:
if self.verbosity == Verbosity.LOW:
subsec = TimeseriesAnalysis.TimeseriesAnalysisSubsection
code = "show_timeseries_analysis(df=df"
subsections_to_show_with_low_verbosity = [
sub
for sub in self.subsections_to_show
if self.subsection_verbosities[sub] == Verbosity.LOW
]
if subsections_to_show_with_low_verbosity != self.default_subsections_to_show:
if self.subsections_to_show_with_low_verbosity != self.default_subsections_to_show:
arg_subsections_names = [
f"TimeseriesAnalysis.TimeseriesAnalysisSubsection.{str(sub)}"
for sub in subsections_to_show_with_low_verbosity
for sub in self.subsections_to_show_with_low_verbosity
]
code += f", subsections={arg_subsections_names}".replace("'", "")
stft_included = subsec.ShortTimeFT in subsections_to_show_with_low_verbosity
stft_included = subsec.ShortTimeFT in self.subsections_to_show_with_low_verbosity
include_sampling_rate = self.sampling_rate is not None and (
stft_included or subsec.FourierTransform in subsections_to_show_with_low_verbosity
stft_included
or subsec.FourierTransform in self.subsections_to_show_with_low_verbosity
)
if include_sampling_rate:
code += f", sampling_rate={self.sampling_rate}"
Expand Down Expand Up @@ -236,6 +238,11 @@ def required_imports(self) -> List[str]:
"from edvart.report_sections.timeseries_analysis.timeseries_analysis"
" import show_timeseries_analysis"
}
if self.subsections_to_show_with_low_verbosity != self.default_subsections_to_show:
imports.add(
"from edvart.report_sections.timeseries_analysis.timeseries_analysis"
" import TimeseriesAnalysis"
)
for sub in self.subsections:
if sub.verbosity > Verbosity.LOW:
imports.update(sub.required_imports())
Expand Down
3 changes: 2 additions & 1 deletion tests/test_bivariate_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,8 @@ def test_imports_verbosity_low_different_subsection_verbosities():
exported_imports = bivariate_section.required_imports()

expected_imports = {
"from edvart.report_sections.bivariate_analysis import show_bivariate_analysis"
"from edvart.report_sections.bivariate_analysis import show_bivariate_analysis",
"from edvart.report_sections.bivariate_analysis import BivariateAnalysis",
}
for s in bivariate_section.subsections:
if s.verbosity > Verbosity.LOW:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_multivariate_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,8 @@ def test_imports_verbosity_low_different_subsection_verbosities():
exported_imports = multivariate_section.required_imports()

expected_imports = {
"from edvart.report_sections.multivariate_analysis import show_multivariate_analysis"
"from edvart.report_sections.multivariate_analysis import show_multivariate_analysis",
"from edvart.report_sections.multivariate_analysis import MultivariateAnalysis",
}
for s in multivariate_section.subsections:
if s.verbosity > Verbosity.LOW:
Expand Down
5 changes: 4 additions & 1 deletion tests/test_overview_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,10 @@ def test_imports_verbosity_low_different_subsection_verbosities():

exported_imports = overview_section.required_imports()

expected_imports = {"from edvart.report_sections.dataset_overview import show_overview"}
expected_imports = {
"from edvart.report_sections.dataset_overview import show_overview",
"from edvart.report_sections.dataset_overview import Overview",
}
for s in overview_section.subsections:
if s.verbosity > Verbosity.LOW:
expected_imports.update(s.required_imports())
Expand Down
1 change: 1 addition & 0 deletions tests/test_timeseries_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ def test_imports_verbosity_low_different_subsection_verbosities():

expected_imports = {
"from edvart.report_sections.timeseries_analysis.timeseries_analysis import show_timeseries_analysis",
"from edvart.report_sections.timeseries_analysis.timeseries_analysis import TimeseriesAnalysis",
}
for s in ts_section.subsections:
if s.verbosity > Verbosity.LOW:
Expand Down