Ejemplo n.º 1
0
 def test_convertable_values(self):
     self.assertTrue(np.allclose(nanops._ensure_numeric('1'), 1.0),
                     'Failed for convertible integer string')
     self.assertTrue(np.allclose(nanops._ensure_numeric('1.1'), 1.1),
                     'Failed for convertible float string')
     self.assertTrue(np.allclose(nanops._ensure_numeric('1+1j'), 1 + 1j),
                     'Failed for convertible complex string')
Ejemplo n.º 2
0
 def test_convertable_values(self):
     self.assertTrue(np.allclose(nanops._ensure_numeric('1'), 1.0),
                     'Failed for convertible integer string')
     self.assertTrue(np.allclose(nanops._ensure_numeric('1.1'), 1.1),
                     'Failed for convertible float string')
     self.assertTrue(np.allclose(nanops._ensure_numeric('1+1j'), 1 + 1j),
                     'Failed for convertible complex string')
Ejemplo n.º 3
0
 def test_numeric_values(self):
     # Test integer
     self.assertEqual(nanops._ensure_numeric(1), 1, "Failed for int")
     # Test float
     self.assertEqual(nanops._ensure_numeric(1.1), 1.1, "Failed for float")
     # Test complex
     self.assertEqual(nanops._ensure_numeric(1 + 2j), 1 + 2j, "Failed for complex")
Ejemplo n.º 4
0
 def test_non_convertable_values(self):
     self.assertRaises(TypeError,
                       lambda: nanops._ensure_numeric('foo'))
     self.assertRaises(TypeError,
                       lambda: nanops._ensure_numeric({}))
     self.assertRaises(TypeError,
                       lambda: nanops._ensure_numeric([]))
Ejemplo n.º 5
0
 def test_non_convertable_values(self):
     self.assertRaises(TypeError,
                       lambda: nanops._ensure_numeric('foo'))
     self.assertRaises(TypeError,
                       lambda: nanops._ensure_numeric({}))
     self.assertRaises(TypeError,
                       lambda: nanops._ensure_numeric([]))
Ejemplo n.º 6
0
 def test_numeric_values(self):
     # Test integer
     self.assertEqual(nanops._ensure_numeric(1), 1, 'Failed for int')
     # Test float
     self.assertEqual(nanops._ensure_numeric(1.1), 1.1, 'Failed for float')
     # Test complex
     self.assertEqual(nanops._ensure_numeric(1 + 2j), 1 + 2j,
                      'Failed for complex')
Ejemplo n.º 7
0
    def test_numeric_values(self):
        # Test integer
        assert nanops._ensure_numeric(1) == 1

        # Test float
        assert nanops._ensure_numeric(1.1) == 1.1

        # Test complex
        assert nanops._ensure_numeric(1 + 2j) == 1 + 2j
Ejemplo n.º 8
0
    def test_numeric_values(self):
        # Test integer
        assert nanops._ensure_numeric(1) == 1

        # Test float
        assert nanops._ensure_numeric(1.1) == 1.1

        # Test complex
        assert nanops._ensure_numeric(1 + 2j) == 1 + 2j
Ejemplo n.º 9
0
    def test_ndarray(self):
        # Test numeric ndarray
        values = np.array([1, 2, 3])
        assert np.allclose(nanops._ensure_numeric(values), values)

        # Test object ndarray
        o_values = values.astype(object)
        assert np.allclose(nanops._ensure_numeric(o_values), values)

        # Test convertible string ndarray
        s_values = np.array(['1', '2', '3'], dtype=object)
        assert np.allclose(nanops._ensure_numeric(s_values), values)

        # Test non-convertible string ndarray
        s_values = np.array(['foo', 'bar', 'baz'], dtype=object)
        pytest.raises(ValueError, lambda: nanops._ensure_numeric(s_values))
Ejemplo n.º 10
0
    def test_ndarray(self):
        # Test numeric ndarray
        values = np.array([1, 2, 3])
        self.assertTrue(np.allclose(nanops._ensure_numeric(values), values), "Failed for numeric ndarray")

        # Test object ndarray
        o_values = values.astype(object)
        self.assertTrue(np.allclose(nanops._ensure_numeric(o_values), values), "Failed for object ndarray")

        # Test convertible string ndarray
        s_values = np.array(["1", "2", "3"], dtype=object)
        self.assertTrue(np.allclose(nanops._ensure_numeric(s_values), values), "Failed for convertible string ndarray")

        # Test non-convertible string ndarray
        s_values = np.array(["foo", "bar", "baz"], dtype=object)
        self.assertRaises(ValueError, lambda: nanops._ensure_numeric(s_values))
Ejemplo n.º 11
0
    def test_ndarray(self):
        # Test numeric ndarray
        values = np.array([1, 2, 3])
        assert np.allclose(nanops._ensure_numeric(values), values)

        # Test object ndarray
        o_values = values.astype(object)
        assert np.allclose(nanops._ensure_numeric(o_values), values)

        # Test convertible string ndarray
        s_values = np.array(['1', '2', '3'], dtype=object)
        assert np.allclose(nanops._ensure_numeric(s_values), values)

        # Test non-convertible string ndarray
        s_values = np.array(['foo', 'bar', 'baz'], dtype=object)
        msg = r"could not convert string to float: '(foo|baz)'"
        with pytest.raises(ValueError, match=msg):
            nanops._ensure_numeric(s_values)
Ejemplo n.º 12
0
    def test_ndarray(self):
        # Test numeric ndarray
        values = np.array([1, 2, 3])
        assert np.allclose(nanops._ensure_numeric(values), values)

        # Test object ndarray
        o_values = values.astype(object)
        assert np.allclose(nanops._ensure_numeric(o_values), values)

        # Test convertible string ndarray
        s_values = np.array(["1", "2", "3"], dtype=object)
        assert np.allclose(nanops._ensure_numeric(s_values), values)

        # Test non-convertible string ndarray
        s_values = np.array(["foo", "bar", "baz"], dtype=object)
        msg = r"could not convert string to float: '(foo|baz)'"
        with pytest.raises(ValueError, match=msg):
            nanops._ensure_numeric(s_values)
Ejemplo n.º 13
0
 def test_non_convertable_values(self):
     msg = "Could not convert foo to numeric"
     with pytest.raises(TypeError, match=msg):
         nanops._ensure_numeric('foo')
     msg = "Could not convert {} to numeric"
     with pytest.raises(TypeError, match=msg):
         nanops._ensure_numeric({})
     msg = r"Could not convert \[\] to numeric"
     with pytest.raises(TypeError, match=msg):
         nanops._ensure_numeric([])
Ejemplo n.º 14
0
 def test_non_convertable_values(self):
     msg = "Could not convert foo to numeric"
     with pytest.raises(TypeError, match=msg):
         nanops._ensure_numeric('foo')
     msg = "Could not convert {} to numeric"
     with pytest.raises(TypeError, match=msg):
         nanops._ensure_numeric({})
     msg = r"Could not convert \[\] to numeric"
     with pytest.raises(TypeError, match=msg):
         nanops._ensure_numeric([])
Ejemplo n.º 15
0
    def test_non_convertable_values(self):
        msg = "Could not convert foo to numeric"
        with pytest.raises(TypeError, match=msg):
            nanops._ensure_numeric("foo")

        # with the wrong type, python raises TypeError for us
        msg = "argument must be a string or a number"
        with pytest.raises(TypeError, match=msg):
            nanops._ensure_numeric({})
        with pytest.raises(TypeError, match=msg):
            nanops._ensure_numeric([])
Ejemplo n.º 16
0
 def test_convertable_values(self):
     assert np.allclose(nanops._ensure_numeric("1"), 1.0)
     assert np.allclose(nanops._ensure_numeric("1.1"), 1.1)
     assert np.allclose(nanops._ensure_numeric("1+1j"), 1 + 1j)
Ejemplo n.º 17
0
 def test_convertable_values(self):
     assert np.allclose(nanops._ensure_numeric('1'), 1.0)
     assert np.allclose(nanops._ensure_numeric('1.1'), 1.1)
     assert np.allclose(nanops._ensure_numeric('1+1j'), 1 + 1j)