diff --git a/edvart/report.py b/edvart/report.py index 03b1907..9390fb9 100755 --- a/edvart/report.py +++ b/edvart/report.py @@ -14,14 +14,20 @@ import pandas as pd from edvart.data_types import is_date -from edvart.report_sections.bivariate_analysis import BivariateAnalysis +from edvart.report_sections.bivariate_analysis import BivariateAnalysis, BivariateAnalysisSubsection from edvart.report_sections.code_string_formatting import code_dedent -from edvart.report_sections.dataset_overview import Overview +from edvart.report_sections.dataset_overview import Overview, OverviewSubsection from edvart.report_sections.group_analysis import GroupAnalysis -from edvart.report_sections.multivariate_analysis import MultivariateAnalysis +from edvart.report_sections.multivariate_analysis import ( + MultivariateAnalysis, + MultivariateAnalysisSubsection, +) from edvart.report_sections.section_base import Section, Verbosity from edvart.report_sections.table_of_contents import TableOfContents -from edvart.report_sections.timeseries_analysis import TimeseriesAnalysis +from edvart.report_sections.timeseries_analysis import ( + TimeseriesAnalysis, + TimeseriesAnalysisSubsection, +) from edvart.report_sections.univariate_analysis import UnivariateAnalysis from edvart.utils import env_var @@ -322,7 +328,7 @@ def add_section( def add_overview( self, columns: Optional[List[str]] = None, - subsections: Optional[List[Overview.OverviewSubsection]] = None, + subsections: Optional[List[OverviewSubsection]] = None, verbosity: Optional[Verbosity] = None, verbosity_quick_info: Optional[Verbosity] = None, verbosity_data_types: Optional[Verbosity] = None, @@ -408,7 +414,7 @@ def add_bivariate_analysis( columns_x: Optional[List[str]] = None, columns_y: Optional[List[str]] = None, columns_pairs: Optional[List[Tuple[str, str]]] = None, - subsections: Optional[List[BivariateAnalysis.BivariateAnalysisSubsection]] = None, + subsections: Optional[List[BivariateAnalysisSubsection]] = None, verbosity: Optional[Verbosity] = None, verbosity_correlations: Optional[Verbosity] = None, verbosity_pairplot: Optional[Verbosity] = None, @@ -438,7 +444,7 @@ def add_bivariate_analysis( `columns`, `columns_x`, `columns_y` is specified. In that case, the first elements of each pair are treated as `columns_x` and the second elements as `columns_y` in pairplots and correlations. - subsections : List[BivariateAnalysis.BivariateAnalysisSubsection], optional + subsections : List[BivariateAnalysisSubsection], optional List of sub-sections to include into the BivariateAnalysis section. If None, all subsections are added. verbosity : Verbosity, optional @@ -473,7 +479,7 @@ def add_bivariate_analysis( def add_multivariate_analysis( self, columns: Optional[List[str]] = None, - subsections: Optional[List[MultivariateAnalysis.MultivariateAnalysisSubsection]] = None, + subsections: Optional[List[MultivariateAnalysisSubsection]] = None, verbosity: Optional[Verbosity] = None, verbosity_pca: Optional[Verbosity] = None, verbosity_umap: Optional[Verbosity] = None, @@ -488,7 +494,7 @@ def add_multivariate_analysis( columns : List[str], optional Columns which to analyze. If None, all columns are used. - subsections : List[MultivariateAnalysis.MultivariateAnalysisSubsection], optional + subsections : List[MultivariateAnalysisSubsection], optional List of sub-sections to include into the BivariateAnalysis section. If None, all subsections are added. verbosity : Verbosity, optional @@ -733,7 +739,7 @@ def __init__( def add_timeseries_analysis( self, columns: Optional[List[str]] = None, - subsections: Optional[List[TimeseriesAnalysis.TimeseriesAnalysisSubsection]] = None, + subsections: Optional[List[TimeseriesAnalysisSubsection]] = None, verbosity: Optional[Verbosity] = None, verbosity_time_series_line_plot: Optional[Verbosity] = None, verbosity_rolling_statistics: Optional[Verbosity] = None, diff --git a/edvart/report_sections/bivariate_analysis.py b/edvart/report_sections/bivariate_analysis.py index 2ebfe3f..f197015 100644 --- a/edvart/report_sections/bivariate_analysis.py +++ b/edvart/report_sections/bivariate_analysis.py @@ -17,6 +17,18 @@ from edvart.report_sections.section_base import ReportSection, Section, Verbosity +# pylint:disable=invalid-name +class BivariateAnalysisSubsection(IntEnum): + """Enum of all implemented bivariate analysis subsections.""" + + CorrelationPlot = 0 + PairPlot = 1 + ContingencyTable = 2 + + def __str__(self): + return self.name + + class BivariateAnalysis(ReportSection): """Generates the Bivariate analysis section of the report. @@ -69,17 +81,6 @@ class BivariateAnalysis(ReportSection): If exactly one of `columns_x`, `columns_y` is specified. """ - # pylint:disable=invalid-name - class BivariateAnalysisSubsection(IntEnum): - """Enum of all implemented bivariate analysis subsections.""" - - CorrelationPlot = 0 - PairPlot = 1 - ContingencyTable = 2 - - def __str__(self): - return self.name - # By default use all subsections _DEFAULT_SUBSECTIONS_TO_SHOW = list(BivariateAnalysisSubsection) @@ -100,13 +101,11 @@ def __init__( verbosity_pairplot = verbosity_pairplot or verbosity verbosity_contingency_table = verbosity_contingency_table or verbosity - subsec = BivariateAnalysis.BivariateAnalysisSubsection - # Store subsection verbosities self.subsection_verbosities = { - subsec.CorrelationPlot: verbosity_correlations, - subsec.PairPlot: verbosity_pairplot, - subsec.ContingencyTable: verbosity_contingency_table, + BivariateAnalysisSubsection.CorrelationPlot: verbosity_correlations, + BivariateAnalysisSubsection.PairPlot: verbosity_pairplot, + BivariateAnalysisSubsection.ContingencyTable: verbosity_contingency_table, } if subsections is None: @@ -130,17 +129,17 @@ def __init__( columns_x_no_pairs = columns_x columns_y_no_pairs = columns_y enum_to_implementation = { - subsec.CorrelationPlot: CorrelationPlot( + BivariateAnalysisSubsection.CorrelationPlot: CorrelationPlot( verbosity_correlations, columns, columns_x_no_pairs, columns_y_no_pairs ), - subsec.PairPlot: PairPlot( + BivariateAnalysisSubsection.PairPlot: PairPlot( verbosity_pairplot, columns, columns_x_no_pairs, columns_y_no_pairs, color_col=color_col, ), - subsec.ContingencyTable: ContingencyTable( + BivariateAnalysisSubsection.ContingencyTable: ContingencyTable( verbosity_contingency_table, columns, columns_x, columns_y, columns_pairs ), } @@ -177,7 +176,7 @@ def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: code = "show_bivariate_analysis(df=df" if self.subsections_to_show_with_low_verbosity != self._DEFAULT_SUBSECTIONS_TO_SHOW: arg_subsections_names = [ - f"BivariateAnalysis.BivariateAnalysisSubsection.{str(sub)}" + f"BivariateAnalysisSubsection.{str(sub)}" for sub in self.subsections_to_show_with_low_verbosity ] @@ -213,7 +212,9 @@ def required_imports(self) -> List[str]: 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") + imports.add( + "from edvart.report_sections.bivariate_analysis import BivariateAnalysisSubsection" + ) for subsec in self.subsections: if subsec.verbosity > Verbosity.LOW: imports.update(subsec.required_imports()) @@ -234,7 +235,7 @@ def show(self, df: pd.DataFrame) -> None: def show_bivariate_analysis( df: pd.DataFrame, - subsections: Optional[List[BivariateAnalysis.BivariateAnalysisSubsection]] = None, + subsections: Optional[List[BivariateAnalysisSubsection]] = None, columns: Optional[List[str]] = None, columns_x: Optional[List[str]] = None, columns_y: Optional[List[str]] = None, diff --git a/edvart/report_sections/dataset_overview.py b/edvart/report_sections/dataset_overview.py index 4da50c7..7a96214 100644 --- a/edvart/report_sections/dataset_overview.py +++ b/edvart/report_sections/dataset_overview.py @@ -21,6 +21,24 @@ from edvart.report_sections.section_base import ReportSection, Section, Verbosity +# pylint: disable=invalid-name +class OverviewSubsection(IntEnum): + """ + Enum of possible subsections of the Overview section. + """ + + QuickInfo = 1 + DataTypes = 2 + DataPreview = 3 + MissingValues = 4 + RowsWithMissingValue = 5 + ConstantOccurrence = 6 + DuplicateRows = 7 + + def __str__(self): + return self.name + + class Overview(ReportSection): """Generates the Overview section of the report. @@ -52,23 +70,6 @@ class Overview(ReportSection): Duplicate rows subsection code verbosity. """ - # pylint: disable=invalid-name - class OverviewSubsection(IntEnum): - """ - Enum of possible subsections of the Overview section. - """ - - QuickInfo = 1 - DataTypes = 2 - DataPreview = 3 - MissingValues = 4 - RowsWithMissingValue = 5 - ConstantOccurrence = 6 - DuplicateRows = 7 - - def __str__(self): - return self.name - # By default use all subsections _DEFAULT_SUBSECTIONS_TO_SHOW = list(OverviewSubsection) @@ -95,17 +96,15 @@ def __init__( verbosity_constant_occurrence = verbosity_constant_occurrence or verbosity verbosity_duplicate_rows = verbosity_duplicate_rows or verbosity - subsec = Overview.OverviewSubsection - # Store subsection verbosities self.subsection_verbosities = { - subsec.QuickInfo: verbosity_quick_info, - subsec.DataTypes: verbosity_data_types, - subsec.DataPreview: verbosity_data_preview, - subsec.MissingValues: verbosity_missing_values, - subsec.RowsWithMissingValue: verbosity_rows_with_missing_value, - subsec.ConstantOccurrence: verbosity_constant_occurrence, - subsec.DuplicateRows: verbosity_duplicate_rows, + OverviewSubsection.QuickInfo: verbosity_quick_info, + OverviewSubsection.DataTypes: verbosity_data_types, + OverviewSubsection.DataPreview: verbosity_data_preview, + OverviewSubsection.MissingValues: verbosity_missing_values, + OverviewSubsection.RowsWithMissingValue: verbosity_rows_with_missing_value, + OverviewSubsection.ConstantOccurrence: verbosity_constant_occurrence, + OverviewSubsection.DuplicateRows: verbosity_duplicate_rows, } if subsections is None: @@ -121,15 +120,17 @@ def __init__( # Construct objects that implement subsections enum_to_implementation = { - subsec.QuickInfo: QuickInfo(verbosity_quick_info, columns), - subsec.DataTypes: DataTypes(verbosity_data_types, columns), - subsec.DataPreview: DataPreview(verbosity_data_preview, columns), - subsec.MissingValues: MissingValues(verbosity_missing_values, columns), - subsec.RowsWithMissingValue: RowsWithMissingValue( + OverviewSubsection.QuickInfo: QuickInfo(verbosity_quick_info, columns), + OverviewSubsection.DataTypes: DataTypes(verbosity_data_types, columns), + OverviewSubsection.DataPreview: DataPreview(verbosity_data_preview, columns), + OverviewSubsection.MissingValues: MissingValues(verbosity_missing_values, columns), + OverviewSubsection.RowsWithMissingValue: RowsWithMissingValue( verbosity_rows_with_missing_value, columns ), - subsec.ConstantOccurrence: ConstantOccurrence(verbosity_constant_occurrence, columns), - subsec.DuplicateRows: DuplicateRows(verbosity_duplicate_rows, columns), + OverviewSubsection.ConstantOccurrence: ConstantOccurrence( + verbosity_constant_occurrence, columns + ), + OverviewSubsection.DuplicateRows: DuplicateRows(verbosity_duplicate_rows, columns), } subsections_implementations = [ @@ -153,7 +154,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") + imports.add( + "from edvart.report_sections.dataset_overview import OverviewSubsection" + ) for subsec in self.subsections: if subsec.verbosity > Verbosity.LOW: @@ -181,7 +184,7 @@ def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: code = "show_overview(df=df" if self.subsections_to_show_with_low_verbosity != self._DEFAULT_SUBSECTIONS_TO_SHOW: arg_subsections_names = [ - f"Overview.OverviewSubsection.{str(sub)}" + f"OverviewSubsection.{str(sub)}" for sub in self.subsections_to_show_with_low_verbosity ] code += f", subsections={arg_subsections_names}".replace("'", "") @@ -209,7 +212,7 @@ def show(self, df: pd.DataFrame) -> None: def show_overview( df: pd.DataFrame, - subsections: Optional[List[Overview.OverviewSubsection]] = None, + subsections: Optional[List[OverviewSubsection]] = None, columns: Optional[List[str]] = None, ) -> None: """Generates overview analysis for df. diff --git a/edvart/report_sections/multivariate_analysis.py b/edvart/report_sections/multivariate_analysis.py index 2cc3427..a8524db 100644 --- a/edvart/report_sections/multivariate_analysis.py +++ b/edvart/report_sections/multivariate_analysis.py @@ -26,6 +26,20 @@ UMAP_AVAILABLE = True +# pylint:disable=invalid-name +class MultivariateAnalysisSubsection(IntEnum): + """Enum of all implemented multivariate analysis subsections.""" + + PCA = 0 + if UMAP_AVAILABLE: + UMAP = 1 + ParallelCoordinates = 2 + ParallelCategories = 3 + + def __str__(self): + return self.name + + class MultivariateAnalysis(ReportSection): """Generates the Multivariate analysis section of the report. @@ -55,19 +69,6 @@ class MultivariateAnalysis(ReportSection): Both numerical and categorical columns are supported. """ - # pylint:disable=invalid-name - class MultivariateAnalysisSubsection(IntEnum): - """Enum of all implemented multivariate analysis subsections.""" - - PCA = 0 - if UMAP_AVAILABLE: - UMAP = 1 - ParallelCoordinates = 2 - ParallelCategories = 3 - - def __str__(self): - return self.name - # By default use all subsections _DEFAULT_SUBSECTIONS_TO_SHOW = list(MultivariateAnalysisSubsection) @@ -95,14 +96,13 @@ def __init__( else verbosity ) - subsec = MultivariateAnalysis.MultivariateAnalysisSubsection self.subsection_verbosities = { - subsec.PCA: verbosity_pca, - subsec.ParallelCoordinates: verbosity_parallel_coordinates, - subsec.ParallelCategories: verbosity_parallel_categories, + MultivariateAnalysisSubsection.PCA: verbosity_pca, + MultivariateAnalysisSubsection.ParallelCoordinates: verbosity_parallel_coordinates, + MultivariateAnalysisSubsection.ParallelCategories: verbosity_parallel_categories, } if UMAP_AVAILABLE: - self.subsection_verbosities[subsec.UMAP] = verbosity_umap + self.subsection_verbosities[MultivariateAnalysisSubsection.UMAP] = verbosity_umap if subsections is None: self.subsections_to_show = self._DEFAULT_SUBSECTIONS_TO_SHOW @@ -116,16 +116,18 @@ def __init__( ] enum_to_implementation = { - subsec.PCA: PCA(verbosity_pca, columns, color_col=color_col), - subsec.ParallelCoordinates: ParallelCoordinates( + MultivariateAnalysisSubsection.PCA: PCA(verbosity_pca, columns, color_col=color_col), + MultivariateAnalysisSubsection.ParallelCoordinates: ParallelCoordinates( verbosity_parallel_coordinates, columns, color_col=color_col ), - subsec.ParallelCategories: ParallelCategories( + MultivariateAnalysisSubsection.ParallelCategories: ParallelCategories( verbosity_parallel_categories, columns, color_col=color_col ), } if UMAP_AVAILABLE: - enum_to_implementation[subsec.UMAP] = UMAP(verbosity_umap, columns, color_col=color_col) + enum_to_implementation[MultivariateAnalysisSubsection.UMAP] = UMAP( + verbosity_umap, columns, color_col=color_col + ) subsections_implementations = [ enum_to_implementation[sub] for sub in self.subsections_to_show @@ -154,7 +156,8 @@ def required_imports(self) -> List[str]: } if self.subsections_to_show_with_low_verbosity != self._DEFAULT_SUBSECTIONS_TO_SHOW: imports.add( - "from edvart.report_sections.multivariate_analysis import MultivariateAnalysis" + "from edvart.report_sections.multivariate_analysis import" + " MultivariateAnalysisSubsection" ) for subsec in self.subsections: if subsec.verbosity > Verbosity.LOW: @@ -181,7 +184,7 @@ def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: code = "show_multivariate_analysis(df=df" if self.subsections_to_show_with_low_verbosity != self._DEFAULT_SUBSECTIONS_TO_SHOW: arg_subsections_names = [ - f"MultivariateAnalysis.MultivariateAnalysisSubsection.{str(sub)}" + f"MultivariateAnalysisSubsection.{str(sub)}" for sub in self.subsections_to_show_with_low_verbosity ] code += f", subsections={arg_subsections_names}".replace("'", "") @@ -211,7 +214,7 @@ def show(self, df: pd.DataFrame) -> None: def show_multivariate_analysis( df: pd.DataFrame, - subsections: Optional[List[MultivariateAnalysis.MultivariateAnalysisSubsection]] = None, + subsections: Optional[List[MultivariateAnalysisSubsection]] = None, columns: Optional[List[str]] = None, color_col: Optional[str] = None, ) -> None: diff --git a/edvart/report_sections/timeseries_analysis/__init__.py b/edvart/report_sections/timeseries_analysis/__init__.py index 0b4d612..7c90fcc 100644 --- a/edvart/report_sections/timeseries_analysis/__init__.py +++ b/edvart/report_sections/timeseries_analysis/__init__.py @@ -8,4 +8,7 @@ from .short_time_ft import ShortTimeFT from .stationarity_tests import StationarityTests from .time_series_line_plot import TimeSeriesLinePlot -from .timeseries_analysis import TimeseriesAnalysis # pylint: disable=cyclic-import +from .timeseries_analysis import ( # pylint: disable=cyclic-import + TimeseriesAnalysis, + TimeseriesAnalysisSubsection, +) diff --git a/edvart/report_sections/timeseries_analysis/timeseries_analysis.py b/edvart/report_sections/timeseries_analysis/timeseries_analysis.py index 2a32b14..e8c5fd0 100644 --- a/edvart/report_sections/timeseries_analysis/timeseries_analysis.py +++ b/edvart/report_sections/timeseries_analysis/timeseries_analysis.py @@ -21,6 +21,23 @@ ) +# pylint: disable=invalid-name +class TimeseriesAnalysisSubsection(IntEnum): + """Enum of all implemented timeseries analysis subsections.""" + + TimeSeriesLinePlot = 0 + RollingStatistics = 1 + BoxplotsOverTime = 2 + SeasonalDecomposition = 3 + StationarityTests = 4 + Autocorrelation = 5 + FourierTransform = 6 + ShortTimeFT = 7 + + def __str__(self): + return self.name + + class TimeseriesAnalysis(ReportSection): """Generates the Timeseries analysis section of the report. @@ -64,22 +81,6 @@ class TimeseriesAnalysis(ReportSection): is not set. """ - # pylint: disable=invalid-name - class TimeseriesAnalysisSubsection(IntEnum): - """Enum of all implemented timeseries analysis subsections.""" - - TimeSeriesLinePlot = 0 - RollingStatistics = 1 - BoxplotsOverTime = 2 - SeasonalDecomposition = 3 - StationarityTests = 4 - Autocorrelation = 5 - FourierTransform = 6 - ShortTimeFT = 7 - - def __str__(self): - return self.name - def __init__( self, subsections: Optional[List[TimeseriesAnalysisSubsection]] = None, @@ -112,46 +113,56 @@ def __init__( verbosity_fourier_transform = verbosity_fourier_transform or verbosity verbosity_short_time_ft = verbosity_short_time_ft or verbosity - subsec = TimeseriesAnalysis.TimeseriesAnalysisSubsection - self.subsection_verbosities = { - subsec.TimeSeriesLinePlot: verbosity_time_series_line_plot, - subsec.RollingStatistics: verbosity_rolling_statistics, - subsec.BoxplotsOverTime: verbosity_boxplots_over_time, - subsec.SeasonalDecomposition: verbosity_seasonal_decomposition, - subsec.StationarityTests: verbosity_stationarity_tests, - subsec.Autocorrelation: verbosity_autocorrelation, - subsec.FourierTransform: verbosity_fourier_transform, - subsec.ShortTimeFT: verbosity_short_time_ft, + TimeseriesAnalysisSubsection.TimeSeriesLinePlot: verbosity_time_series_line_plot, + TimeseriesAnalysisSubsection.RollingStatistics: verbosity_rolling_statistics, + TimeseriesAnalysisSubsection.BoxplotsOverTime: verbosity_boxplots_over_time, + TimeseriesAnalysisSubsection.SeasonalDecomposition: verbosity_seasonal_decomposition, + TimeseriesAnalysisSubsection.StationarityTests: verbosity_stationarity_tests, + TimeseriesAnalysisSubsection.Autocorrelation: verbosity_autocorrelation, + TimeseriesAnalysisSubsection.FourierTransform: verbosity_fourier_transform, + TimeseriesAnalysisSubsection.ShortTimeFT: verbosity_short_time_ft, } enum_to_implementation = { - subsec.TimeSeriesLinePlot: TimeSeriesLinePlot(verbosity_time_series_line_plot, columns), - subsec.RollingStatistics: RollingStatistics(verbosity_rolling_statistics, columns), - subsec.BoxplotsOverTime: BoxplotsOverTime(verbosity_boxplots_over_time, columns), - subsec.SeasonalDecomposition: SeasonalDecomposition( + TimeseriesAnalysisSubsection.TimeSeriesLinePlot: TimeSeriesLinePlot( + verbosity_time_series_line_plot, columns + ), + TimeseriesAnalysisSubsection.RollingStatistics: RollingStatistics( + verbosity_rolling_statistics, columns + ), + TimeseriesAnalysisSubsection.BoxplotsOverTime: BoxplotsOverTime( + verbosity_boxplots_over_time, columns + ), + TimeseriesAnalysisSubsection.SeasonalDecomposition: SeasonalDecomposition( verbosity_seasonal_decomposition, columns ), - subsec.StationarityTests: StationarityTests(verbosity_stationarity_tests, columns), - subsec.Autocorrelation: Autocorrelation(verbosity_autocorrelation, columns), + TimeseriesAnalysisSubsection.StationarityTests: StationarityTests( + verbosity_stationarity_tests, columns + ), + TimeseriesAnalysisSubsection.Autocorrelation: Autocorrelation( + verbosity_autocorrelation, columns + ), } # Add FT and STFT only if required parameters specified if sampling_rate is not None: - enum_to_implementation[subsec.FourierTransform] = FourierTransform( - sampling_rate, verbosity_fourier_transform, columns - ) + enum_to_implementation[ + TimeseriesAnalysisSubsection.FourierTransform + ] = FourierTransform(sampling_rate, verbosity_fourier_transform, columns) if stft_window_size is not None: - enum_to_implementation[subsec.ShortTimeFT] = ShortTimeFT( + enum_to_implementation[TimeseriesAnalysisSubsection.ShortTimeFT] = ShortTimeFT( sampling_rate, stft_window_size, verbosity_short_time_ft, columns ) - elif subsections is not None and subsec.ShortTimeFT in subsections: + elif ( + subsections is not None and TimeseriesAnalysisSubsection.ShortTimeFT in subsections + ): raise ValueError( "Need to set an `stft_window_size` to plot Short-time Fourier transform." ) elif subsections is not None: - if subsec.FourierTransform in subsections: + if TimeseriesAnalysisSubsection.FourierTransform in subsections: raise ValueError("Need to set a `sampling_rate` to plot Fourier transform.") - if subsec.ShortTimeFT in subsections: + if TimeseriesAnalysisSubsection.ShortTimeFT in subsections: raise ValueError( "Need to set a `sampling_rate` to plot Short-time Fourier transform." ) @@ -195,18 +206,21 @@ def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None: cells.append(section_header) if self.verbosity == Verbosity.LOW: - subsec = TimeseriesAnalysis.TimeseriesAnalysisSubsection code = "show_timeseries_analysis(df=df" if self.subsections_to_show_with_low_verbosity != self.default_subsections_to_show: arg_subsections_names = [ - f"TimeseriesAnalysis.TimeseriesAnalysisSubsection.{str(sub)}" + f"TimeseriesAnalysisSubsection.{str(sub)}" for sub in self.subsections_to_show_with_low_verbosity ] code += f", subsections={arg_subsections_names}".replace("'", "") - stft_included = subsec.ShortTimeFT in self.subsections_to_show_with_low_verbosity + stft_included = ( + TimeseriesAnalysisSubsection.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 self.subsections_to_show_with_low_verbosity + or TimeseriesAnalysisSubsection.FourierTransform + in self.subsections_to_show_with_low_verbosity ) if include_sampling_rate: code += f", sampling_rate={self.sampling_rate}" @@ -241,7 +255,7 @@ def required_imports(self) -> List[str]: 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" + " import TimeseriesAnalysisSubsection" ) for sub in self.subsections: if sub.verbosity > Verbosity.LOW: @@ -265,7 +279,7 @@ def show(self, df: pd.DataFrame) -> None: @check_index_time_ascending def show_timeseries_analysis( df: pd.DataFrame, - subsections: Optional[List[TimeseriesAnalysis.TimeseriesAnalysisSubsection]] = None, + subsections: Optional[List[TimeseriesAnalysisSubsection]] = None, columns: Optional[List[str]] = None, sampling_rate: Optional[int] = None, stft_window_size: Optional[int] = None, diff --git a/tests/test_bivariate_analysis.py b/tests/test_bivariate_analysis.py index bb71a5b..d1ad1eb 100644 --- a/tests/test_bivariate_analysis.py +++ b/tests/test_bivariate_analysis.py @@ -5,7 +5,7 @@ import pytest from edvart.report_sections import bivariate_analysis -from edvart.report_sections.bivariate_analysis import BivariateAnalysis +from edvart.report_sections.bivariate_analysis import BivariateAnalysis, BivariateAnalysisSubsection from edvart.report_sections.code_string_formatting import get_code from edvart.report_sections.section_base import Verbosity @@ -95,11 +95,11 @@ def test_negative_verbosities(): def test_section_adding(): bivariate_section = bivariate_analysis.BivariateAnalysis( subsections=[ - bivariate_analysis.BivariateAnalysis.BivariateAnalysisSubsection.PairPlot, - bivariate_analysis.BivariateAnalysis.BivariateAnalysisSubsection.CorrelationPlot, - bivariate_analysis.BivariateAnalysis.BivariateAnalysisSubsection.PairPlot, - bivariate_analysis.BivariateAnalysis.BivariateAnalysisSubsection.PairPlot, - bivariate_analysis.BivariateAnalysis.BivariateAnalysisSubsection.ContingencyTable, + BivariateAnalysisSubsection.PairPlot, + BivariateAnalysisSubsection.CorrelationPlot, + BivariateAnalysisSubsection.PairPlot, + BivariateAnalysisSubsection.PairPlot, + BivariateAnalysisSubsection.ContingencyTable, ] ) assert isinstance( @@ -136,8 +136,8 @@ def test_code_export_verbosity_low(): def test_code_export_verbosity_low_with_subsections(): bivariate_section = bivariate_analysis.BivariateAnalysis( subsections=[ - bivariate_analysis.BivariateAnalysis.BivariateAnalysisSubsection.ContingencyTable, - bivariate_analysis.BivariateAnalysis.BivariateAnalysisSubsection.PairPlot, + BivariateAnalysisSubsection.ContingencyTable, + BivariateAnalysisSubsection.PairPlot, ], verbosity=Verbosity.LOW, ) @@ -149,8 +149,8 @@ def test_code_export_verbosity_low_with_subsections(): # Define expected code expected_code = [ "show_bivariate_analysis(df=df, subsections=[" - "BivariateAnalysis.BivariateAnalysisSubsection.ContingencyTable, " - "BivariateAnalysis.BivariateAnalysisSubsection.PairPlot])" + "BivariateAnalysisSubsection.ContingencyTable, " + "BivariateAnalysisSubsection.PairPlot])" ] # Test code equivalence assert len(exported_code) == 1 @@ -189,9 +189,9 @@ def test_generated_code_verbosity_medium(): bivariate_section = bivariate_analysis.BivariateAnalysis( verbosity=Verbosity.MEDIUM, subsections=[ - bivariate_analysis.BivariateAnalysis.BivariateAnalysisSubsection.PairPlot, - bivariate_analysis.BivariateAnalysis.BivariateAnalysisSubsection.CorrelationPlot, - bivariate_analysis.BivariateAnalysis.BivariateAnalysisSubsection.ContingencyTable, + BivariateAnalysisSubsection.PairPlot, + BivariateAnalysisSubsection.CorrelationPlot, + BivariateAnalysisSubsection.ContingencyTable, ], ) @@ -218,9 +218,9 @@ def test_generated_code_verbosity_medium_columns_x_y(): columns_x=columns_x, columns_y=columns_y, subsections=[ - bivariate_analysis.BivariateAnalysis.BivariateAnalysisSubsection.PairPlot, - bivariate_analysis.BivariateAnalysis.BivariateAnalysisSubsection.CorrelationPlot, - bivariate_analysis.BivariateAnalysis.BivariateAnalysisSubsection.ContingencyTable, + BivariateAnalysisSubsection.PairPlot, + BivariateAnalysisSubsection.CorrelationPlot, + BivariateAnalysisSubsection.ContingencyTable, ], color_col="b", ) @@ -248,9 +248,9 @@ def test_generated_code_verbosity_medium_columns_pairs(): verbosity=Verbosity.MEDIUM, columns_pairs=columns_pairs, subsections=[ - bivariate_analysis.BivariateAnalysis.BivariateAnalysisSubsection.PairPlot, - bivariate_analysis.BivariateAnalysis.BivariateAnalysisSubsection.CorrelationPlot, - bivariate_analysis.BivariateAnalysis.BivariateAnalysisSubsection.ContingencyTable, + BivariateAnalysisSubsection.PairPlot, + BivariateAnalysisSubsection.CorrelationPlot, + BivariateAnalysisSubsection.ContingencyTable, ], ) @@ -273,9 +273,9 @@ def test_generated_code_verbosity_high(): bivariate_section = bivariate_analysis.BivariateAnalysis( verbosity=Verbosity.HIGH, subsections=[ - bivariate_analysis.BivariateAnalysis.BivariateAnalysisSubsection.PairPlot, - bivariate_analysis.BivariateAnalysis.BivariateAnalysisSubsection.CorrelationPlot, - bivariate_analysis.BivariateAnalysis.BivariateAnalysisSubsection.ContingencyTable, + BivariateAnalysisSubsection.PairPlot, + BivariateAnalysisSubsection.CorrelationPlot, + BivariateAnalysisSubsection.ContingencyTable, ], ) @@ -312,10 +312,10 @@ def test_verbosity_low_different_subsection_verbosities(): bivariate_section = BivariateAnalysis( verbosity=Verbosity.LOW, subsections=[ - BivariateAnalysis.BivariateAnalysisSubsection.PairPlot, - BivariateAnalysis.BivariateAnalysisSubsection.ContingencyTable, - BivariateAnalysis.BivariateAnalysisSubsection.PairPlot, - BivariateAnalysis.BivariateAnalysisSubsection.CorrelationPlot, + BivariateAnalysisSubsection.PairPlot, + BivariateAnalysisSubsection.ContingencyTable, + BivariateAnalysisSubsection.PairPlot, + BivariateAnalysisSubsection.CorrelationPlot, ], verbosity_pairplot=Verbosity.HIGH, verbosity_correlations=Verbosity.MEDIUM, @@ -327,7 +327,7 @@ def test_verbosity_low_different_subsection_verbosities(): expected_code = [ "show_bivariate_analysis(df=df, " - "subsections=[BivariateAnalysis.BivariateAnalysisSubsection.ContingencyTable])", + "subsections=[BivariateAnalysisSubsection.ContingencyTable])", get_code(bivariate_analysis.plot_pairplot) + "\n\n" + "plot_pairplot(df=df)", get_code(bivariate_analysis.plot_pairplot) + "\n\n" + "plot_pairplot(df=df)", "plot_correlations(df=df)", @@ -384,10 +384,10 @@ def test_imports_verbosity_low_different_subsection_verbosities(): bivariate_section = BivariateAnalysis( verbosity=Verbosity.LOW, subsections=[ - BivariateAnalysis.BivariateAnalysisSubsection.PairPlot, - BivariateAnalysis.BivariateAnalysisSubsection.ContingencyTable, - BivariateAnalysis.BivariateAnalysisSubsection.PairPlot, - BivariateAnalysis.BivariateAnalysisSubsection.CorrelationPlot, + BivariateAnalysisSubsection.PairPlot, + BivariateAnalysisSubsection.ContingencyTable, + BivariateAnalysisSubsection.PairPlot, + BivariateAnalysisSubsection.CorrelationPlot, ], verbosity_pairplot=Verbosity.HIGH, verbosity_correlations=Verbosity.MEDIUM, @@ -397,7 +397,7 @@ def test_imports_verbosity_low_different_subsection_verbosities(): expected_imports = { "from edvart.report_sections.bivariate_analysis import show_bivariate_analysis", - "from edvart.report_sections.bivariate_analysis import BivariateAnalysis", + "from edvart.report_sections.bivariate_analysis import BivariateAnalysisSubsection", } for s in bivariate_section.subsections: if s.verbosity > Verbosity.LOW: diff --git a/tests/test_multivariate_analysis.py b/tests/test_multivariate_analysis.py index 20ba3f2..db05ca2 100644 --- a/tests/test_multivariate_analysis.py +++ b/tests/test_multivariate_analysis.py @@ -11,7 +11,11 @@ from edvart import utils from edvart.report_sections import multivariate_analysis, umap from edvart.report_sections.code_string_formatting import code_dedent, get_code -from edvart.report_sections.multivariate_analysis import UMAP_AVAILABLE, MultivariateAnalysis +from edvart.report_sections.multivariate_analysis import ( + UMAP_AVAILABLE, + MultivariateAnalysis, + MultivariateAnalysisSubsection, +) from edvart.report_sections.section_base import Verbosity from edvart.utils import select_numeric_columns @@ -95,13 +99,13 @@ def test_negative_verbosities(): def test_section_adding(): subsections = [ - MultivariateAnalysis.MultivariateAnalysisSubsection.PCA, - MultivariateAnalysis.MultivariateAnalysisSubsection.PCA, - MultivariateAnalysis.MultivariateAnalysisSubsection.ParallelCoordinates, - MultivariateAnalysis.MultivariateAnalysisSubsection.ParallelCategories, + MultivariateAnalysisSubsection.PCA, + MultivariateAnalysisSubsection.PCA, + MultivariateAnalysisSubsection.ParallelCoordinates, + MultivariateAnalysisSubsection.ParallelCategories, ] if UMAP_AVAILABLE: - subsections.append(MultivariateAnalysis.MultivariateAnalysisSubsection.UMAP) + subsections.append(MultivariateAnalysisSubsection.UMAP) multivariate_section = MultivariateAnalysis(subsections=subsections) if UMAP_AVAILABLE: assert len(multivariate_section.subsections) == 5 @@ -127,7 +131,7 @@ def test_section_adding(): def test_code_export_verbosity_low(): df = get_test_df() - multivariate_section = multivariate_analysis.MultivariateAnalysis(verbosity=Verbosity.LOW) + multivariate_section = MultivariateAnalysis(verbosity=Verbosity.LOW) # Export code exported_cells = [] multivariate_section.add_cells(exported_cells, df=df) @@ -141,7 +145,7 @@ def test_code_export_verbosity_low(): def test_code_export_verbosity_low_with_subsections(): - subsec = multivariate_analysis.MultivariateAnalysis.MultivariateAnalysisSubsection + subsec = MultivariateAnalysisSubsection subsections = [subsec.ParallelCategories, subsec.PCA, subsec.ParallelCoordinates, subsec.PCA] if UMAP_AVAILABLE: subsections.append(subsec.UMAP) @@ -159,19 +163,19 @@ def test_code_export_verbosity_low_with_subsections(): # Define expected code expected_code = [ "show_multivariate_analysis(df=df, subsections=[" - "MultivariateAnalysis.MultivariateAnalysisSubsection.ParallelCategories, " - "MultivariateAnalysis.MultivariateAnalysisSubsection.PCA, " - "MultivariateAnalysis.MultivariateAnalysisSubsection.ParallelCoordinates, " - "MultivariateAnalysis.MultivariateAnalysisSubsection.PCA, " - "MultivariateAnalysis.MultivariateAnalysisSubsection.UMAP])" + "MultivariateAnalysisSubsection.ParallelCategories, " + "MultivariateAnalysisSubsection.PCA, " + "MultivariateAnalysisSubsection.ParallelCoordinates, " + "MultivariateAnalysisSubsection.PCA, " + "MultivariateAnalysisSubsection.UMAP])" ] else: expected_code = [ "show_multivariate_analysis(df=df, subsections=[" - "MultivariateAnalysis.MultivariateAnalysisSubsection.ParallelCategories, " - "MultivariateAnalysis.MultivariateAnalysisSubsection.PCA, " - "MultivariateAnalysis.MultivariateAnalysisSubsection.ParallelCoordinates, " - "MultivariateAnalysis.MultivariateAnalysisSubsection.PCA])" + "MultivariateAnalysisSubsection.ParallelCategories, " + "MultivariateAnalysisSubsection.PCA, " + "MultivariateAnalysisSubsection.ParallelCoordinates, " + "MultivariateAnalysisSubsection.PCA])" ] # Test code equivalence assert len(exported_code) == 1 @@ -183,9 +187,11 @@ def test_code_export_verbosity_medium_all_cols_valid(): data=[[1.1, 1, -2], [2.2, 2, -5.3], [3.3, 3, 4]], columns=["col1", "col2", "col3"] ) - subsec = multivariate_analysis.MultivariateAnalysis.MultivariateAnalysisSubsection - multivariate_section = multivariate_analysis.MultivariateAnalysis( - subsections=[subsec.PCA, subsec.ParallelCategories], + multivariate_section = MultivariateAnalysis( + subsections=[ + MultivariateAnalysisSubsection.PCA, + MultivariateAnalysisSubsection.ParallelCategories, + ], verbosity=Verbosity.MEDIUM, ) @@ -205,7 +211,7 @@ def test_code_export_verbosity_medium_all_cols_valid(): def test_generated_code_verbosity_1(): - multivariate_section = multivariate_analysis.MultivariateAnalysis(verbosity=Verbosity.MEDIUM) + multivariate_section = MultivariateAnalysis(verbosity=Verbosity.MEDIUM) df = get_test_df() exported_cells = [] @@ -242,7 +248,7 @@ def test_generated_code_verbosity_1(): def test_generated_code_verbosity_2(): df = get_test_df() - multivariate_section = multivariate_analysis.MultivariateAnalysis(verbosity=Verbosity.HIGH) + multivariate_section = MultivariateAnalysis(verbosity=Verbosity.HIGH) multivariate_cells = [] multivariate_section.add_cells(multivariate_cells, df=df) @@ -305,7 +311,7 @@ def test_verbosity_medium_non_categorical_col(): random_array = np.random.randint(low=1, high=40, size=(100, 3)) random_df = pd.DataFrame(data=random_array, columns=["integral", "floating", "cat"]) random_df = random_df.astype({"integral": int, "floating": float, "cat": "category"}) - subsec = multivariate_analysis.MultivariateAnalysis.MultivariateAnalysisSubsection + subsec = MultivariateAnalysisSubsection multivariate_section = multivariate_analysis.MultivariateAnalysis( subsections=[subsec.ParallelCategories], verbosity=Verbosity.MEDIUM ) @@ -323,13 +329,13 @@ def test_verbosity_medium_non_categorical_col(): def test_verbosity_low_different_subsection_verbosities(): subsections = [ - MultivariateAnalysis.MultivariateAnalysisSubsection.PCA, - MultivariateAnalysis.MultivariateAnalysisSubsection.PCA, - MultivariateAnalysis.MultivariateAnalysisSubsection.ParallelCategories, - MultivariateAnalysis.MultivariateAnalysisSubsection.ParallelCoordinates, + MultivariateAnalysisSubsection.PCA, + MultivariateAnalysisSubsection.PCA, + MultivariateAnalysisSubsection.ParallelCategories, + MultivariateAnalysisSubsection.ParallelCoordinates, ] if UMAP_AVAILABLE: - subsections.insert(2, MultivariateAnalysis.MultivariateAnalysisSubsection.UMAP) + subsections.insert(2, MultivariateAnalysisSubsection.UMAP) df = get_test_df() multivariate_section = MultivariateAnalysis( verbosity=Verbosity.LOW, @@ -342,11 +348,11 @@ def test_verbosity_low_different_subsection_verbosities(): 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", - "MultivariateAnalysis.MultivariateAnalysisSubsection.PCA", + "MultivariateAnalysisSubsection.PCA", + "MultivariateAnalysisSubsection.PCA", ] if UMAP_AVAILABLE: - expected_subsections.append("MultivariateAnalysis.MultivariateAnalysisSubsection.UMAP") + expected_subsections.append("MultivariateAnalysisSubsection.UMAP") expected_subsections_str = ", ".join(expected_subsections) expected_code = [ "show_multivariate_analysis(df=df, " f"subsections=[{expected_subsections_str}])", @@ -409,13 +415,13 @@ def test_imports_verbosity_high(): def test_imports_verbosity_low_different_subsection_verbosities(): subsections = [ - MultivariateAnalysis.MultivariateAnalysisSubsection.PCA, - MultivariateAnalysis.MultivariateAnalysisSubsection.PCA, - MultivariateAnalysis.MultivariateAnalysisSubsection.ParallelCategories, - MultivariateAnalysis.MultivariateAnalysisSubsection.ParallelCoordinates, + MultivariateAnalysisSubsection.PCA, + MultivariateAnalysisSubsection.PCA, + MultivariateAnalysisSubsection.ParallelCategories, + MultivariateAnalysisSubsection.ParallelCoordinates, ] if UMAP_AVAILABLE: - subsections.insert(3, MultivariateAnalysis.MultivariateAnalysisSubsection.UMAP) + subsections.insert(3, MultivariateAnalysisSubsection.UMAP) multivariate_section = MultivariateAnalysis( verbosity=Verbosity.LOW, subsections=subsections, @@ -427,7 +433,7 @@ def test_imports_verbosity_low_different_subsection_verbosities(): expected_imports = { "from edvart.report_sections.multivariate_analysis import show_multivariate_analysis", - "from edvart.report_sections.multivariate_analysis import MultivariateAnalysis", + "from edvart.report_sections.multivariate_analysis import MultivariateAnalysisSubsection", } for s in multivariate_section.subsections: if s.verbosity > Verbosity.LOW: diff --git a/tests/test_overview_section.py b/tests/test_overview_section.py index 1f92563..7fb3b44 100644 --- a/tests/test_overview_section.py +++ b/tests/test_overview_section.py @@ -17,7 +17,7 @@ from edvart.pandas_formatting import render_dictionary, series_to_frame from edvart.report_sections import dataset_overview from edvart.report_sections.code_string_formatting import get_code -from edvart.report_sections.dataset_overview import Overview +from edvart.report_sections.dataset_overview import Overview, OverviewSubsection from edvart.report_sections.section_base import Verbosity @@ -100,11 +100,11 @@ def test_high_verbosities(): def test_section_adding(): overview_section = Overview( subsections=[ - Overview.OverviewSubsection.QuickInfo, - Overview.OverviewSubsection.QuickInfo, - Overview.OverviewSubsection.MissingValues, - Overview.OverviewSubsection.DuplicateRows, - Overview.OverviewSubsection.DuplicateRows, + OverviewSubsection.QuickInfo, + OverviewSubsection.QuickInfo, + OverviewSubsection.MissingValues, + OverviewSubsection.DuplicateRows, + OverviewSubsection.DuplicateRows, ] ) assert isinstance( @@ -140,8 +140,8 @@ def test_code_export_verbosity_low(): def test_code_export_verbosity_low_with_subsections(): overview_section = Overview( subsections=[ - Overview.OverviewSubsection.QuickInfo, - Overview.OverviewSubsection.MissingValues, + OverviewSubsection.QuickInfo, + OverviewSubsection.MissingValues, ], verbosity=Verbosity.LOW, ) @@ -152,8 +152,8 @@ def test_code_export_verbosity_low_with_subsections(): exported_code = [cell["source"] for cell in exported_cells if cell["cell_type"] == "code"] # Define expected code expected_code = [ - "show_overview(df=df, subsections=[Overview.OverviewSubsection.QuickInfo, " - "Overview.OverviewSubsection.MissingValues])" + "show_overview(df=df, subsections=[OverviewSubsection.QuickInfo, " + "OverviewSubsection.MissingValues])" ] # Test code equivalence assert exported_code[0] == expected_code[0], "Exported code mismatch" @@ -163,13 +163,13 @@ def test_code_export_verbosity_medium(): # Construct overview section overview_section = Overview( subsections=[ - Overview.OverviewSubsection.QuickInfo, - Overview.OverviewSubsection.DataTypes, - Overview.OverviewSubsection.DataPreview, - Overview.OverviewSubsection.MissingValues, - Overview.OverviewSubsection.RowsWithMissingValue, - Overview.OverviewSubsection.ConstantOccurrence, - Overview.OverviewSubsection.DuplicateRows, + OverviewSubsection.QuickInfo, + OverviewSubsection.DataTypes, + OverviewSubsection.DataPreview, + OverviewSubsection.MissingValues, + OverviewSubsection.RowsWithMissingValue, + OverviewSubsection.ConstantOccurrence, + OverviewSubsection.DuplicateRows, ], verbosity=Verbosity.MEDIUM, ) @@ -197,13 +197,13 @@ def test_code_export_verbosity_high(): # Construct overview section overview_section = Overview( subsections=[ - Overview.OverviewSubsection.QuickInfo, - Overview.OverviewSubsection.DataTypes, - Overview.OverviewSubsection.DataPreview, - Overview.OverviewSubsection.MissingValues, - Overview.OverviewSubsection.RowsWithMissingValue, - Overview.OverviewSubsection.ConstantOccurrence, - Overview.OverviewSubsection.DuplicateRows, + OverviewSubsection.QuickInfo, + OverviewSubsection.DataTypes, + OverviewSubsection.DataPreview, + OverviewSubsection.MissingValues, + OverviewSubsection.RowsWithMissingValue, + OverviewSubsection.ConstantOccurrence, + OverviewSubsection.DuplicateRows, ], verbosity=Verbosity.HIGH, ) @@ -284,11 +284,11 @@ def test_verbosity_low_different_subsection_verbosities(): expected_code = [ "show_overview(df=df, " - "subsections=[Overview.OverviewSubsection.DataTypes, " - "Overview.OverviewSubsection.DataPreview, " - "Overview.OverviewSubsection.MissingValues, " - "Overview.OverviewSubsection.RowsWithMissingValue, " - "Overview.OverviewSubsection.ConstantOccurrence])", + "subsections=[OverviewSubsection.DataTypes, " + "OverviewSubsection.DataPreview, " + "OverviewSubsection.MissingValues, " + "OverviewSubsection.RowsWithMissingValue, " + "OverviewSubsection.ConstantOccurrence])", "quick_info(df=df)", ( get_code(render_dictionary) @@ -355,7 +355,7 @@ def test_imports_verbosity_low_different_subsection_verbosities(): expected_imports = { "from edvart.report_sections.dataset_overview import show_overview", - "from edvart.report_sections.dataset_overview import Overview", + "from edvart.report_sections.dataset_overview import OverviewSubsection", } for s in overview_section.subsections: if s.verbosity > Verbosity.LOW: diff --git a/tests/test_timeseries_analysis.py b/tests/test_timeseries_analysis.py index 3834309..c01dc40 100644 --- a/tests/test_timeseries_analysis.py +++ b/tests/test_timeseries_analysis.py @@ -9,7 +9,11 @@ from edvart.report_sections import timeseries_analysis from edvart.report_sections.code_string_formatting import get_code from edvart.report_sections.section_base import Verbosity -from edvart.report_sections.timeseries_analysis import BoxplotsOverTime, TimeseriesAnalysis +from edvart.report_sections.timeseries_analysis import ( + BoxplotsOverTime, + TimeseriesAnalysis, + TimeseriesAnalysisSubsection, +) def test_default_config_verbosity(): @@ -89,11 +93,11 @@ def test_negative_verbosities(): def test_section_adding(): bivariate_section = TimeseriesAnalysis( subsections=[ - TimeseriesAnalysis.TimeseriesAnalysisSubsection.RollingStatistics, - TimeseriesAnalysis.TimeseriesAnalysisSubsection.BoxplotsOverTime, - TimeseriesAnalysis.TimeseriesAnalysisSubsection.StationarityTests, - TimeseriesAnalysis.TimeseriesAnalysisSubsection.RollingStatistics, - TimeseriesAnalysis.TimeseriesAnalysisSubsection.SeasonalDecomposition, + TimeseriesAnalysisSubsection.RollingStatistics, + TimeseriesAnalysisSubsection.BoxplotsOverTime, + TimeseriesAnalysisSubsection.StationarityTests, + TimeseriesAnalysisSubsection.RollingStatistics, + TimeseriesAnalysisSubsection.SeasonalDecomposition, ] ) assert isinstance( @@ -148,21 +152,19 @@ def test_ft_stft_included(): def test_ft_no_sampling_rate_error(): with pytest.raises(ValueError): - ts = TimeseriesAnalysis( - subsections=[TimeseriesAnalysis.TimeseriesAnalysisSubsection.FourierTransform] - ) + ts = TimeseriesAnalysis(subsections=[TimeseriesAnalysisSubsection.FourierTransform]) with pytest.raises(ValueError): ts = TimeseriesAnalysis( - subsections=[TimeseriesAnalysis.TimeseriesAnalysisSubsection.FourierTransform], + subsections=[TimeseriesAnalysisSubsection.FourierTransform], stft_window_size=2, ) with pytest.raises(ValueError): ts = TimeseriesAnalysis( - subsections=[TimeseriesAnalysis.TimeseriesAnalysisSubsection.ShortTimeFT], + subsections=[TimeseriesAnalysisSubsection.ShortTimeFT], ) with pytest.raises(ValueError): ts = TimeseriesAnalysis( - subsections=[TimeseriesAnalysis.TimeseriesAnalysisSubsection.ShortTimeFT], + subsections=[TimeseriesAnalysisSubsection.ShortTimeFT], sampling_rate=1, ) @@ -184,8 +186,8 @@ def test_code_export_verbosity_low(): def test_code_export_verbosity_low_with_subsections(): ts_section = TimeseriesAnalysis( subsections=[ - TimeseriesAnalysis.TimeseriesAnalysisSubsection.RollingStatistics, - TimeseriesAnalysis.TimeseriesAnalysisSubsection.StationarityTests, + TimeseriesAnalysisSubsection.RollingStatistics, + TimeseriesAnalysisSubsection.StationarityTests, ], verbosity=Verbosity.LOW, ) @@ -197,8 +199,8 @@ def test_code_export_verbosity_low_with_subsections(): # Define expected code expected_code = [ "show_timeseries_analysis(df=df, subsections=[" - "TimeseriesAnalysis.TimeseriesAnalysisSubsection.RollingStatistics, " - "TimeseriesAnalysis.TimeseriesAnalysisSubsection.StationarityTests])" + "TimeseriesAnalysisSubsection.RollingStatistics, " + "TimeseriesAnalysisSubsection.StationarityTests])" ] # Test code equivalence assert len(exported_code) == 1 @@ -208,8 +210,8 @@ def test_code_export_verbosity_low_with_subsections(): def test_code_export_verbosity_low_with_fft_stft(): ts_section = TimeseriesAnalysis( subsections=[ - TimeseriesAnalysis.TimeseriesAnalysisSubsection.FourierTransform, - TimeseriesAnalysis.TimeseriesAnalysisSubsection.ShortTimeFT, + TimeseriesAnalysisSubsection.FourierTransform, + TimeseriesAnalysisSubsection.ShortTimeFT, ], verbosity=Verbosity.LOW, sampling_rate=1, @@ -223,8 +225,8 @@ def test_code_export_verbosity_low_with_fft_stft(): # Define expected code expected_code = [ "show_timeseries_analysis(df=df, subsections=[" - "TimeseriesAnalysis.TimeseriesAnalysisSubsection.FourierTransform, " - "TimeseriesAnalysis.TimeseriesAnalysisSubsection.ShortTimeFT], " + "TimeseriesAnalysisSubsection.FourierTransform, " + "TimeseriesAnalysisSubsection.ShortTimeFT], " "sampling_rate=1, stft_window_size=1)" ] # Test code equivalence @@ -326,12 +328,12 @@ def test_verbosity_low_different_subsection_verbosities(): ts_section = TimeseriesAnalysis( verbosity=Verbosity.LOW, subsections=[ - TimeseriesAnalysis.TimeseriesAnalysisSubsection.TimeSeriesLinePlot, - TimeseriesAnalysis.TimeseriesAnalysisSubsection.FourierTransform, - TimeseriesAnalysis.TimeseriesAnalysisSubsection.RollingStatistics, - TimeseriesAnalysis.TimeseriesAnalysisSubsection.StationarityTests, - TimeseriesAnalysis.TimeseriesAnalysisSubsection.BoxplotsOverTime, - TimeseriesAnalysis.TimeseriesAnalysisSubsection.ShortTimeFT, + TimeseriesAnalysisSubsection.TimeSeriesLinePlot, + TimeseriesAnalysisSubsection.FourierTransform, + TimeseriesAnalysisSubsection.RollingStatistics, + TimeseriesAnalysisSubsection.StationarityTests, + TimeseriesAnalysisSubsection.BoxplotsOverTime, + TimeseriesAnalysisSubsection.ShortTimeFT, ], sampling_rate=1, stft_window_size=2, @@ -346,9 +348,9 @@ def test_verbosity_low_different_subsection_verbosities(): expected_code = [ "show_timeseries_analysis(df=df, " - "subsections=[TimeseriesAnalysis.TimeseriesAnalysisSubsection.TimeSeriesLinePlot, " - "TimeseriesAnalysis.TimeseriesAnalysisSubsection.StationarityTests, " - "TimeseriesAnalysis.TimeseriesAnalysisSubsection.BoxplotsOverTime])", + "subsections=[TimeseriesAnalysisSubsection.TimeSeriesLinePlot, " + "TimeseriesAnalysisSubsection.StationarityTests, " + "TimeseriesAnalysisSubsection.BoxplotsOverTime])", "show_fourier_transform(df=df, sampling_rate=1)", "show_rolling_statistics(df=df)", ( @@ -447,12 +449,12 @@ def test_imports_verbosity_low_different_subsection_verbosities(): ts_section = TimeseriesAnalysis( verbosity=Verbosity.LOW, subsections=[ - TimeseriesAnalysis.TimeseriesAnalysisSubsection.TimeSeriesLinePlot, - TimeseriesAnalysis.TimeseriesAnalysisSubsection.FourierTransform, - TimeseriesAnalysis.TimeseriesAnalysisSubsection.RollingStatistics, - TimeseriesAnalysis.TimeseriesAnalysisSubsection.StationarityTests, - TimeseriesAnalysis.TimeseriesAnalysisSubsection.BoxplotsOverTime, - TimeseriesAnalysis.TimeseriesAnalysisSubsection.ShortTimeFT, + TimeseriesAnalysisSubsection.TimeSeriesLinePlot, + TimeseriesAnalysisSubsection.FourierTransform, + TimeseriesAnalysisSubsection.RollingStatistics, + TimeseriesAnalysisSubsection.StationarityTests, + TimeseriesAnalysisSubsection.BoxplotsOverTime, + TimeseriesAnalysisSubsection.ShortTimeFT, ], sampling_rate=1, stft_window_size=2, @@ -464,7 +466,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", + "from edvart.report_sections.timeseries_analysis.timeseries_analysis import TimeseriesAnalysisSubsection", } for s in ts_section.subsections: if s.verbosity > Verbosity.LOW: