def test_time_series_dim(self): result = CSV(slicer.metrics.wins) \ .transform(cont_dim_df, slicer, [slicer.dimensions.timestamp], []) expected = cont_dim_df.copy()[[fm('wins')]] expected.index.names = ['Timestamp'] expected.columns = ['Wins'] self.assertEqual(expected.to_csv(), result)
def test_time_series_dim(self): result = Pandas(slicer.metrics.wins) \ .transform(cont_dim_df, slicer, [slicer.dimensions.timestamp], []) expected = cont_dim_df.copy()[[fm('wins')]] expected.index.names = ['Timestamp'] expected.columns = ['Wins'] expected.columns.name = 'Metrics' pandas.testing.assert_frame_equal(expected, result)
def test_sort_value_greater_than_number_of_columns_is_ignored(self): result = Pandas(slicer.metrics.wins, sort=[5]) \ .transform(cont_dim_df, slicer, [slicer.dimensions.timestamp], []) expected = cont_dim_df.copy()[[fm('wins')]] expected.index.names = ['Timestamp'] expected.columns = ['Wins'] expected.columns.name = 'Metrics' pandas.testing.assert_frame_equal(expected, result)
def test_multiple_metrics_sort_value_desc(self): result = Pandas(slicer.metrics.wins, sort=[1], ascending=[False]) \ .transform(cont_dim_df, slicer, [slicer.dimensions.timestamp], []) expected = cont_dim_df.copy()[[fm('wins')]] expected.index.names = ['Timestamp'] expected.columns = ['Wins'] expected.columns.name = 'Metrics' expected = expected.sort_values(['Wins'], ascending=False) pandas.testing.assert_frame_equal(expected, result)
def test_metric_format(self): import copy votes = copy.copy(slicer.metrics.votes) votes.prefix = '$' votes.suffix = '€' votes.precision = 2 # divide the data frame by 3 to get a repeating decimal so we can check precision result = Pandas(votes) \ .transform(cont_dim_df / 3, slicer, [slicer.dimensions.timestamp], []) expected = cont_dim_df.copy()[[fm('votes')]] expected[fm('votes')] = ['${0:,.2f}€'.format(x) for x in expected[fm('votes')] / 3] expected.index.names = ['Timestamp'] expected.columns = ['Votes'] expected.columns.name = 'Metrics' pandas.testing.assert_frame_equal(expected, result)
def test_metric_format(self): import copy votes = copy.copy(slicer.metrics.votes) votes.prefix = '$' votes.suffix = '€' votes.precision = 2 # divide the data frame by 3 to get a repeating decimal so we can check precision result = Pandas(votes) \ .transform(cont_dim_df / 3, slicer, [slicer.dimensions.timestamp], []) expected = cont_dim_df.copy()[[fm('votes')]] expected[fm('votes')] = [ '${0:,.2f}€'.format(x) for x in expected[fm('votes')] / 3 ] expected.index.names = ['Timestamp'] expected.columns = ['Votes'] expected.columns.name = 'Metrics' pandas.testing.assert_frame_equal(expected, result)