Skip to content

Commit

Permalink
refactor: use new Verbosity enum instead of int (#81)
Browse files Browse the repository at this point in the history
These changes should have been made in commit 521ce53.
  • Loading branch information
lukany authored Aug 10, 2023
1 parent 6865945 commit 291c990
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 26 deletions.
14 changes: 8 additions & 6 deletions edvart/report_sections/bivariate_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,13 @@ def __init__(
else:
subsections_all = subsections

# Store subsections with 0 verbosity
self.subsections_0 = [sub for sub in subsections_all if verbosities[sub] == 0]
# Store subsections with LOW verbosity
self.subsections_low_verbosity = [
sub for sub in subsections_all if verbosities[sub] == Verbosity.LOW
]

if len(self.subsections_0) == len(subsections_all) and subsections is None:
self.subsections_0 = None
if len(self.subsections_low_verbosity) == len(subsections_all) and subsections is None:
self.subsections_low_verbosity = None

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 @@ -231,10 +233,10 @@ def add_cells(self, cells: List[Dict[str, Any]]) -> None:
cells.append(section_header)
if self.verbosity == Verbosity.LOW:
code = "bivariate_analysis(df=df"
if self.subsections_0 is not None:
if self.subsections_low_verbosity is not None:
arg_subsections_names = [
f"BivariateAnalysis.BivariateAnalysisSubsection.{str(sub)}"
for sub in self.subsections_0
for sub in self.subsections_low_verbosity
]

code += f", subsections={arg_subsections_names}".replace("'", "")
Expand Down
15 changes: 9 additions & 6 deletions edvart/report_sections/dataset_overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,13 @@ def __init__(
else:
subsections_all = subsections

# Store subsections with 0 verbosity
self.subsections_0 = [sub for sub in subsections_all if verbosities[sub] == 0]
# Store subsections with LOW verbosity
self.subsections_low_verbosity = [
sub for sub in subsections_all if verbosities[sub] == Verbosity.LOW
]

if len(self.subsections_0) == len(subsections_all) and subsections is None:
self.subsections_0 = None
if len(self.subsections_low_verbosity) == len(subsections_all) and subsections is None:
self.subsections_low_verbosity = None

# Construct objects that implement subsections
enum_to_implementation = {
Expand Down Expand Up @@ -212,9 +214,10 @@ def add_cells(self, cells: List[Dict[str, Any]]) -> None:

if self.verbosity == Verbosity.LOW:
code = "overview_analysis(df=df"
if self.subsections_0 is not None:
if self.subsections_low_verbosity is not None:
arg_subsections_names = [
f"Overview.OverviewSubsection.{str(sub)}" for sub in self.subsections_0
f"Overview.OverviewSubsection.{str(sub)}"
for sub in self.subsections_low_verbosity
]
code += f", subsections={arg_subsections_names}".replace("'", "")
if self.columns is not None:
Expand Down
14 changes: 8 additions & 6 deletions edvart/report_sections/multivariate_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,13 @@ def __init__(
else:
subsections_all = subsections

# Store subsections with 0 verbosity
self.subsections_0 = [sub for sub in subsections_all if verbosities[sub] == 0]
# Store subsections with LOW verbosity
self.subsections_low_verbosity = [
sub for sub in subsections_all if verbosities[sub] == Verbosity.LOW
]

if len(self.subsections_0) == len(subsections_all) and subsections is None:
self.subsections_0 = None
if len(self.subsections_low_verbosity) == len(subsections_all) and subsections is None:
self.subsections_low_verbosity = None

enum_to_implementation = {
subsec.PCA: PCA(df, verbosity_pca, columns, color_col=color_col),
Expand Down Expand Up @@ -210,10 +212,10 @@ def add_cells(self, cells: List[Dict[str, Any]]) -> None:
cells.append(section_header)
if self.verbosity == Verbosity.LOW:
code = "multivariate_analysis(df=df"
if self.subsections_0 is not None:
if self.subsections_low_verbosity is not None:
arg_subsections_names = [
f"MultivariateAnalysis.MultivariateAnalysisSubsection.{str(sub)}"
for sub in self.subsections_0
for sub in self.subsections_low_verbosity
]
code += f", subsections={arg_subsections_names}".replace("'", "")
if self.columns is not None:
Expand Down
19 changes: 11 additions & 8 deletions edvart/report_sections/timeseries_analysis/timeseries_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,13 @@ def __init__(
else:
subsections_all = subsections

# Store subsections with Verbosity.LOW
self.subsections_0 = [sub for sub in subsections_all if verbosities[sub] == Verbosity.LOW]
# Store subsections with LOW verbosity
self.subsections_low_verbosity = [
sub for sub in subsections_all if verbosities[sub] == Verbosity.LOW
]

if len(self.subsections_0) == len(subsections_all) and subsections is None:
self.subsections_0 = None
if len(self.subsections_low_verbosity) == len(subsections_all) and subsections is None:
self.subsections_low_verbosity = None

if subsections is None:
subsections_implementations = list(enum_to_implementation.values())
Expand Down Expand Up @@ -258,18 +260,19 @@ def add_cells(self, cells: List[Dict[str, Any]]) -> None:
subsec = TimeseriesAnalysis.TimeseriesAnalysisSubsection
code = "timeseries_analysis(df=df"

if self.subsections_0 is not None:
if self.subsections_low_verbosity is not None:
arg_subsections_names = [
f"TimeseriesAnalysis.TimeseriesAnalysisSubsection.{str(sub)}"
for sub in self.subsections_0
for sub in self.subsections_low_verbosity
]
code += f", subsections={arg_subsections_names}".replace("'", "")

stft_included_or_empty = (
self.subsections_0 is None or subsec.ShortTimeFT in self.subsections_0
self.subsections_low_verbosity is None
or subsec.ShortTimeFT in self.subsections_low_verbosity
)
include_sampling_rate = self.sampling_rate is not None and (
stft_included_or_empty or subsec.FourierTransform in self.subsections_0
stft_included_or_empty or subsec.FourierTransform in self.subsections_low_verbosity
)
if include_sampling_rate:
code += f", sampling_rate={self.sampling_rate}"
Expand Down

0 comments on commit 291c990

Please sign in to comment.