Exemplo n.º 1
0
def test_series_corr(setup):
    rs = np.random.RandomState(0)
    raw = rs.rand(20)
    raw = pd.Series(np.where(raw > 0.4, raw, np.nan))
    raw2 = rs.rand(20)
    raw2 = pd.Series(np.where(raw2 > 0.4, raw2, np.nan))

    s = Series(raw)
    s2 = Series(raw2)

    result = s.corr(s2)
    assert result.execute().fetch() == raw.corr(raw2)

    result = s.corr(s2, method='kendall')
    assert result.execute().fetch() == raw.corr(raw2, method='kendall')

    result = s.autocorr(2)
    assert result.execute().fetch() == raw.autocorr(2)

    s = Series(raw, chunk_size=6)
    s2 = Series(raw2, chunk_size=4)

    with pytest.raises(Exception):
        s.corr(s2, method='kendall').execute()

    result = s.corr(s2)
    assert pytest.approx(result.execute().fetch()) == raw.corr(raw2)

    result = s.corr(s2, min_periods=7)
    assert pytest.approx(result.execute().fetch()) == raw.corr(raw2,
                                                               min_periods=7)

    result = s.autocorr(2)
    assert pytest.approx(result.execute().fetch()) == raw.autocorr(2)
Exemplo n.º 2
0
    def testSeriesCorr(self):
        rs = np.random.RandomState(0)
        raw = rs.rand(20)
        raw = pd.Series(np.where(raw > 0.4, raw, np.nan))
        raw2 = rs.rand(20)
        raw2 = pd.Series(np.where(raw2 > 0.4, raw2, np.nan))

        s = Series(raw)
        s2 = Series(raw2)

        result = s.corr(s2)
        self.assertEqual(
            self.executor.execute_dataframe(result, concat=True)[0],
            raw.corr(raw2))

        result = s.corr(s2, method='kendall')
        self.assertEqual(
            self.executor.execute_dataframe(result, concat=True)[0],
            raw.corr(raw2, method='kendall'))

        result = s.autocorr(2)
        self.assertEqual(
            self.executor.execute_dataframe(result, concat=True)[0],
            raw.autocorr(2))

        s = Series(raw, chunk_size=6)
        s2 = Series(raw2, chunk_size=4)

        with self.assertRaises(Exception):
            self.executor.execute_dataframe(s.corr(s2, method='kendall'),
                                            concat=True)

        result = s.corr(s2)
        self.assertAlmostEqual(
            self.executor.execute_dataframe(result, concat=True)[0],
            raw.corr(raw2))

        result = s.corr(s2, min_periods=7)
        self.assertAlmostEqual(
            self.executor.execute_dataframe(result, concat=True)[0],
            raw.corr(raw2, min_periods=7))

        result = s.autocorr(2)
        self.assertAlmostEqual(
            self.executor.execute_dataframe(result, concat=True)[0],
            raw.autocorr(2))