From f8814d5fb83d736a89e5f58605d5ad262df33c7d Mon Sep 17 00:00:00 2001 From: zm711 <92116279+zm711@users.noreply.github.com> Date: Thu, 17 Oct 2024 17:16:13 -0400 Subject: [PATCH 1/2] add new testing --- quantities/tests/test_methods.py | 7 +------ quantities/tests/test_numpy.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 quantities/tests/test_numpy.py diff --git a/quantities/tests/test_methods.py b/quantities/tests/test_methods.py index ba184a3..94710f3 100644 --- a/quantities/tests/test_methods.py +++ b/quantities/tests/test_methods.py @@ -19,7 +19,6 @@ def test_sum(self): self.assertQuantityEqual(self.q.sum(1), [3, 7]*pq.m) def test_nansum(self): - import numpy as np qnan = [[1,2], [3,4], [np.nan,np.nan]] * pq.m self.assertQuantityEqual(qnan.nansum(), 10*pq.m ) self.assertQuantityEqual(qnan.nansum(0), [4,6]*pq.m ) @@ -108,7 +107,7 @@ def test_nonzero(self): self.assertQuantityEqual(q.nonzero()[0], [0, 2, 3, 5]) def methodWithOut(self, name, result, q=None, *args, **kw): - import numpy as np + from .. import Quantity if q is None: @@ -153,7 +152,6 @@ def test_nanmax(self): self.assertQuantityEqual(q.nanmax(), 4*pq.m) def test_argmax(self): - import numpy as np self.assertQuantityEqual(self.q.argmax(), 3) self.assertQuantityEqual(self.q.argmax(axis=0), [1, 1]) self.assertQuantityEqual(self.q.argmax(axis=1), [1, 1]) @@ -178,7 +176,6 @@ def test_nanmin(self): self.assertQuantityEqual(q.nanmin(), 1*pq.m) def test_argmin(self): - import numpy as np self.assertQuantityEqual(self.q.argmin(), 0) self.assertQuantityEqual(self.q.argmin(axis=0), [0, 0]) self.assertQuantityEqual(self.q.argmin(axis=1), [0, 0]) @@ -252,7 +249,6 @@ def test_mean(self): self.methodWithOut('mean', [1.5, 3.5] * pq.m, axis=1) def test_nanmean(self): - import numpy as np q = [[1,2], [3,4], [np.nan,np.nan]] * pq.m self.assertQuantityEqual(q.nanmean(), self.q.mean()) @@ -267,7 +263,6 @@ def test_std(self): self.methodWithOut('std', [0.5, 0.5] * pq.m, axis=1) def test_nanstd(self): - import numpy as np q0 = [[1,2], [3,4]] * pq.m q1 = [[1,2], [3,4], [np.nan,np.nan]] * pq.m self.assertQuantityEqual(q0.std(), q1.nanstd()) diff --git a/quantities/tests/test_numpy.py b/quantities/tests/test_numpy.py new file mode 100644 index 0000000..f433952 --- /dev/null +++ b/quantities/tests/test_numpy.py @@ -0,0 +1,24 @@ +import warnings +from .. import QuantitiesDeprecationWarning, units as pq +from .common import TestCase +import numpy as np + +class TestNumpy2_0(TestCase): + + + # issues between NumPy < 2.0 and > 2.0 appear to be missed in current quantities testing + # https://github.com/NeuralEnsemble/python-neo/pull/1490 + # this is a small test class to add changes to ensure pre and post 2.0 compatability + + def setUp(self): + self.q = [[1, 2], [3, 4]] * pq.m + + def test_numpy_concatenate(self): + + concatenated_array = np.concatenate((self.q.flatten(), self.q.flatten())) + self.assertQuantityEqual(concatenated_array, [1,2,3,4]*pq.m) + + def test_numpy_dtype(self): + + test_array_float32 = np.arange(10, dtype=np.float32) * pq.s + self.assertEqual(test_array_float32.dtype, np.float32) \ No newline at end of file From e27053e7f7c173bc8a202520b05e265a6ebb2154 Mon Sep 17 00:00:00 2001 From: zm711 <92116279+zm711@users.noreply.github.com> Date: Thu, 17 Oct 2024 17:25:27 -0400 Subject: [PATCH 2/2] fix test --- quantities/tests/test_numpy.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quantities/tests/test_numpy.py b/quantities/tests/test_numpy.py index f433952..36d22f6 100644 --- a/quantities/tests/test_numpy.py +++ b/quantities/tests/test_numpy.py @@ -9,14 +9,14 @@ class TestNumpy2_0(TestCase): # issues between NumPy < 2.0 and > 2.0 appear to be missed in current quantities testing # https://github.com/NeuralEnsemble/python-neo/pull/1490 # this is a small test class to add changes to ensure pre and post 2.0 compatability - + def setUp(self): self.q = [[1, 2], [3, 4]] * pq.m def test_numpy_concatenate(self): concatenated_array = np.concatenate((self.q.flatten(), self.q.flatten())) - self.assertQuantityEqual(concatenated_array, [1,2,3,4]*pq.m) + self.assertQuantityEqual(concatenated_array, [1,2,3,4, 1,2,3,4]*pq.m) def test_numpy_dtype(self):
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: