Skip to content

Commit

Permalink
calculate_statistic() is not a SumStat class method. Remove the loggi…
Browse files Browse the repository at this point in the history
…ng, which requires the logger that is created in the constructor of the SumStat class. Instead, raise an exception with a detailed message.
  • Loading branch information
bikegeek committed Oct 17, 2024
1 parent 09afa8e commit 6123792
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions metcalcpy/sum_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def process_rows(self):
# return self.parallelize(data, partial(self.run_on_subset, func), num_of_processes)


def calculate_statistic(self, values, columns_names, stat_name, aggregation=False):
def calculate_statistic(values, columns_names, stat_name, aggregation=False):
"""Calculate the statistic of values
Args:
values: a np.array of values we want to calculate the statistic on
Expand All @@ -307,19 +307,17 @@ def calculate_statistic(self, values, columns_names, stat_name, aggregation=Fals
Raises:
an error
"""
logger = self.logger
safe_log(logger, "debug", f"Calculating statistic '{stat_name}' with aggregation: {aggregation}.")
try:
func_name = f'calculate_{stat_name}'
num_parameters = len(signature(globals()[func_name]).parameters)
if num_parameters == 2:
stat = globals()[func_name](values, columns_names, logger=logger)
stat = globals()[func_name](values, columns_names)
else:
stat = globals()[func_name](values, columns_names, aggregation, logger=logger)
safe_log(logger, "info", f"Successfully calculated statistic '{stat_name}'.")
except Exception as e:
safe_log(logger, "error", f"An error occurred while calculating statistic '{stat_name}': {e}")
raise
stat = globals()[func_name](values, columns_names, aggregation)
except Exception:
raise RuntimeError(
"Error occurred while calculating statistic using METcalcpy sum_stat module's calculate_statistic(): " +
stat_name)
return stat


Expand Down

0 comments on commit 6123792

Please sign in to comment.