From c233e8f6c89cbed8e715ed8ec728b8e6596929e4 Mon Sep 17 00:00:00 2001 From: Eirikur Jonsson <36180221+eirikurj@users.noreply.github.com> Date: Mon, 18 Dec 2023 16:07:41 +0000 Subject: [PATCH] Fix numpy 1.25 deprecation warnings (#372) * fix deprecation warnings * adding disallow_deprecations to tests * address comments --- .github/test_real.sh | 2 +- pyoptsparse/pyOpt_solution.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/test_real.sh b/.github/test_real.sh index 69eb3d54..4af0258e 100755 --- a/.github/test_real.sh +++ b/.github/test_real.sh @@ -11,4 +11,4 @@ cd tests # we have to copy over the coveragerc file to make sure it's in the # same directory where codecov is run cp ../.coveragerc . -testflo --pre_announce -v --coverage --coverpkg pyoptsparse $EXTRA_FLAGS +testflo --pre_announce --disallow_deprecations -v --coverage --coverpkg pyoptsparse $EXTRA_FLAGS diff --git a/pyoptsparse/pyOpt_solution.py b/pyoptsparse/pyOpt_solution.py index 1d41b342..f6fba48e 100644 --- a/pyoptsparse/pyOpt_solution.py +++ b/pyoptsparse/pyOpt_solution.py @@ -1,6 +1,9 @@ # Standard Python modules import copy +# External modules +import numpy as np + # Local modules from .pyOpt_optimization import Optimization @@ -49,9 +52,9 @@ def __init__(self, optProb, xStar, fStar, lambdaStar, optInform, info): i += 1 # Now set the f-values - if isinstance(fStar, float) or len(fStar) == 1: - self.objectives[list(self.objectives.keys())[0]].value = float(fStar) - fStar = float(fStar) + if isinstance(fStar, np.ndarray) and len(fStar) == 1: + self.objectives[list(self.objectives.keys())[0]].value = fStar.item() + fStar = fStar.item() else: for f_name, f in self.objectives.items(): f.value = fStar[f_name]