-
Notifications
You must be signed in to change notification settings - Fork 154
Make use of ABC abstract class in unsequa module #1054
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
Changes from all commits
0a47b9c
42c0e6f
e200f3e
623dc85
8121416
7e650c3
d67ed7b
5b42eba
80ebe63
f8b734f
a15fba9
cd2c8d4
0009703
e29e703
6906784
68f01c7
1f523e1
7f78263
5a538ea
da3f690
08671e4
d5c129c
1b47887
7c616ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ | |
|
|
||
| import datetime as dt | ||
| import logging | ||
| from abc import ABC, abstractmethod | ||
| from itertools import zip_longest | ||
| from pathlib import Path | ||
|
|
||
|
|
@@ -71,7 +72,7 @@ | |
| } | ||
|
|
||
|
|
||
| class UncOutput: | ||
| class UncOutput(ABC): | ||
|
Check warning on line 75 in climada/engine/unsequa/unc_output.py
|
||
| """ | ||
| Class to store and plot uncertainty and sensitivity analysis output data | ||
|
|
||
|
|
@@ -107,16 +108,20 @@ | |
| "sensitivity_kwargs", | ||
| ] | ||
|
|
||
| # @abstractmethod | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. making
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. You usually call inits of base classes from derived classes instead of overriding them. |
||
| def __init__(self, samples_df, unit=None): | ||
| # """ | ||
| # Empty constructor to be overwritten by subclasses | ||
| # """ | ||
| """ | ||
| Initialize Uncertainty Data object. | ||
| Initialize Uncertainty Data object | ||
|
|
||
| Parameters | ||
| ---------- | ||
| samples_df : pandas.DataFrame | ||
| input parameters samples | ||
| input parameters samples | ||
| unit : str, optional | ||
| value unit | ||
| value unit | ||
| """ | ||
| # Data | ||
| self.samples_df = samples_df | ||
|
|
@@ -1232,6 +1237,58 @@ | |
| return unc_data | ||
|
|
||
|
|
||
| # class UncBaseOutput(UncOutput): | ||
| # """ | ||
| # Class to store and plot uncertainty and sensitivity analysis output data | ||
| # | ||
| # This is the base class to store uncertainty and sensitivity outputs of an | ||
| # analysis done on climada.engine.impact.Impact() or | ||
| # climada.engine.costbenefit.CostBenefit() object. | ||
| # | ||
| # Attributes | ||
| # ---------- | ||
| # samples_df : pandas.DataFrame | ||
| # Values of the sampled uncertainty parameters. It has n_samples rows | ||
| # and one column per uncertainty parameter. | ||
| # sampling_method : str | ||
| # Name of the sampling method from SAlib. | ||
| # https://salib.readthedocs.io/en/latest/api.html# | ||
| # n_samples : int | ||
| # Effective number of samples (number of rows of samples_df) | ||
| # param_labels : list | ||
| # Name of all the uncertainty parameters | ||
| # distr_dict : dict | ||
| # Comon flattened dictionary of all the distr_dict of all input variables. | ||
| # It represents the distribution of all the uncertainty parameters. | ||
| # problem_sa : dict | ||
| # The description of the uncertainty variables and their | ||
| # distribution as used in SALib. | ||
| # https://salib.readthedocs.io/en/latest/basics.html. | ||
| # """ | ||
| # | ||
| # _metadata = [ | ||
| # "sampling_method", | ||
| # "sampling_kwargs", | ||
| # "sensitivity_method", | ||
| # "sensitivity_kwargs", | ||
| # ] | ||
| # | ||
| # def __init__(self, samples_df, unit=None): | ||
| # """ | ||
| # Initialize Uncertainty Data object. | ||
| # | ||
| # Parameters | ||
| # ---------- | ||
| # samples_df : pandas.DataFrame | ||
| # input parameters samples | ||
| # unit : str, optional | ||
| # value unit | ||
| # """ | ||
| # # Data | ||
| # self.samples_df = samples_df | ||
| # self.unit = unit | ||
|
|
||
|
|
||
| class UncImpactOutput(UncOutput): | ||
| """Extension of UncOutput specific for CalcImpact, returned by the | ||
| uncertainty() method. | ||
|
|
||
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private and abstract seems somehow contradicting. if we go for it,
compute_metricsought to be public.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree. An abstract method just means that "this implementation is to be defined in a derived class". Depending on the semantics of the class, the method in question may very well be private.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@peanutfun Technically speaking, you're absolutely right. In this particular case I still think
compute_metricsought to be public.