Exemple #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
        assert_almost_equal(res.values.squeeze(), expected)
        assert res.index[0] == start
        assert res.index[-1] == end

        res = convolution_filter(x, [.75, .5, .3, .2, .1], nsides=1)
        expected = self.expected.conv1_odd
        assert_almost_equal(res.values.squeeze(), expected)
        assert res.index[0] == start
        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
        assert_almost_equal(res.values.squeeze(), expected, 4)
        assert res.index[0] == start
        assert res.index[-1] == end
Exemple #2
0
 def test_pandas2d(self):
     start = datetime(1951, 3, 31)
     end = datetime(1958, 12, 31)
     x = pd.concat((self.data[0], self.data[0]), axis=1)
     res = convolution_filter(x, [[.75, .75], [.25, .25]])
     assert res.index[0] == start
     assert res.index[-1] == end
Exemple #3
0
    def test_convolution(self):
        x = self.data.values.squeeze()
        res = convolution_filter(x, [.75, .25])
        expected = self.expected.conv2
        assert_almost_equal(res, expected)

        res = convolution_filter(x, [.75, .25], nsides=1)
        expected = self.expected.conv1
        assert_almost_equal(res, expected)

        x = self.datana.values.squeeze()
        res = convolution_filter(x, [.75, .25])
        expected = self.expected.conv2_na
        assert_almost_equal(res, expected)

        res = convolution_filter(x, [.75, .25], nsides=1)
        expected = self.expected.conv1_na
        assert_almost_equal(res, expected)
Exemple #4
0
    def test_convolution2d(self):
        x = self.data.values
        res = convolution_filter(x, [[.75], [.25]])
        expected = self.expected.conv2
        assert_almost_equal(res, expected[:, None])
        res = convolution_filter(np.c_[x, x], [[.75, .75], [.25, .25]])
        assert_almost_equal(res, np.c_[expected, expected])

        res = convolution_filter(x, [[.75], [.25]], nsides=1)
        expected = self.expected.conv1
        assert_almost_equal(res, expected[:, None])

        x = self.datana.values
        res = convolution_filter(x, [[.75], [.25]])
        expected = self.expected.conv2_na
        assert_almost_equal(res, expected[:, None])

        res = convolution_filter(x, [[.75], [.25]], nsides=1)
        expected = self.expected.conv1_na
        assert_almost_equal(res, expected[:, None])
Exemple #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