Skip to content

Commit

Permalink
Feature 404 v3.0.0 beta6 (#406)
Browse files Browse the repository at this point in the history
* Per #404, modifying version and dates

* Per #404, updating release notes

* Adding self as an argument to calculate_statistic to attempt to resolve error with METplotpy run

* Removing self as an argument to calculate_statistic to attempt to resolve error with METplotpy run because this would need to be done in the develop branch

* calculate_statistic() is not a SumStat class method.  Remove the logging, which requires the logger that is created in the constructor of the SumStat class.  Instead, raise an exception with a detailed message.

---------

Co-authored-by: Julie Prestopnik <[email protected]>
  • Loading branch information
bikegeek and jprestop authored Oct 17, 2024
1 parent 835ab36 commit 469c624
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 469c624

Please sign in to comment.