Пример #1
0
    def test_odd_length_filter(self):
        start = datetime(1951, 3, 31)
        end = datetime(1958, 12, 31)
        x = self.data[0]
        res = convolution_filter(x, [.75, .5, .3, .2, .1])
        expected = self.expected.conv2_odd
        np.testing.assert_almost_equal(res.values.squeeze(), expected)
        np.testing.assert_(res.index[0] == start)
        np.testing.assert_(res.index[-1] == end)

        res = convolution_filter(x, [.75, .5, .3, .2, .1], nsides=1)
        expected = self.expected.conv1_odd
        np.testing.assert_almost_equal(res.values.squeeze(), expected)
        np.testing.assert_(res.index[0] == start)
        np.testing.assert_(res.index[-1] == end)
        # with no NAs

        # not a stable filter
        res = recursive_filter(x, [.75, .5, .3, .2, .1], init=[150, 100,
                                                               125, 135,
                                                               145])
        expected = self.expected.recurse_odd
        # only have 12 characters in R and this blows up and gets big
        np.testing.assert_almost_equal(res.values.squeeze(), expected, 4)
        np.testing.assert_(res.index[0] == start)
        np.testing.assert_(res.index[-1] == end)
Пример #2
0
    def test_odd_length_filter(self):
        start = datetime(1951, 3, 31)
        end = datetime(1958, 12, 31)
        x = self.data[0]
        res = convolution_filter(x, [.75, .5, .3, .2, .1])
        expected = self.expected.conv2_odd
        np.testing.assert_almost_equal(res.values.squeeze(), expected)
        np.testing.assert_(res.index[0] == start)
        np.testing.assert_(res.index[-1] == end)

        res = convolution_filter(x, [.75, .5, .3, .2, .1], nsides=1)
        expected = self.expected.conv1_odd
        np.testing.assert_almost_equal(res.values.squeeze(), expected)
        np.testing.assert_(res.index[0] == start)
        np.testing.assert_(res.index[-1] == end)
        # with no NAs

        # not a stable filter
        res = recursive_filter(x, [.75, .5, .3, .2, .1], init=[150, 100,
                                                               125, 135,
                                                               145])
        expected = self.expected.recurse_odd
        # only have 12 characters in R and this blows up and gets big
        np.testing.assert_almost_equal(res.values.squeeze(), expected, 4)
        np.testing.assert_(res.index[0] == start)
        np.testing.assert_(res.index[-1] == end)
Пример #3
0
    def test_pandas(self):
        start = datetime(1951, 3, 31)
        end = datetime(1958, 12, 31)
        x = self.data[0]
        res = convolution_filter(x, [.75, .25])
        assert_(res.index[0] == start)
        assert_(res.index[-1] == end)

        res = convolution_filter(x, [.75, .25], nsides=1)
        assert_(res.index[0] == start)
        # with no nan-padding q1 if not
        assert_(res.index[-1] == end)

        res = recursive_filter(x, [.75, .25])
        assert_(res.index[0] == start)
        assert_(res.index[-1] == end)

        x = self.datana
        res = recursive_filter(x, [.75, .25])
        assert_(res.index[0] == start)
        assert_(res.index[-1] == end)
Пример #4
0
    def test_recursive(self):
        x = self.data.values.squeeze()
        res = recursive_filter(x, [.75, .25])
        expected = self.expected.recurse
        np.testing.assert_almost_equal(res, expected)

        res = recursive_filter(x, [.75, .25], init=[150, 100])
        expected = self.expected.recurse_init
        np.testing.assert_almost_equal(res, expected)

        x = self.datana.values.squeeze()
        res = recursive_filter(x, [.75, .25])
        expected = self.expected.recurse_na
        np.testing.assert_almost_equal(res, expected)

        res = recursive_filter(x, [.75, .25], init=[150, 100])
        expected = self.expected.recurse_init_na
        np.testing.assert_almost_equal(res, expected)

        assert_raises(ValueError, recursive_filter, x,
                      [.75, .25, .5], [150, 100])
Пример #5
0
    def test_pandas(self):
        start = datetime(1951, 3, 31)
        end = datetime(1958, 12, 31)
        x = self.data[0]
        res = convolution_filter(x, [.75, .25])
        assert_(res.index[0] == start)
        assert_(res.index[-1] == end)

        res = convolution_filter(x, [.75, .25], nsides=1)
        assert_(res.index[0] == start)
        # with no nan-padding q1 if not
        assert_(res.index[-1] == end)

        res = recursive_filter(x, [.75, .25])
        assert_(res.index[0] == start)
        assert_(res.index[-1] == end)

        x = self.datana
        res = recursive_filter(x, [.75, .25])
        assert_(res.index[0] == start)
        assert_(res.index[-1] == end)
Пример #6
0
    def test_recursive(self):
        x = self.data.values.squeeze()
        res = recursive_filter(x, [.75, .25])
        expected = self.expected.recurse
        np.testing.assert_almost_equal(res, expected)

        res = recursive_filter(x, [.75, .25], init=[150, 100])
        expected = self.expected.recurse_init
        np.testing.assert_almost_equal(res, expected)

        x = self.datana.values.squeeze()
        res = recursive_filter(x, [.75, .25])
        expected = self.expected.recurse_na
        np.testing.assert_almost_equal(res, expected)

        res = recursive_filter(x, [.75, .25], init=[150, 100])
        expected = self.expected.recurse_init_na
        np.testing.assert_almost_equal(res, expected)

        assert_raises(ValueError, recursive_filter, x,
                      [.75, .25, .5], [150, 100])