IBM/causallib

View on GitHub

Showing 110 of 110 total issues

Function __init__ has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
Open

def __init__(self, topology, var_types, prob_categories, link_types, snr, treatment_importances,
treatment_methods="gaussian", outcome_types=CATEGORICAL, effect_sizes=None,
survival_distribution="expon", survival_baseline=1, params=None):
"""
Constructor
Severity: Minor
Found in causallib/simulation/CausalSimulator3.py - About 4 hrs to fix

Function generate_outcome_col has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
Open

def generate_outcome_col(self, X_parents, link_type, snr, prob_category, outcome_type, treatment_importance=None,
effect_size=None, survival_distribution=None, survival_baseline=None, var_name=None):
"""
Generates a single outcome variable column.
 
 
Severity: Minor
Found in causallib/simulation/CausalSimulator3.py - About 4 hrs to fix

Function _run has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
Open

def _run(self, X, A, w_init=None, is_train=True, use_stabilized=None, **select_kwargs):
if use_stabilized is None:
use_stabilized = self.use_stabilized
 
if w_init is None:
Severity: Minor
Found in causallib/contrib/adversarial_balancing/adversarial_balancing.py - About 4 hrs to fix

Function generate_data has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

def generate_data(self, X_given=None, num_samples=None, random_seed=None):
"""
Generates tables of dataset given the object's initial parameters.
 
Args:
Severity: Minor
Found in causallib/simulation/CausalSimulator3.py - About 4 hrs to fix

Function fit has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
Open

def fit(self, train, epochs=100, batch_size=10, lr=1e-3, wd=0, ltype='log', dev=None, metric='AP', response='bin',
use_p_correction=True, imb_fun='mmd2_lin', p_alpha=1e-4):
"""This method uses ELBO to perform parameter updates using a first order optimizer routing.
 
Args:
Severity: Minor
Found in causallib/contrib/hemm/hemm.py - About 4 hrs to fix

Function _select_classifier_from_list has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

def _select_classifier_from_list(candidates, X, A, n_splits=5, seed=None, loss_type='01'):
accuracies = np.zeros(len(candidates))
 
class_weight = compute_class_weight(class_weight='balanced', classes=np.unique(A), y=A)[LabelEncoder().fit_transform(A)]
 
 
Severity: Minor
Found in causallib/contrib/adversarial_balancing/classifier_selection.py - About 3 hrs to fix

CausalSimulator3 has 28 functions (exceeds 20 allowed). Consider refactoring.
Open

class CausalSimulator3(object):
TREATMENT_METHODS = {"random": lambda x, p, snr, params: CausalSimulator3._treatment_random(x, p),
"odds_ratio": lambda x, p, snr, params: CausalSimulator3._treatment_odds_ratio(x, p, snr),
"quantile_gauss_fit": lambda x, p, snr, params: CausalSimulator3._treatment_quantile_gauss_fit(
x, p, snr),
Severity: Minor
Found in causallib/simulation/CausalSimulator3.py - About 3 hrs to fix

    Function _discretize_col has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

    def _discretize_col(x_col, prob_category, method="empiric", retbins=False, bins=None):
    """
    If needed, turns the continuous covariate column into a discrete one (having discrete values as specified by the
    length of prob_category).
     
     
    Severity: Minor
    Found in causallib/simulation/CausalSimulator3.py - About 3 hrs to fix

    Function plot_propensity_score_distribution has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

    def plot_propensity_score_distribution(
    propensity,
    treatment,
    reflect=True,
    kde=False,
    Severity: Minor
    Found in causallib/evaluation/plots/plots.py - About 2 hrs to fix

    Function forward has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

    def forward(self, x, t, soft=True, infer=True, response='bin'):
    if self.sep_heads:
    selector = t.cpu().data.numpy().astype('int').tolist()
    else:
    Severity: Minor
    Found in causallib/contrib/hemm/hemm.py - About 2 hrs to fix

    Function safe_join has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

    def safe_join(df: Optional[pd.DataFrame] = None, list_of_series: List[pd.Series] = None, return_series_names=False):
    """
    Safely joins (concatenates on axis 1) a collection of Series (or one DataFrame and multiple Series),
    while renaming Series that have a duplicate name (a name that already exists in DataFrame or another Series).
    * Note that DataFrame columns are never changed (only Series names are).
    Severity: Minor
    Found in causallib/survival/survival_utils.py - About 2 hrs to fix

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    X_te, T_te, Y_te, Z_te, mu1_te, mu0_te = X_[r:], T_[r:], Y_[r:], Z_[r:], mu1_[r:], mu0_[r:]
    Severity: Major
    Found in causallib/contrib/hemm/gen_synthetic_data.py and 1 other location - About 2 hrs to fix
    causallib/contrib/hemm/gen_synthetic_data.py on lines 175..175

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    X_tr, T_tr, Y_tr, Z_tr, mu1_tr, mu0_tr = X_[:r], T_[:r], Y_[:r], Z_[:r], mu1_[:r], mu0_[:r]
    Severity: Major
    Found in causallib/contrib/hemm/gen_synthetic_data.py and 1 other location - About 2 hrs to fix
    causallib/contrib/hemm/gen_synthetic_data.py on lines 176..176

    Function lcost has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

    def lcost(self, x_, t_, y_, ltype="log", response='bin', use_p_correction=True, imb_fun=None, p_alpha=1e-4,
    rbf_sigma=0.1, wass_its=20, wass_lambda=10.0):
    """Implements ELBO as the objective function (eq 12 in paper).
     
    Args:
    Severity: Minor
    Found in causallib/contrib/hemm/hemm.py - About 2 hrs to fix

    Function canonize_dtypes_and_names has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

    def canonize_dtypes_and_names(a=None, t=None, y=None, w=None, X=None):
    """
    Housekeeping method that assign names for unnamed series and canonizes their data types.
     
    Args:
    Severity: Minor
    Found in causallib/survival/survival_utils.py - About 2 hrs to fix

    Function generate_censor_col has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

    def generate_censor_col(self, X_parents, link_type, snr, prob_category, outcome_type,
    treatment_importance=None, survival_distribution=None, survival_baseline=None,
    var_name=None):
    """
    Generates a single censor variable column.
    Severity: Minor
    Found in causallib/simulation/CausalSimulator3.py - About 2 hrs to fix

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    if self.with_std:
    scales = X.loc[:, self._feature_mask_].std(skipna=self.ignore_nans)
    else:
    scales = pd.Series(1, index=continuous_features)
    Severity: Major
    Found in causallib/preprocessing/transformers.py and 1 other location - About 2 hrs to fix
    causallib/preprocessing/transformers.py on lines 68..71

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    if self.with_mean:
    means = X.loc[:, self._feature_mask_].mean(skipna=self.ignore_nans)
    else:
    means = pd.Series(0, index=continuous_features)
    Severity: Major
    Found in causallib/preprocessing/transformers.py and 1 other location - About 2 hrs to fix
    causallib/preprocessing/transformers.py on lines 74..77

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

    std[i] = std[i] + spread * (torch.rand_like(std[i]) - 0.5)
    Severity: Major
    Found in causallib/contrib/hemm/hemm.py and 2 other locations - About 1 hr to fix
    causallib/contrib/hemm/hemm.py on lines 80..80
    causallib/contrib/hemm/hemm.py on lines 82..82

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

    p[i] = p[i] + spread * (torch.rand_like(p[i]) - 0.5)
    Severity: Major
    Found in causallib/contrib/hemm/hemm.py and 2 other locations - About 1 hr to fix
    causallib/contrib/hemm/hemm.py on lines 80..80
    causallib/contrib/hemm/hemm.py on lines 81..81
    Severity
    Category
    Status
    Source
    Language