Python pandas.core.nanops.nansum() Examples

The following are 24 code examples of pandas.core.nanops.nansum(). 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 Project: recruit   Author: Frank-qlu   File: test_apply.py    License: Apache License 2.0 6 votes vote down vote up
def test_apply(frame):
    applied = frame.apply(np.sqrt)
    assert isinstance(applied, SparseDataFrame)
    tm.assert_almost_equal(applied.values, np.sqrt(frame.values))

    # agg / broadcast
    with tm.assert_produces_warning(FutureWarning):
        broadcasted = frame.apply(np.sum, broadcast=True)
    assert isinstance(broadcasted, SparseDataFrame)

    with tm.assert_produces_warning(FutureWarning):
        exp = frame.to_dense().apply(np.sum, broadcast=True)
    tm.assert_frame_equal(broadcasted.to_dense(), exp)

    applied = frame.apply(np.sum)
    tm.assert_series_equal(applied,
                           frame.to_dense().apply(nanops.nansum).to_sparse()) 
Example #2
Source Project: recruit   Author: Frank-qlu   File: test_reductions.py    License: Apache License 2.0 6 votes vote down vote up
def test_sum_inf(self):
        s = Series(np.random.randn(10))
        s2 = s.copy()

        s[5:8] = np.inf
        s2[5:8] = np.nan

        assert np.isinf(s.sum())

        arr = np.random.randn(100, 100).astype('f4')
        arr[:, 2] = np.inf

        with pd.option_context("mode.use_inf_as_na", True):
            tm.assert_almost_equal(s.sum(), s2.sum())

        res = nanops.nansum(arr, axis=1)
        assert np.isinf(res).all() 
Example #3
Source Project: vnpy_crypto   Author: birforce   File: test_apply.py    License: MIT License 6 votes vote down vote up
def test_apply(frame):
    applied = frame.apply(np.sqrt)
    assert isinstance(applied, SparseDataFrame)
    tm.assert_almost_equal(applied.values, np.sqrt(frame.values))

    # agg / broadcast
    with tm.assert_produces_warning(FutureWarning):
        broadcasted = frame.apply(np.sum, broadcast=True)
    assert isinstance(broadcasted, SparseDataFrame)

    with tm.assert_produces_warning(FutureWarning):
        exp = frame.to_dense().apply(np.sum, broadcast=True)
    tm.assert_frame_equal(broadcasted.to_dense(), exp)

    applied = frame.apply(np.sum)
    tm.assert_series_equal(applied,
                           frame.to_dense().apply(nanops.nansum)) 
Example #4
Source Project: vnpy_crypto   Author: birforce   File: test_analytics.py    License: MIT License 6 votes vote down vote up
def test_sum_inf(self):
        s = Series(np.random.randn(10))
        s2 = s.copy()

        s[5:8] = np.inf
        s2[5:8] = np.nan

        assert np.isinf(s.sum())

        arr = np.random.randn(100, 100).astype('f4')
        arr[:, 2] = np.inf

        with pd.option_context("mode.use_inf_as_na", True):
            assert_almost_equal(s.sum(), s2.sum())

        res = nanops.nansum(arr, axis=1)
        assert np.isinf(res).all() 
Example #5
Source Project: Computable   Author: ktraunmueller   File: test_sparse.py    License: MIT License 6 votes vote down vote up
def test_apply(self):
        applied = self.frame.apply(np.sqrt)
        tm.assert_isinstance(applied, SparseDataFrame)
        assert_almost_equal(applied.values, np.sqrt(self.frame.values))

        applied = self.fill_frame.apply(np.sqrt)
        self.assert_(applied['A'].fill_value == np.sqrt(2))

        # agg / broadcast
        broadcasted = self.frame.apply(np.sum, broadcast=True)
        tm.assert_isinstance(broadcasted, SparseDataFrame)
        assert_frame_equal(broadcasted.to_dense(),
                           self.frame.to_dense().apply(np.sum, broadcast=True))

        self.assert_(self.empty.apply(np.sqrt) is self.empty)

        from pandas.core import nanops
        applied = self.frame.apply(np.sum)
        assert_series_equal(applied,
                            self.frame.to_dense().apply(nanops.nansum)) 
Example #6
Source Project: predictive-maintenance-using-machine-learning   Author: awslabs   File: test_apply.py    License: Apache License 2.0 6 votes vote down vote up
def test_apply(frame):
    applied = frame.apply(np.sqrt)
    assert isinstance(applied, SparseDataFrame)
    tm.assert_almost_equal(applied.values, np.sqrt(frame.values))

    # agg / broadcast
    with tm.assert_produces_warning(FutureWarning):
        broadcasted = frame.apply(np.sum, broadcast=True)
    assert isinstance(broadcasted, SparseDataFrame)

    with tm.assert_produces_warning(FutureWarning):
        exp = frame.to_dense().apply(np.sum, broadcast=True)
    tm.assert_frame_equal(broadcasted.to_dense(), exp)

    applied = frame.apply(np.sum)
    tm.assert_series_equal(applied,
                           frame.to_dense().apply(nanops.nansum).to_sparse()) 
Example #7
Source Project: predictive-maintenance-using-machine-learning   Author: awslabs   File: test_reductions.py    License: Apache License 2.0 6 votes vote down vote up
def test_sum_inf(self):
        s = Series(np.random.randn(10))
        s2 = s.copy()

        s[5:8] = np.inf
        s2[5:8] = np.nan

        assert np.isinf(s.sum())

        arr = np.random.randn(100, 100).astype('f4')
        arr[:, 2] = np.inf

        with pd.option_context("mode.use_inf_as_na", True):
            tm.assert_almost_equal(s.sum(), s2.sum())

        res = nanops.nansum(arr, axis=1)
        assert np.isinf(res).all() 
Example #8
Source Project: elasticintel   Author: securityclippy   File: test_frame.py    License: GNU General Public License v3.0 6 votes vote down vote up
def test_apply(self):
        applied = self.frame.apply(np.sqrt)
        assert isinstance(applied, SparseDataFrame)
        tm.assert_almost_equal(applied.values, np.sqrt(self.frame.values))

        applied = self.fill_frame.apply(np.sqrt)
        assert applied['A'].fill_value == np.sqrt(2)

        # agg / broadcast
        broadcasted = self.frame.apply(np.sum, broadcast=True)
        assert isinstance(broadcasted, SparseDataFrame)

        exp = self.frame.to_dense().apply(np.sum, broadcast=True)
        tm.assert_frame_equal(broadcasted.to_dense(), exp)

        assert self.empty.apply(np.sqrt) is self.empty

        from pandas.core import nanops
        applied = self.frame.apply(np.sum)
        tm.assert_series_equal(applied,
                               self.frame.to_dense().apply(nanops.nansum)) 
Example #9
Source Project: elasticintel   Author: securityclippy   File: test_analytics.py    License: GNU General Public License v3.0 6 votes vote down vote up
def test_sum_inf(self):
        s = Series(np.random.randn(10))
        s2 = s.copy()

        s[5:8] = np.inf
        s2[5:8] = np.nan

        assert np.isinf(s.sum())

        arr = np.random.randn(100, 100).astype('f4')
        arr[:, 2] = np.inf

        with pd.option_context("mode.use_inf_as_na", True):
            assert_almost_equal(s.sum(), s2.sum())

        res = nanops.nansum(arr, axis=1)
        assert np.isinf(res).all() 
Example #10
Source Project: coffeegrindsize   Author: jgagneastro   File: test_apply.py    License: MIT License 6 votes vote down vote up
def test_apply(frame):
    applied = frame.apply(np.sqrt)
    assert isinstance(applied, SparseDataFrame)
    tm.assert_almost_equal(applied.values, np.sqrt(frame.values))

    # agg / broadcast
    with tm.assert_produces_warning(FutureWarning):
        broadcasted = frame.apply(np.sum, broadcast=True)
    assert isinstance(broadcasted, SparseDataFrame)

    with tm.assert_produces_warning(FutureWarning):
        exp = frame.to_dense().apply(np.sum, broadcast=True)
    tm.assert_frame_equal(broadcasted.to_dense(), exp)

    applied = frame.apply(np.sum)
    tm.assert_series_equal(applied,
                           frame.to_dense().apply(nanops.nansum).to_sparse()) 
Example #11
Source Project: twitter-stock-recommendation   Author: alvarobartt   File: test_apply.py    License: MIT License 6 votes vote down vote up
def test_apply(frame):
    applied = frame.apply(np.sqrt)
    assert isinstance(applied, SparseDataFrame)
    tm.assert_almost_equal(applied.values, np.sqrt(frame.values))

    # agg / broadcast
    with tm.assert_produces_warning(FutureWarning):
        broadcasted = frame.apply(np.sum, broadcast=True)
    assert isinstance(broadcasted, SparseDataFrame)

    with tm.assert_produces_warning(FutureWarning):
        exp = frame.to_dense().apply(np.sum, broadcast=True)
    tm.assert_frame_equal(broadcasted.to_dense(), exp)

    applied = frame.apply(np.sum)
    tm.assert_series_equal(applied,
                           frame.to_dense().apply(nanops.nansum)) 
Example #12
Source Project: twitter-stock-recommendation   Author: alvarobartt   File: test_analytics.py    License: MIT License 6 votes vote down vote up
def test_sum_inf(self):
        s = Series(np.random.randn(10))
        s2 = s.copy()

        s[5:8] = np.inf
        s2[5:8] = np.nan

        assert np.isinf(s.sum())

        arr = np.random.randn(100, 100).astype('f4')
        arr[:, 2] = np.inf

        with pd.option_context("mode.use_inf_as_na", True):
            assert_almost_equal(s.sum(), s2.sum())

        res = nanops.nansum(arr, axis=1)
        assert np.isinf(res).all() 
Example #13
Source Project: recruit   Author: Frank-qlu   File: test_nanops.py    License: Apache License 2.0 5 votes vote down vote up
def test_nansum(self):
        self.check_funs(nanops.nansum, np.sum, allow_str=False,
                        allow_date=False, allow_tdelta=True, check_dtype=False,
                        empty_targfunc=np.nansum) 
Example #14
Source Project: recruit   Author: Frank-qlu   File: test_reductions.py    License: Apache License 2.0 5 votes vote down vote up
def test_nansum_buglet(self):
        ser = Series([1.0, np.nan], index=[0, 1])
        result = np.nansum(ser)
        tm.assert_almost_equal(result, 1) 
Example #15
Source Project: recruit   Author: Frank-qlu   File: numpy_.py    License: Apache License 2.0 5 votes vote down vote up
def sum(self, axis=None, dtype=None, out=None, keepdims=False,
            initial=None, skipna=True, min_count=0):
        nv.validate_sum((), dict(dtype=dtype, out=out, keepdims=keepdims,
                                 initial=initial))
        return nanops.nansum(self._ndarray, axis=axis, skipna=skipna,
                             min_count=min_count) 
Example #16
Source Project: vnpy_crypto   Author: birforce   File: test_nanops.py    License: MIT License 5 votes vote down vote up
def test_nansum(self):
        self.check_funs(nanops.nansum, np.sum, allow_str=False,
                        allow_date=False, allow_tdelta=True, check_dtype=False,
                        empty_targfunc=np.nansum) 
Example #17
Source Project: vnpy_crypto   Author: birforce   File: test_analytics.py    License: MIT License 5 votes vote down vote up
def test_nansum_buglet(self):
        s = Series([1.0, np.nan], index=[0, 1])
        result = np.nansum(s)
        assert_almost_equal(result, 1) 
Example #18
Source Project: predictive-maintenance-using-machine-learning   Author: awslabs   File: test_nanops.py    License: Apache License 2.0 5 votes vote down vote up
def test_nansum(self):
        self.check_funs(nanops.nansum, np.sum, allow_str=False,
                        allow_date=False, allow_tdelta=True, check_dtype=False,
                        empty_targfunc=np.nansum) 
Example #19
Source Project: predictive-maintenance-using-machine-learning   Author: awslabs   File: test_reductions.py    License: Apache License 2.0 5 votes vote down vote up
def test_nansum_buglet(self):
        ser = Series([1.0, np.nan], index=[0, 1])
        result = np.nansum(ser)
        tm.assert_almost_equal(result, 1) 
Example #20
Source Project: predictive-maintenance-using-machine-learning   Author: awslabs   File: numpy_.py    License: Apache License 2.0 5 votes vote down vote up
def sum(self, axis=None, dtype=None, out=None, keepdims=False,
            initial=None, skipna=True, min_count=0):
        nv.validate_sum((), dict(dtype=dtype, out=out, keepdims=keepdims,
                                 initial=initial))
        return nanops.nansum(self._ndarray, axis=axis, skipna=skipna,
                             min_count=min_count) 
Example #21
Source Project: elasticintel   Author: securityclippy   File: test_nanops.py    License: GNU General Public License v3.0 5 votes vote down vote up
def test_nansum(self):
        self.check_funs(nanops.nansum, np.sum, allow_str=False,
                        allow_date=False, allow_tdelta=True, check_dtype=False) 
Example #22
Source Project: elasticintel   Author: securityclippy   File: test_analytics.py    License: GNU General Public License v3.0 5 votes vote down vote up
def test_nansum_buglet(self):
        s = Series([1.0, np.nan], index=[0, 1])
        result = np.nansum(s)
        assert_almost_equal(result, 1) 
Example #23
Source Project: twitter-stock-recommendation   Author: alvarobartt   File: test_nanops.py    License: MIT License 5 votes vote down vote up
def test_nansum(self):
        self.check_funs(nanops.nansum, np.sum, allow_str=False,
                        allow_date=False, allow_tdelta=True, check_dtype=False,
                        empty_targfunc=np.nansum) 
Example #24
Source Project: twitter-stock-recommendation   Author: alvarobartt   File: test_analytics.py    License: MIT License 5 votes vote down vote up
def test_nansum_buglet(self):
        s = Series([1.0, np.nan], index=[0, 1])
        result = np.nansum(s)
        assert_almost_equal(result, 1)