Python pandas.core.nanops.nanstd() Examples

The following are 17 code examples of pandas.core.nanops.nanstd(). 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 predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_nanstd_nans(self):
        samples = np.nan * np.ones(2 * self.samples.shape[0])
        samples[::2] = self.samples

        actual_std = nanops.nanstd(samples, skipna=True)
        tm.assert_almost_equal(actual_std, self.variance ** 0.5,
                               check_less_precise=2)

        actual_std = nanops.nanvar(samples, skipna=False)
        tm.assert_almost_equal(actual_std, np.nan,
                               check_less_precise=2) 
Example #2
Source File: test_nanops.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_ground_truth(self):
        # Test against values that were precomputed with Numpy.
        samples = np.empty((4, 4))
        samples[:3, :3] = np.array([[0.97303362, 0.21869576, 0.55560287
                                     ], [0.72980153, 0.03109364, 0.99155171],
                                    [0.09317602, 0.60078248, 0.15871292]])
        samples[3] = samples[:, 3] = np.nan

        # Actual variances along axis=0, 1 for ddof=0, 1, 2
        variance = np.array([[[0.13762259, 0.05619224, 0.11568816
                               ], [0.20643388, 0.08428837, 0.17353224],
                              [0.41286776, 0.16857673, 0.34706449]],
                             [[0.09519783, 0.16435395, 0.05082054
                               ], [0.14279674, 0.24653093, 0.07623082],
                              [0.28559348, 0.49306186, 0.15246163]]])

        # Test nanvar.
        for axis in range(2):
            for ddof in range(3):
                var = nanops.nanvar(samples, skipna=True, axis=axis, ddof=ddof)
                tm.assert_almost_equal(var[:3], variance[axis, ddof])
                assert np.isnan(var[3])

        # Test nanstd.
        for axis in range(2):
            for ddof in range(3):
                std = nanops.nanstd(samples, skipna=True, axis=axis, ddof=ddof)
                tm.assert_almost_equal(std[:3], variance[axis, ddof] ** 0.5)
                assert np.isnan(std[3]) 
Example #3
Source File: test_nanops.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_nanstd_nans(self):
        samples = np.nan * np.ones(2 * self.samples.shape[0])
        samples[::2] = self.samples

        actual_std = nanops.nanstd(samples, skipna=True)
        tm.assert_almost_equal(actual_std, self.variance ** 0.5,
                               check_less_precise=2)

        actual_std = nanops.nanvar(samples, skipna=False)
        tm.assert_almost_equal(actual_std, np.nan,
                               check_less_precise=2) 
Example #4
Source File: test_nanops.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_nanstd(self, ddof):
        self.check_funs(nanops.nanstd, np.std, allow_complex=False,
                        allow_str=False, allow_date=False,
                        allow_tdelta=True, allow_obj='convert', ddof=ddof) 
Example #5
Source File: test_nanops.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def test_ground_truth(self):
        # Test against values that were precomputed with Numpy.
        samples = np.empty((4, 4))
        samples[:3, :3] = np.array([[0.97303362, 0.21869576, 0.55560287
                                     ], [0.72980153, 0.03109364, 0.99155171],
                                    [0.09317602, 0.60078248, 0.15871292]])
        samples[3] = samples[:, 3] = np.nan

        # Actual variances along axis=0, 1 for ddof=0, 1, 2
        variance = np.array([[[0.13762259, 0.05619224, 0.11568816
                               ], [0.20643388, 0.08428837, 0.17353224],
                              [0.41286776, 0.16857673, 0.34706449]],
                             [[0.09519783, 0.16435395, 0.05082054
                               ], [0.14279674, 0.24653093, 0.07623082],
                              [0.28559348, 0.49306186, 0.15246163]]])

        # Test nanvar.
        for axis in range(2):
            for ddof in range(3):
                var = nanops.nanvar(samples, skipna=True, axis=axis, ddof=ddof)
                tm.assert_almost_equal(var[:3], variance[axis, ddof])
                assert np.isnan(var[3])

        # Test nanstd.
        for axis in range(2):
            for ddof in range(3):
                std = nanops.nanstd(samples, skipna=True, axis=axis, ddof=ddof)
                tm.assert_almost_equal(std[:3], variance[axis, ddof] ** 0.5)
                assert np.isnan(std[3]) 
Example #6
Source File: test_nanops.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def test_nanstd_nans(self):
        samples = np.nan * np.ones(2 * self.samples.shape[0])
        samples[::2] = self.samples

        actual_std = nanops.nanstd(samples, skipna=True)
        tm.assert_almost_equal(actual_std, self.variance ** 0.5,
                               check_less_precise=2)

        actual_std = nanops.nanvar(samples, skipna=False)
        tm.assert_almost_equal(actual_std, np.nan,
                               check_less_precise=2) 
Example #7
Source File: test_nanops.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def test_nanstd(self):
        self.check_funs_ddof(nanops.nanstd, np.std, allow_complex=False,
                             allow_str=False, allow_date=False,
                             allow_tdelta=True, allow_obj='convert') 
Example #8
Source File: numpy_.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def std(self, axis=None, dtype=None, out=None, ddof=1, keepdims=False,
            skipna=True):
        nv.validate_stat_ddof_func((), dict(dtype=dtype, out=out,
                                            keepdims=keepdims),
                                   fname='std')
        return nanops.nanstd(self._ndarray, axis=axis, skipna=skipna,
                             ddof=ddof) 
Example #9
Source File: test_nanops.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_ground_truth(self):
        # Test against values that were precomputed with Numpy.
        samples = np.empty((4, 4))
        samples[:3, :3] = np.array([[0.97303362, 0.21869576, 0.55560287
                                     ], [0.72980153, 0.03109364, 0.99155171],
                                    [0.09317602, 0.60078248, 0.15871292]])
        samples[3] = samples[:, 3] = np.nan

        # Actual variances along axis=0, 1 for ddof=0, 1, 2
        variance = np.array([[[0.13762259, 0.05619224, 0.11568816
                               ], [0.20643388, 0.08428837, 0.17353224],
                              [0.41286776, 0.16857673, 0.34706449]],
                             [[0.09519783, 0.16435395, 0.05082054
                               ], [0.14279674, 0.24653093, 0.07623082],
                              [0.28559348, 0.49306186, 0.15246163]]])

        # Test nanvar.
        for axis in range(2):
            for ddof in range(3):
                var = nanops.nanvar(samples, skipna=True, axis=axis, ddof=ddof)
                tm.assert_almost_equal(var[:3], variance[axis, ddof])
                assert np.isnan(var[3])

        # Test nanstd.
        for axis in range(2):
            for ddof in range(3):
                std = nanops.nanstd(samples, skipna=True, axis=axis, ddof=ddof)
                tm.assert_almost_equal(std[:3], variance[axis, ddof] ** 0.5)
                assert np.isnan(std[3]) 
Example #10
Source File: test_nanops.py    From recruit with Apache License 2.0 5 votes vote down vote up
def test_nanstd(self, ddof):
        self.check_funs(nanops.nanstd, np.std, allow_complex=False,
                        allow_str=False, allow_date=False,
                        allow_tdelta=True, allow_obj='convert', ddof=ddof) 
Example #11
Source File: test_nanops.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_nanstd(self, ddof):
        self.check_funs(nanops.nanstd, np.std, allow_complex=False,
                        allow_str=False, allow_date=False,
                        allow_tdelta=True, allow_obj='convert', ddof=ddof) 
Example #12
Source File: test_nanops.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_ground_truth(self):
        # Test against values that were precomputed with Numpy.
        samples = np.empty((4, 4))
        samples[:3, :3] = np.array([[0.97303362, 0.21869576, 0.55560287
                                     ], [0.72980153, 0.03109364, 0.99155171],
                                    [0.09317602, 0.60078248, 0.15871292]])
        samples[3] = samples[:, 3] = np.nan

        # Actual variances along axis=0, 1 for ddof=0, 1, 2
        variance = np.array([[[0.13762259, 0.05619224, 0.11568816
                               ], [0.20643388, 0.08428837, 0.17353224],
                              [0.41286776, 0.16857673, 0.34706449]],
                             [[0.09519783, 0.16435395, 0.05082054
                               ], [0.14279674, 0.24653093, 0.07623082],
                              [0.28559348, 0.49306186, 0.15246163]]])

        # Test nanvar.
        for axis in range(2):
            for ddof in range(3):
                var = nanops.nanvar(samples, skipna=True, axis=axis, ddof=ddof)
                tm.assert_almost_equal(var[:3], variance[axis, ddof])
                assert np.isnan(var[3])

        # Test nanstd.
        for axis in range(2):
            for ddof in range(3):
                std = nanops.nanstd(samples, skipna=True, axis=axis, ddof=ddof)
                tm.assert_almost_equal(std[:3], variance[axis, ddof] ** 0.5)
                assert np.isnan(std[3]) 
Example #13
Source File: test_nanops.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_nanstd_nans(self):
        samples = np.nan * np.ones(2 * self.samples.shape[0])
        samples[::2] = self.samples

        actual_std = nanops.nanstd(samples, skipna=True)
        tm.assert_almost_equal(actual_std, self.variance ** 0.5,
                               check_less_precise=2)

        actual_std = nanops.nanvar(samples, skipna=False)
        tm.assert_almost_equal(actual_std, np.nan,
                               check_less_precise=2) 
Example #14
Source File: test_nanops.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_nanstd(self, ddof):
        self.check_funs(nanops.nanstd, np.std, allow_complex=False,
                        allow_str=False, allow_date=False,
                        allow_tdelta=True, allow_obj='convert', ddof=ddof) 
Example #15
Source File: numpy_.py    From recruit with Apache License 2.0 5 votes vote down vote up
def std(self, axis=None, dtype=None, out=None, ddof=1, keepdims=False,
            skipna=True):
        nv.validate_stat_ddof_func((), dict(dtype=dtype, out=out,
                                            keepdims=keepdims),
                                   fname='std')
        return nanops.nanstd(self._ndarray, axis=axis, skipna=skipna,
                             ddof=ddof) 
Example #16
Source File: test_nanops.py    From recruit with Apache License 2.0 5 votes vote down vote up
def test_ground_truth(self):
        # Test against values that were precomputed with Numpy.
        samples = np.empty((4, 4))
        samples[:3, :3] = np.array([[0.97303362, 0.21869576, 0.55560287
                                     ], [0.72980153, 0.03109364, 0.99155171],
                                    [0.09317602, 0.60078248, 0.15871292]])
        samples[3] = samples[:, 3] = np.nan

        # Actual variances along axis=0, 1 for ddof=0, 1, 2
        variance = np.array([[[0.13762259, 0.05619224, 0.11568816
                               ], [0.20643388, 0.08428837, 0.17353224],
                              [0.41286776, 0.16857673, 0.34706449]],
                             [[0.09519783, 0.16435395, 0.05082054
                               ], [0.14279674, 0.24653093, 0.07623082],
                              [0.28559348, 0.49306186, 0.15246163]]])

        # Test nanvar.
        for axis in range(2):
            for ddof in range(3):
                var = nanops.nanvar(samples, skipna=True, axis=axis, ddof=ddof)
                tm.assert_almost_equal(var[:3], variance[axis, ddof])
                assert np.isnan(var[3])

        # Test nanstd.
        for axis in range(2):
            for ddof in range(3):
                std = nanops.nanstd(samples, skipna=True, axis=axis, ddof=ddof)
                tm.assert_almost_equal(std[:3], variance[axis, ddof] ** 0.5)
                assert np.isnan(std[3]) 
Example #17
Source File: test_nanops.py    From recruit with Apache License 2.0 5 votes vote down vote up
def test_nanstd_nans(self):
        samples = np.nan * np.ones(2 * self.samples.shape[0])
        samples[::2] = self.samples

        actual_std = nanops.nanstd(samples, skipna=True)
        tm.assert_almost_equal(actual_std, self.variance ** 0.5,
                               check_less_precise=2)

        actual_std = nanops.nanvar(samples, skipna=False)
        tm.assert_almost_equal(actual_std, np.nan,
                               check_less_precise=2)