Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add additional NumPy tests for inconsistent behavior across versions. #244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions quantities/tests/test_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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])
Expand All @@ -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])
Expand Down Expand Up @@ -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())

Expand All @@ -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())
Expand Down
24 changes: 24 additions & 0 deletions quantities/tests/test_numpy.py
Original file line number Diff line number Diff line change
@@ -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, 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)
Loading