<commit_before>import copy

import numpy as np

from dowhy.causal_refuter import CausalRefutation
from dowhy.causal_refuter import CausalRefuter


class PlaceboTreatmentRefuter(CausalRefuter):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._placebo_type = kwargs["placebo_type"]

    def refute_estimate(self):
        num_rows = self._data.shape[0]
        if self._placebo_type == "permute":
            new_treatment = self._data[self._treatment_name].sample(frac=1).values
        else:
            new_treatment = np.random.randn(num_rows)
        new_data = self._data.assign(placebo=new_treatment)

        self.logger.debug(new_data[0:10])
        estimator_class = self._estimate.params['estimator_class']
        identified_estimand = copy.deepcopy(self._target_estimand)
        identified_estimand.treatment_variable = "placebo"

        new_estimator = estimator_class(
            new_data,
            identified_estimand,
            "placebo", self._outcome_name,
            test_significance=None
        )
        new_effect = new_estimator.estimate_effect()
        refute = CausalRefutation(self._estimate.value, new_effect.value,
                                  refutation_type="Refute: Use a Placebo Treatment")
        return refute<commit_msg>treatment var from str to list in placebo refuter<commit_after>import copy

import numpy as np

from dowhy.causal_refuter import CausalRefutation
from dowhy.causal_refuter import CausalRefuter


class PlaceboTreatmentRefuter(CausalRefuter):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._placebo_type = kwargs["placebo_type"]

    def refute_estimate(self):
        num_rows = self._data.shape[0]
        if self._placebo_type == "permute":
            new_treatment = self._data[self._treatment_name].sample(frac=1).values
        else:
            new_treatment = np.random.randn(num_rows)
        new_data = self._data.assign(placebo=new_treatment)

        self.logger.debug(new_data[0:10])
        estimator_class = self._estimate.params['estimator_class']
        identified_estimand = copy.deepcopy(self._target_estimand)
        identified_estimand.treatment_variable = ["placebo"]

        new_estimator = estimator_class(
            new_data,
            identified_estimand,
            "placebo", self._outcome_name,
            test_significance=None
        )
        new_effect = new_estimator.estimate_effect()
        refute = CausalRefutation(self._estimate.value, new_effect.value,
                                  refutation_type="Refute: Use a Placebo Treatment")
        return refute
{'fraction_non_alphanumeric': 0.0880597014925373, 'fraction_numerical': 0.0037313432835820895, 'mean_word_length': 2.8354792560801143, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6265415', 'n_tokens_mistral': 857, 'n_tokens_neox': 795, 'n_words': 135}