Esempio n. 1
0
    def testSeriesQuantileExecution(self):
        raw = pd.Series(np.random.rand(10), name='a')
        a = Series(raw, chunk_size=3)

        # q = 0.5, scalar
        r = a.quantile()
        result = self.executor.execute_dataframe(r, concat=True)[0]
        expected = raw.quantile()

        self.assertEqual(result, expected)

        # q is a list
        r = a.quantile([0.3, 0.7])
        result = self.executor.execute_dataframe(r, concat=True)[0]
        expected = raw.quantile([0.3, 0.7])

        pd.testing.assert_series_equal(result, expected)

        # test interpolation
        r = a.quantile([0.3, 0.7], interpolation='midpoint')
        result = self.executor.execute_dataframe(r, concat=True)[0]
        expected = raw.quantile([0.3, 0.7], interpolation='midpoint')

        pd.testing.assert_series_equal(result, expected)

        ctx, executor = self._create_test_context(self.executor)
        with ctx:
            q = tensor([0.3, 0.7])

            # q is a tensor
            r = a.quantile(q)
            result = executor.execute_dataframes([r])[0]
            expected = raw.quantile([0.3, 0.7])

            pd.testing.assert_series_equal(result, expected)
Esempio n. 2
0
def test_series_quantile_execution(setup):
    raw = pd.Series(np.random.rand(10), name='a')
    a = Series(raw, chunk_size=3)

    # q = 0.5, scalar
    r = a.quantile()
    result = r.execute().fetch()
    expected = raw.quantile()

    assert result == expected

    # q is a list
    r = a.quantile([0.3, 0.7])
    result = r.execute().fetch()
    expected = raw.quantile([0.3, 0.7])

    pd.testing.assert_series_equal(result, expected)

    # test interpolation
    r = a.quantile([0.3, 0.7], interpolation='midpoint')
    result = r.execute().fetch()
    expected = raw.quantile([0.3, 0.7], interpolation='midpoint')

    pd.testing.assert_series_equal(result, expected)

    q = tensor([0.3, 0.7])

    # q is a tensor
    r = a.quantile(q)
    result = r.execute().fetch()
    expected = raw.quantile([0.3, 0.7])

    pd.testing.assert_series_equal(result, expected)
Esempio n. 3
0
    def testSeriesQuantileExecution(self):
        raw = pd.Series(np.random.rand(10), name='a')
        a = Series(raw, chunk_size=3)

        # q = 0.5, scalar
        r = a.quantile()
        result = self.executor.execute_dataframe(r, concat=True)[0]
        expected = raw.quantile()

        self.assertEqual(result, expected)

        # q is a list
        r = a.quantile([0.3, 0.7])
        result = self.executor.execute_dataframe(r, concat=True)[0]
        expected = raw.quantile([0.3, 0.7])

        pd.testing.assert_series_equal(result, expected)

        # test interpolation
        r = a.quantile([0.3, 0.7], interpolation='midpoint')
        result = self.executor.execute_dataframe(r, concat=True)[0]
        expected = raw.quantile([0.3, 0.7], interpolation='midpoint')

        pd.testing.assert_series_equal(result, expected)

        this = self

        class MockSession:
            def __init__(self):
                self.executor = this.executor

        ctx = LocalContext(MockSession())
        executor = ExecutorForTest('numpy', storage=ctx)
        with ctx:
            q = tensor([0.3, 0.7])

            # q is a tensor
            r = a.quantile(q)
            result = executor.execute_dataframes([r])[0]
            expected = raw.quantile([0.3, 0.7])

            pd.testing.assert_series_equal(result, expected)