Exemplo n.º 1
0
    def test_compute_colaresi(self):
        """ Test compute_colaresi() """
        df = Crosslevel.merge_levels(self.df_h, self.df_l, self.df_links)

        col_h = self.df_h.columns[0]
        col_l = self.df_l.columns[0]

        sum_h_by_l = df.groupby([self.timevar,
                                 self.groupvar_l])[col_h].transform('sum')

        p_h = df[col_h]
        p_l = df[col_l]

        joint_1 = p_l * (p_h / sum_h_by_l)

        joint_2 = Crosslevel.compute_colaresi(df, col_h, col_l, self.timevar,
                                              self.groupvar_l)

        pd.testing.assert_series_equal(joint_1, joint_2)
Exemplo n.º 2
0
    def test_worker_colaresi(self):
        """ Test colaresi worker chain """

        # Compute colaresian product by calling static worker directly
        df_merged = Crosslevel.merge_levels(self.df_h, self.df_l,
                                            self.df_links)
        job = self.job_colaresi
        result_1 = Crosslevel.compute_colaresi(df=df_merged,
                                               col_h=job['col_h'],
                                               col_l=job['col_l'],
                                               timevar=self.timevar,
                                               groupvar_l=self.groupvar_l)

        # Compute by calling the worker chain

        this_cl = Crosslevel()
        this_cl._setup_state(self.df_h, self.df_l, self.df_links, self.timevar,
                             self.groupvar_h, self.groupvar_l)

        result_2 = this_cl.worker(self.local_settings, job)

        pd.testing.assert_series_equal(result_1, result_2)