コード例 #1
0
    def test_window_size_timedelta(self):
        """window_size accepts Timedelta object."""
        # setup
        X = self.X
        timeseries = self.timeseries

        # run
        array = cutoff_window_sequences(
            X,
            timeseries,
            window_size=pd.Timedelta(days=3),
        )

        # assert
        expected_array = np.array([[[2, 22], [3, 23], [4, 24]],
                                   [[14, 34], [15, 35], [16, 36]]])

        assert_allclose(array, expected_array)
コード例 #2
0
    def test_window_size_string(self):
        """window_size accepts string."""
        # setup
        X = self.X
        timeseries = self.timeseries

        # run
        array = cutoff_window_sequences(
            X,
            timeseries,
            window_size='3d',
        )

        # assert
        expected_array = np.array([[[2, 22], [3, 23], [4, 24]],
                                   [[14, 34], [15, 35], [16, 36]]])

        assert_allclose(array, expected_array)
コード例 #3
0
    def test_multiple_filter(self):
        """Test X with two identifier columns."""
        # setup
        X = self.X
        X['id2'] = [3, 4]
        timeseries = self.timeseries
        timeseries['id2'] = [3, 4] * 10

        # run
        array = cutoff_window_sequences(
            X,
            timeseries,
            window_size=2,
        )

        # assert
        expected_array = np.array([[[1, 21], [3, 23]], [[14, 34], [16, 36]]])

        assert_allclose(array, expected_array)
コード例 #4
0
    def test_time_index_column(self):
        """Passing time_index. The indicated column will be used as the timeseries index."""
        # setup
        X = self.X
        timeseries = self.timeseries.reset_index()

        # run
        array = cutoff_window_sequences(
            X,
            timeseries,
            window_size=3,
            time_index='timestamp',
        )

        # assert
        expected_array = np.array([[[2, 22], [3, 23], [4, 24]],
                                   [[14, 34], [15, 35], [16, 36]]])

        assert_allclose(array, expected_array)
コード例 #5
0
    def test_cutoff_time_only(self):
        """Test X without any other column than cutoff_time."""
        # setup
        X = self.X
        del X['id1']
        timeseries = self.timeseries
        del timeseries['id1']

        # run
        array = cutoff_window_sequences(
            X,
            timeseries,
            window_size=3,
        )

        # assert
        expected_array = np.array([[[12, 32], [13, 33], [14, 34]],
                                   [[14, 34], [15, 35], [16, 36]]])

        assert_allclose(array, expected_array)
コード例 #6
0
    def test_not_enough_data(self):
        """If there is not enough data for the given window_size, shape changes."""
        # setup
        X = self.X
        timeseries = self.timeseries

        # run
        array = cutoff_window_sequences(
            X,
            timeseries,
            window_size=5,
        )

        # assert
        assert len(array) == 2

        expected_array = np.array([
            np.array([[1, 21], [2, 22], [3, 23], [4, 24]]),
            np.array([[12, 32], [13, 33], [14, 34], [15, 35], [16, 36]])
        ])

        assert_allclose(array[0], expected_array[0])

        assert_allclose(array[1], expected_array[1])