diff --git a/auto_sizing/cli.py b/auto_sizing/cli.py index 66d547c..05f5b38 100644 --- a/auto_sizing/cli.py +++ b/auto_sizing/cli.py @@ -372,7 +372,7 @@ def run( raise Exception("Either provide a config file or run auto sizing presets.") analysis_executor = AnalysisExecutor( - target_slug=target_slug, + target_slug=target_slug if target_slug else All, project_id=project_id, dataset_id=dataset_id, bucket=bucket, diff --git a/auto_sizing/size_calculation.py b/auto_sizing/size_calculation.py index 7b3b207..7414243 100644 --- a/auto_sizing/size_calculation.py +++ b/auto_sizing/size_calculation.py @@ -8,6 +8,7 @@ from mozanalysis.experiment import TimeLimits from mozanalysis.frequentist_stats.sample_size import z_or_t_ind_sample_size_calc from mozanalysis.sizing import HistoricalTarget +from numpy import nan, ndarray from pandas import DataFrame import auto_sizing.errors as errors @@ -86,7 +87,9 @@ def calculate_metrics( ) ) - df = self.bigquerycontext.run_query(metrics_sql, metrics_table_name).to_dataframe() + df = self.bigquerycontext.run_query( + metrics_sql, metrics_table_name, replace_tables=True + ).to_dataframe() delete_bq_table( self.bigquerycontext.fully_qualify_table_name(targets_table_name), self.project ) @@ -106,8 +109,12 @@ def calculate_sample_sizes( metrics_results = { key: { "number_of_clients_targeted": res[key]["number_of_clients_targeted"], - "sample_size_per_branch": res[key]["sample_size_per_branch"], - "population_percent_per_branch": res[key]["population_percent_per_branch"], + "sample_size_per_branch": nan + if isinstance(res[key]["sample_size_per_branch"], ndarray) + else res[key]["sample_size_per_branch"], + "population_percent_per_branch": nan + if type(res[key]["population_percent_per_branch"], ndarray) + else res[key]["population_percent_per_branch"], } for key in res.keys() } @@ -124,7 +131,7 @@ def publish_results(self, result_dict: Dict[str, Any], current_date: str) -> Non path.write_text(json.dumps(result_dict)) print(f"Results saved at {path}") - else: + elif self.bucket: export_sample_size_json( self.project, self.bucket, @@ -133,6 +140,10 @@ def publish_results(self, result_dict: Dict[str, Any], current_date: str) -> Non current_date, ) + path = Path(__file__).parent / f"{self.config.target_slug}.json" + path.write_text(json.dumps(result_dict)) + print(f"Results saved at {path}") + def run(self, current_date: datetime) -> None: time_limits = self._validate_requested_timelimits(current_date)