예제 #1
0
    def test_multi_ts(self):

        series1 = constant_timeseries(0., 3)
        series2 = constant_timeseries(1., 3)

        data = [series1, series2]

        mapper1 = InvertibleMapper(fn=lambda x: x + 10,
                                   inverse_fn=lambda x: x - 10)
        mapper2 = InvertibleMapper(fn=lambda x: x * 10,
                                   inverse_fn=lambda x: x / 10)

        transformers = [mapper1, mapper2]
        p = Pipeline(transformers)

        # when
        transformed = p.transform(data)
        back = p.inverse_transform(transformed)

        # then
        self.assertEqual(data, back)
예제 #2
0
    def test_pipeline_n_jobs(self):
        """
        Checks if the n_jobs param applied to the pipeline is changing the verbosity level in the
        contained transformers.
        """
        def plus_ten(x):
            return x + 10

        mapper = Mapper(fn=plus_ten, n_jobs=1)
        mapper_inv = InvertibleMapper(fn=lambda x: x + 2,
                                      inverse_fn=lambda x: x - 2,
                                      n_jobs=2)

        n_jobs_value = -1
        pipeline = Pipeline([mapper, mapper_inv], n_jobs=n_jobs_value)

        for transformer in pipeline:
            self.assertEqual(transformer._n_jobs, n_jobs_value)
예제 #3
0
    def test_pipeline_verbose(self):
        """
        Checks if the verbose param applied to the pipeline is changing the verbosity level in the 
        contained transformers.
        """
        def plus_ten(x):
            return x + 10

        mapper = Mapper(fn=plus_ten, verbose=True)
        mapper_inv = InvertibleMapper(fn=lambda x: x + 2,
                                      inverse_fn=lambda x: x - 2,
                                      verbose=True)

        verbose_value = False
        pipeline = Pipeline([mapper, mapper_inv], verbose=verbose_value)

        for transformer in pipeline:
            self.assertEqual(transformer._verbose, verbose_value)
예제 #4
0
    def test_pipeline_partial_inverse(self):
        series = constant_timeseries(0., 3)

        def plus_ten(x):
            return x + 10

        mapper = Mapper(fn=plus_ten)
        mapper_inv = InvertibleMapper(fn=lambda x: x + 2,
                                      inverse_fn=lambda x: x - 2)

        series_plus_ten = mapper.transform(series)

        pipeline = Pipeline([mapper, mapper_inv])

        transformed = pipeline.transform(series)

        # should fail, since partial is False by default
        with self.assertRaises(ValueError):
            pipeline.inverse_transform(transformed)

        back = pipeline.inverse_transform(transformed, partial=True)

        # while the +/- 2 is inverted, the +10 operation is not
        self.assertEqual(series_plus_ten, back)