From eae30a9f2664fb86f89f325efb8a9d1e844e41fc Mon Sep 17 00:00:00 2001 From: "Neal P. Avis Kozar" Date: Tue, 7 Jan 2025 15:52:09 -0500 Subject: [PATCH 1/3] Fix Numpy error starting in v1.25.0 from element-wise boolean logic --- pippi_read.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pippi_read.py b/pippi_read.py index 077b9d4..e22b22c 100644 --- a/pippi_read.py +++ b/pippi_read.py @@ -313,7 +313,7 @@ def getChainData(filename, cut_all_invalid=None, requested_cols=None, assignment data_isvalid.append(np.array(entries[column_names[index]+"_isvalid"], dtype=np.float64)) lookup_key[index] = index_count index_count += 1 - non_functional_cols = [i for i, elem in enumerate(data) if data[i] != 'functional'] + non_functional_cols = [i for i, elem in enumerate(data) if np.all(data[i] != 'functional')] # Numpy now requires the user cast to a scalar when performing boolean checks on arrays if not non_functional_cols: print("ERROR: At least one non-function assignment is needed in") print("assign_to_pippi_datastream, or a multiplicity or likelihood") @@ -325,13 +325,13 @@ def getChainData(filename, cut_all_invalid=None, requested_cols=None, assignment # Fill in the functional columns with zeros. Note that this uses more memory than doing it after validity # cuts, but should actually be faster (I think; haven't actually tested that). It makes the code simpler too. for i, elem in enumerate(data): - if elem == 'functional': + if np.any(elem == 'functional'): # Numpy cast to a scalar boolean check data[i] = np.zeros(total_samples, dtype=np.float64) else: # Do some pruning to deal with cases where the some datasets have extra entries (although this arguably indicates a bug in the sampler) data[i] = elem[:total_samples] for i, elem in enumerate(data_isvalid): - if elem == 'functional': + if np.any(elem == 'functional'): # Numpy cast to a scalar boolean check data_isvalid[i] = np.ones(total_samples, dtype=np.float64) else: # Do some pruning to deal with cases where the some datasets have extra entries (although this arguably indicates a bug in the sampler) From c4fdeb1731704ac1a816b151c6b6236fb019a6da Mon Sep 17 00:00:00 2001 From: "Neal P. Avis Kozar" Date: Tue, 7 Jan 2025 16:11:01 -0500 Subject: [PATCH 2/3] Distutils dropped by PEP 632, using recommended Packaging instead --- Readme | 4 ++-- pippi_parse.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Readme b/Readme index 4376aff..41f1623 100644 --- a/Readme +++ b/Readme @@ -24,8 +24,8 @@ Installation Pippi requires almost no installation. 1. Make sure you have the following already installed: - * Either Python v2.7 or later or Python v3 - * NumPy and SciPy libraries for python (NumPy v0.9.0 or + * Either Python v2.7 or later or Python v3.8 or later + * NumPy, SciPy, and Packaging libraries for python (NumPy v0.9.0 or greater is required for full functionality) * ctioga2 v0.8 or later * bash diff --git a/pippi_parse.py b/pippi_parse.py index 594cd6f..454ebc0 100644 --- a/pippi_parse.py +++ b/pippi_parse.py @@ -17,8 +17,8 @@ from scipy.interpolate import InterpolatedUnivariateSpline as oneDspline from scipy.interpolate import RectBivariateSpline as twoDbilinear -from distutils.version import StrictVersion -if StrictVersion(scipyCurrent.version) >= StrictVersion("0.9.0"): +from packaging.version import Version +if Version(scipyCurrent.version) >= Version("0.9.0"): from scipy.interpolate import CloughTocher2DInterpolator as twoDspline # Define parse-specific pip file entries @@ -69,7 +69,7 @@ def parse(filename): if twoDplots.value is not None: if intMethod.value is None: intMethod.value = allowedIntMethods[0] if intMethod.value not in allowedIntMethods: sys.exit('Error: unrecognised interpolation_method.') - if intMethod.value == 'spline' and StrictVersion(scipyCurrent.version) < StrictVersion("0.9.0"): + if intMethod.value == 'spline' and Version(scipyCurrent.version) < Version("0.9.0"): sys.exit('Sorry, Clough-Tocher 2D interpolation is not supported in SciPy \n'+ 'v0.8 or lower; please upgrade your installation to use this option.') From 1f4902e07273f73a2c9adb0407799820fa5aeb6e Mon Sep 17 00:00:00 2001 From: "Neal P. Avis Kozar" Date: Tue, 7 Jan 2025 16:50:28 -0500 Subject: [PATCH 3/3] Stop printing error message on clean exit --- pippi | 28 ++++++++++++++++++---------- pippi_read.py | 2 +- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/pippi b/pippi index f7c638a..69bcfbf 100755 --- a/pippi +++ b/pippi @@ -43,11 +43,15 @@ def main(arguments): try: command(arguments[2:]) except BaseException as err: - print() - print('Running pippi failed in '+command.__name__+' operation, due to error:') - print(err) - print() - sys.exit() + clean_exit = False + if isinstance(err, SystemExit): + clean_exit = True if err.code == 0 else clean_exit + if not clean_exit: + print() + print('Running pippi failed in '+command.__name__+' operation, due to error:') + print(err) + print() + sys.exit() if not command in [merge, pare]: print() print('Completed sucessfully.') @@ -61,11 +65,15 @@ def main(arguments): try: command(arguments[1:]) except BaseException as err: - print() - print('Running pippi failed in '+command.__name__+' operation.') - print(err) - print() - sys.exit() + clean_exit = False + if isinstance(err, SystemExit): + clean_exit = True if err.code == 0 else clean_exit + if not clean_exit: + print() + print('Running pippi failed in '+command.__name__+' operation.') + print(err) + print() + sys.exit() print() print('Completed sucessfully.') print() diff --git a/pippi_read.py b/pippi_read.py index e22b22c..cf87263 100644 --- a/pippi_read.py +++ b/pippi_read.py @@ -278,7 +278,7 @@ def getChainData(filename, cut_all_invalid=None, requested_cols=None, assignment for i, column_name in enumerate(column_names): if column_name != '': print(" ", i, ":", column_name) print() - quit() + sys.exit(0) # Identify any likelihood or multiplicity indicated by the labels. if labels: