From 34ee5b0cc38d27025bb089f2dedd0df3799e10fd Mon Sep 17 00:00:00 2001 From: SongshGeo Date: Sat, 25 Feb 2023 17:01:24 +0800 Subject: [PATCH 1/2] fix: :bug: fixing complains of pd.groupby fixed a warning from pandas >>> .groupby(..., group_keys=False) --- SyntheticControlMethods/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SyntheticControlMethods/main.py b/SyntheticControlMethods/main.py index aa7a306..0d96cf9 100644 --- a/SyntheticControlMethods/main.py +++ b/SyntheticControlMethods/main.py @@ -458,13 +458,13 @@ def difference_data(self, dataset, not_diff_cols): ignore_all_cols = not_diff_cols == None #Compute difference of outcome variable - modified_dataset[data.outcome_var] = modified_dataset.groupby(data.id)[data.outcome_var].apply( + modified_dataset[data.outcome_var] = modified_dataset.groupby(data.id, group_keys=False)[data.outcome_var].apply( lambda unit: unit.interpolate(method='linear', limit_direction="both")).diff() #For covariates for col in data.covariates: #Fill in missing values using unitwise linear interpolation - modified_dataset[col] = modified_dataset.groupby(data.id)[col].apply( + modified_dataset[col] = modified_dataset.groupby(data.id, group_keys=False)[col].apply( lambda unit: unit.interpolate(method='linear', limit_direction="both")) #Compute change from previous period From 727afd8f450ff2ccbd7850a8d10705f0053f726b Mon Sep 17 00:00:00 2001 From: SongshGeo Date: Sun, 15 Dec 2024 14:01:59 +0100 Subject: [PATCH 2/2] fix: :bug: Fixed x_0 wrong dimension issue optimize.py should delete "size=1" https://github.com/OscarEngelbrektson/SyntheticControlMethods/issues/27 --- SyntheticControlMethods/optimize.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SyntheticControlMethods/optimize.py b/SyntheticControlMethods/optimize.py index e264c01..9073db4 100644 --- a/SyntheticControlMethods/optimize.py +++ b/SyntheticControlMethods/optimize.py @@ -86,10 +86,10 @@ def optimize(self, v_0 = np.append(v_0, 0) else: #Dirichlet distribution returns a valid pmf over n_covariates states - v_0 = self.original_data.rng.dirichlet(np.ones(data.n_covariates), size=1) + v_0 = self.original_data.rng.dirichlet(np.ones(data.n_covariates)) if pen == "auto": #if pen =="auto", we have an additional parameter to optimize over, so we append it - v_0 = np.append(v_0, self.original_data.rng.lognormal(1.5, 1, size=1)) #Still experimenting with what distribution is appropriate + v_0 = np.append(v_0, self.original_data.rng.lognormal(1.5, 1)) #Still experimenting with what distribution is appropriate #Required to have non negative values