Example #1
0
    def test_multi_dims_time_series_and_uni(self):
        result = CSV(slicer.metrics.wins) \
            .transform(cont_uni_dim_df, slicer, [slicer.dimensions.timestamp, slicer.dimensions.state], [])

        expected = cont_uni_dim_df.copy() \
            .set_index(fd('state_display'), append=True) \
            .reset_index(fd('state'), drop=False)[[fm('wins')]]
        expected.index.names = ['Timestamp', 'State']
        expected.columns = ['Wins']

        self.assertEqual(expected.to_csv(), result)
Example #2
0
    def test_multi_dims_time_series_and_uni(self):
        result = CSV(slicer.metrics.wins) \
            .transform(cont_uni_dim_df, slicer, [slicer.dimensions.timestamp, slicer.dimensions.state], [])

        expected = cont_uni_dim_df.copy() \
            .set_index(fd('state_display'), append=True) \
            .reset_index(fd('state'), drop=False)[[fm('wins')]]
        expected.index.names = ['Timestamp', 'State']
        expected.columns = ['Wins']

        self.assertEqual(expected.to_csv(), result)
Example #3
0
    def test_pivoted_multi_dims_time_series_and_uni(self):
        result = CSV(slicer.metrics.votes, pivot=[slicer.dimensions.state]) \
            .transform(cont_uni_dim_df, slicer, [slicer.dimensions.timestamp, slicer.dimensions.state], [])

        expected = cont_uni_dim_df.copy() \
            .set_index(fd('state_display'), append=True) \
            .reset_index(fd('state'), drop=True)[[fm('votes')]]
        expected = expected.unstack(level=[1])
        expected.index.names = ['Timestamp']
        expected.columns = ['California', 'Texas']

        self.assertEqual(expected.to_csv(), result)
Example #4
0
    def test_pivoted_multi_dims_time_series_and_uni(self):
        result = CSV(slicer.metrics.votes, pivot=[slicer.dimensions.state]) \
            .transform(cont_uni_dim_df, slicer, [slicer.dimensions.timestamp, slicer.dimensions.state], [])

        expected = cont_uni_dim_df.copy() \
            .set_index(fd('state_display'), append=True) \
            .reset_index(fd('state'), drop=True)[[fm('votes')]]
        expected = expected.unstack(level=[1])
        expected.index.names = ['Timestamp']
        expected.columns = ['California', 'Texas']

        self.assertEqual(expected.to_csv(), result)
Example #5
0
    def test_pivoted_multi_dims_time_series_and_uni_with_sort_index_desc(self):
        result = Pandas(slicer.metrics.votes, pivot=[slicer.dimensions.state], sort=[0], ascending=[False]) \
            .transform(cont_uni_dim_df, slicer, [slicer.dimensions.timestamp, slicer.dimensions.state], [])

        expected = cont_uni_dim_df.copy() \
            .set_index(fd('state_display'), append=True) \
            .reset_index(fd('state'), drop=True)[[fm('votes')]]
        expected = expected.unstack(level=[1])
        expected.index.names = ['Timestamp']
        expected.columns = ['California', 'Texas']
        expected.columns.names = ['State']

        expected = expected.sort_index(ascending=False)

        pandas.testing.assert_frame_equal(expected, result)
Example #6
0
    def test_pivoted_multi_dims_time_series_and_uni_with_sort_index_desc(self):
        result = Pandas(slicer.metrics.votes, pivot=[slicer.dimensions.state], sort=[0], ascending=[False]) \
            .transform(cont_uni_dim_df, slicer, [slicer.dimensions.timestamp, slicer.dimensions.state], [])

        expected = cont_uni_dim_df.copy() \
            .set_index(fd('state_display'), append=True) \
            .reset_index(fd('state'), drop=True)[[fm('votes')]]
        expected = expected.unstack(level=[1])
        expected.index.names = ['Timestamp']
        expected.columns = ['California', 'Texas']
        expected.columns.names = ['State']

        expected = expected.sort_index(ascending=False)

        pandas.testing.assert_frame_equal(expected, result)
Example #7
0
    def test_multi_dims_time_series_and_cat_sort_index_level_0_asc(self):
        result = Pandas(slicer.metrics.wins, sort=[0]) \
            .transform(cont_uni_dim_df, slicer, [slicer.dimensions.timestamp, slicer.dimensions.state], [])

        expected = cont_uni_dim_df.copy() \
            .set_index(fd('state_display'), append=True) \
            .reset_index(fd('state'), drop=False)[[fm('wins')]]
        expected.index.names = ['Timestamp', 'State']
        expected.columns = ['Wins']
        expected.columns.name = 'Metrics'

        expected = expected.reset_index()
        expected = expected.sort_values(['Timestamp'])
        expected = expected.set_index(['Timestamp', 'State'])

        pandas.testing.assert_frame_equal(expected, result)
Example #8
0
    def test_pivoted_multi_dims_time_series_and_cat_sort_index_and_values(self):
        result = Pandas(slicer.metrics.wins, sort=[0, 2], ascending=[False, True]) \
            .transform(cont_uni_dim_df, slicer, [slicer.dimensions.timestamp, slicer.dimensions.state], [])

        expected = cont_uni_dim_df.copy() \
            .set_index(fd('state_display'), append=True) \
            .reset_index(fd('state'), drop=False)[[fm('wins')]]
        expected.index.names = ['Timestamp', 'State']
        expected.columns = ['Wins']
        expected.columns.name = 'Metrics'

        expected = expected.reset_index()
        expected = expected.sort_values(['Timestamp', 'Wins'], ascending=[False, True])
        expected = expected.set_index(['Timestamp', 'State'])

        pandas.testing.assert_frame_equal(expected, result)