Python pandas.core.nanops._ensure_numeric() Examples

The following are 20 code examples of pandas.core.nanops._ensure_numeric(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pandas.core.nanops , or try the search function .
Example #1
Source File: test_nanops.py    From recruit with Apache License 2.0 6 votes vote down vote up
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)) 
Example #2
Source File: test_nanops.py    From twitter-stock-recommendation with MIT License 6 votes vote down vote up
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)) 
Example #3
Source File: test_nanops.py    From vnpy_crypto with MIT License 6 votes vote down vote up
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)) 
Example #4
Source File: test_nanops.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 6 votes vote down vote up
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)) 
Example #5
Source File: test_nanops.py    From elasticintel with GNU General Public License v3.0 6 votes vote down vote up
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)) 
Example #6
Source File: test_nanops.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_non_convertable_values(self):
        pytest.raises(TypeError, lambda: nanops._ensure_numeric('foo'))
        pytest.raises(TypeError, lambda: nanops._ensure_numeric({}))
        pytest.raises(TypeError, lambda: nanops._ensure_numeric([])) 
Example #7
Source File: test_nanops.py    From recruit with Apache License 2.0 5 votes vote down vote up
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 
Example #8
Source File: test_nanops.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
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) 
Example #9
Source File: test_nanops.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
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 
Example #10
Source File: test_nanops.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def test_non_convertable_values(self):
        pytest.raises(TypeError, lambda: nanops._ensure_numeric('foo'))
        pytest.raises(TypeError, lambda: nanops._ensure_numeric({}))
        pytest.raises(TypeError, lambda: nanops._ensure_numeric([])) 
Example #11
Source File: test_nanops.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #12
Source File: test_nanops.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #13
Source File: test_nanops.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_non_convertable_values(self):
        pytest.raises(TypeError, lambda: nanops._ensure_numeric('foo'))
        pytest.raises(TypeError, lambda: nanops._ensure_numeric({}))
        pytest.raises(TypeError, lambda: nanops._ensure_numeric([])) 
Example #14
Source File: test_nanops.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
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) 
Example #15
Source File: test_nanops.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
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 
Example #16
Source File: test_nanops.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_non_convertable_values(self):
        pytest.raises(TypeError, lambda: nanops._ensure_numeric('foo'))
        pytest.raises(TypeError, lambda: nanops._ensure_numeric({}))
        pytest.raises(TypeError, lambda: nanops._ensure_numeric([])) 
Example #17
Source File: test_nanops.py    From vnpy_crypto with MIT License 5 votes vote down vote up
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) 
Example #18
Source File: test_nanops.py    From vnpy_crypto with MIT License 5 votes vote down vote up
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 
Example #19
Source File: test_nanops.py    From recruit with Apache License 2.0 5 votes vote down vote up
def test_non_convertable_values(self):
        pytest.raises(TypeError, lambda: nanops._ensure_numeric('foo'))
        pytest.raises(TypeError, lambda: nanops._ensure_numeric({}))
        pytest.raises(TypeError, lambda: nanops._ensure_numeric([])) 
Example #20
Source File: test_nanops.py    From recruit with Apache License 2.0 5 votes vote down vote up
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)