From 1920ff0ecb146a050c1c2f0a199cf620834728b2 Mon Sep 17 00:00:00 2001 From: Arrielle Opotowsky Date: Fri, 3 Jan 2025 10:51:19 -0600 Subject: [PATCH] Unpinning the max `matplotlib` version (#2040) --- armi/bookkeeping/db/database.py | 11 ++++++----- armi/bookkeeping/db/databaseInterface.py | 5 ++++- armi/reactor/assemblies.py | 4 ++-- armi/reactor/components/__init__.py | 6 +++--- armi/utils/mathematics.py | 7 +++++-- armi/utils/tests/test_iterables.py | 7 ------- armi/utils/tests/test_tabulate.py | 6 +++--- armi/utils/tests/test_textProcessors.py | 2 +- pyproject.toml | 3 ++- 9 files changed, 26 insertions(+), 25 deletions(-) diff --git a/armi/bookkeeping/db/database.py b/armi/bookkeeping/db/database.py index 5a718cda8..672e905fd 100644 --- a/armi/bookkeeping/db/database.py +++ b/armi/bookkeeping/db/database.py @@ -1097,7 +1097,7 @@ def _readParams(h5group, compTypeName, comps, allowMissing=False): ) ) - if data.dtype.type is np.string_: + if data.dtype.type is np.bytes_: data = np.char.decode(data) if attrs.get("specialFormatting", False): @@ -1291,7 +1291,7 @@ def getHistoriesByLocation( ) raise - if data.dtype.type is np.string_: + if data.dtype.type is np.bytes_: data = np.char.decode(data) if dataSet.attrs.get("specialFormatting", False): @@ -1394,8 +1394,9 @@ def getHistories( # current time step and something has created the group to store aux data continue - cycle = h5TimeNodeGroup.attrs["cycle"] - timeNode = h5TimeNodeGroup.attrs["timeNode"] + # might save as int or np.int64, so forcing int keeps things predictable + cycle = int(h5TimeNodeGroup.attrs["cycle"]) + timeNode = int(h5TimeNodeGroup.attrs["timeNode"]) layout = Layout( (self.versionMajor, self.versionMinor), h5group=h5TimeNodeGroup ) @@ -1450,7 +1451,7 @@ def getHistories( ) raise - if data.dtype.type is np.string_: + if data.dtype.type is np.bytes_: data = np.char.decode(data) if dataSet.attrs.get("specialFormatting", False): diff --git a/armi/bookkeeping/db/databaseInterface.py b/armi/bookkeeping/db/databaseInterface.py index fd5ebbd2b..d5850ed35 100644 --- a/armi/bookkeeping/db/databaseInterface.py +++ b/armi/bookkeeping/db/databaseInterface.py @@ -390,7 +390,10 @@ def getHistory( if nowRequested: for param in params or history.keys(): if param == "location": - history[param][now] = tuple(comp.spatialLocator.indices) + # might save as int or np.int64, so forcing int keeps things predictable + history[param][now] = tuple( + int(i) for i in comp.spatialLocator.indices + ) else: history[param][now] = comp.p[param] diff --git a/armi/reactor/assemblies.py b/armi/reactor/assemblies.py index 149c04690..c36833513 100644 --- a/armi/reactor/assemblies.py +++ b/armi/reactor/assemblies.py @@ -1021,7 +1021,7 @@ def getBlocksBetweenElevations(self, zLower, zUpper): return blocksHere def getParamValuesAtZ( - self, param, elevations, interpType="linear", fillValue=np.NaN + self, param, elevations, interpType="linear", fillValue=np.nan ): """ Interpolates a param axially to find it at any value of elevation z. @@ -1070,7 +1070,7 @@ def getParamValuesAtZ( ) return interpolator(elevations) - def getParamOfZFunction(self, param, interpType="linear", fillValue=np.NaN): + def getParamOfZFunction(self, param, interpType="linear", fillValue=np.nan): """ Interpolates a param axially to find it at any value of elevation z. diff --git a/armi/reactor/components/__init__.py b/armi/reactor/components/__init__.py index 953d12d22..8b5a938a2 100644 --- a/armi/reactor/components/__init__.py +++ b/armi/reactor/components/__init__.py @@ -132,7 +132,7 @@ def __init__( material, Tinput, Thot, - area=np.NaN, + area=np.nan, modArea=None, isotopics=None, mergeWith=None, @@ -224,12 +224,12 @@ def __init__( material, Tinput, Thot, - area=np.NaN, + area=np.nan, op=None, isotopics=None, mergeWith=None, components=None, - volume=np.NaN, + volume=np.nan, ): Component.__init__( self, diff --git a/armi/utils/mathematics.py b/armi/utils/mathematics.py index 3169e92be..57ac4fe1e 100644 --- a/armi/utils/mathematics.py +++ b/armi/utils/mathematics.py @@ -411,7 +411,9 @@ def goalFunc(guess, func, positiveGuesses): tol=tol, options={"maxiter": maxIterations}, ) - ans = float(X["x"]) + + # X returns `[num]` instead of `num`, so we have to grab the first/only element in that list + ans = float(X["x"][0]) if positiveGuesses is True: ans = abs(ans) @@ -515,7 +517,8 @@ def parabolaFromPoints(p1, p2, p3): print("Error in parabola {} {}".format(A, b)) raise - return float(x[0]), float(x[1]), float(x[2]) + # x[#] returns `[num]` instead of `num`, so we have to grab the first/only element in that list + return float(x[0][0]), float(x[1][0]), float(x[2][0]) def parabolicInterpolation(ap, bp, cp, targetY): diff --git a/armi/utils/tests/test_iterables.py b/armi/utils/tests/test_iterables.py index f1ebcb8e0..fc233810a 100644 --- a/armi/utils/tests/test_iterables.py +++ b/armi/utils/tests/test_iterables.py @@ -13,7 +13,6 @@ # limitations under the License. """Unittests for iterables.py.""" -import time import unittest import numpy as np @@ -69,20 +68,14 @@ def test_split(self): self.assertEqual(unchu, data) def test_packingAndUnpackingBinaryStrings(self): - start = time.perf_counter() packed = iterables.packBinaryStrings(_TEST_DATA) unpacked = iterables.unpackBinaryStrings(packed["turtle"][0]) - timeDelta = time.perf_counter() - start self.assertEqual(_TEST_DATA["turtle"], unpacked) - return timeDelta def test_packingAndUnpackingHexStrings(self): - start = time.perf_counter() packed = iterables.packHexStrings(_TEST_DATA) unpacked = iterables.unpackHexStrings(packed["turtle"][0]) - timeDelta = time.perf_counter() - start self.assertEqual(_TEST_DATA["turtle"], unpacked) - return timeDelta def test_sequenceInit(self): # init an empty sequence diff --git a/armi/utils/tests/test_tabulate.py b/armi/utils/tests/test_tabulate.py index 06a27ec1b..140c28426 100644 --- a/armi/utils/tests/test_tabulate.py +++ b/armi/utils/tests/test_tabulate.py @@ -213,7 +213,7 @@ def test_numpyRecordArray(self): [("Alice", 23, 169.5), ("Bob", 27, 175.0)], dtype={ "names": ["name", "age", "height"], - "formats": ["a32", "uint8", "float32"], + "formats": ["S32", "uint8", "float32"], }, ) expected = "\n".join( @@ -233,7 +233,7 @@ def test_numpyRecordArrayKeys(self): [("Alice", 23, 169.5), ("Bob", 27, 175.0)], dtype={ "names": ["name", "age", "height"], - "formats": ["a32", "uint8", "float32"], + "formats": ["S32", "uint8", "float32"], }, ) expected = "\n".join( @@ -253,7 +253,7 @@ def test_numpyRecordArrayHeaders(self): [("Alice", 23, 169.5), ("Bob", 27, 175.0)], dtype={ "names": ["name", "age", "height"], - "formats": ["a32", "uint8", "float32"], + "formats": ["S32", "uint8", "float32"], }, ) expected = "\n".join( diff --git a/armi/utils/tests/test_textProcessors.py b/armi/utils/tests/test_textProcessors.py index 141ebe58f..16f5a11ef 100644 --- a/armi/utils/tests/test_textProcessors.py +++ b/armi/utils/tests/test_textProcessors.py @@ -145,7 +145,7 @@ def test_readFile(self): def test_readFileWithPattern(self): with textProcessors.SequentialReader(self._DUMMY_FILE_NAME) as sr: - self.assertTrue(sr.searchForPattern("(X\s+Y\s+\d+\.\d+)")) + self.assertTrue(sr.searchForPattern(r"(X\s+Y\s+\d+\.\d+)")) self.assertEqual(float(sr.line.split()[2]), 3.5) def test_issueWarningOnFindingText(self): diff --git a/pyproject.toml b/pyproject.toml index affae444d..0de69c1e2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,7 +34,8 @@ dependencies = [ "h5py>=3.0,<=3.9 ; python_version < '3.11.0'", "h5py>=3.9 ; python_version >= '3.11.0'", # Needed because our database files are H5 format "htmltree>=0.7.6", # Our reports have HTML output - "matplotlib>=3.5.3,<3.8.0", # Important plotting library + "matplotlib>=3.5.3,<3.8.0 ; python_version < '3.11.0'", + "matplotlib>=3.5.3 ; python_version >= '3.11.0'", # Important plotting library "numpy>=1.21", # Important math library "ordered-set>=3.1.1", # A useful data structure "pluggy>=1.2.0", # Central tool behind the ARMI Plugin system