summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_function_base.py
diff options
context:
space:
mode:
authorBen Root <ben.v.root@gmail.com>2012-01-21 22:22:02 -0600
committerCharles Harris <charlesr.harris@gmail.com>2012-01-27 20:58:58 -0700
commit9e2fd1066c92876bf1f3272ba1edf1acee9f0d04 (patch)
tree9d592daf62fae493ed0417753e4c0b1c3042faa9 /numpy/lib/tests/test_function_base.py
parent06d947c51726c303cc5c30f16643903d89da7207 (diff)
downloadnumpy-9e2fd1066c92876bf1f3272ba1edf1acee9f0d04.tar.gz
TST: Test gradient(...) of datetime64 and timedelta64 arrays.
Diffstat (limited to 'numpy/lib/tests/test_function_base.py')
-rw-r--r--numpy/lib/tests/test_function_base.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index ba6b336ff..fc033b164 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -265,10 +265,12 @@ class TestDiff(TestCase):
class TestGradient(TestCase):
def test_basic(self):
- x = array([[1, 1], [3, 4]])
+ v = [[1, 1], [3, 4]]
+ x = array(v)
dx = [array([[2., 3.], [2., 3.]]),
array([[0., 0.], [1., 1.]])]
assert_array_equal(gradient(x), dx)
+ assert_array_equal(gradient(v), dx)
def test_badargs(self):
# for 2D array, gradient can take 0,1, or 2 extra args
@@ -281,6 +283,22 @@ class TestGradient(TestCase):
x = np.ma.array([[1, 1], [3, 4]])
assert_equal(type(gradient(x)[0]), type(x))
+ def test_datetime64(self):
+ # Make sure gradient() can handle special types like datetime64
+ x = array(['1910-08-16', '1910-08-11', '1910-08-10', '1910-08-12',
+ '1910-10-12', '1910-12-12', '1912-12-12'],
+ dtype='datetime64[D]')
+ dx = array([ -5, -3, 0, 31, 61, 396, 731], dtype='timedelta64[D]')
+ assert_array_equal(gradient(x), dx)
+ assert_(dx.dtype == np.dtype('timedelta64[D]'))
+
+ def test_timedelta64(self):
+ # Make sure gradient() can handle special types like timedelta64
+ x = array([-5, -3, 10, 12, 61, 321, 300], dtype='timedelta64[D]')
+ dx = array([ 2, 7, 7, 25, 154, 119, -21], dtype='timedelta64[D]')
+ assert_array_equal(gradient(x), dx)
+ assert_(dx.dtype == np.dtype('timedelta64[D]'))
+
class TestAngle(TestCase):
def test_basic(self):