Beispiel #1
0
    def test_build_pandas_dataframe_empty_cellset(self):

        self.tm1.cubes.cells.write_value(
            value=0,
            cube_name=self.cube_name,
            element_tuple=(
                self.dim1_element_names[0],
                self.dim2_element_names[0],
                self.dim3_element_names[0],
                self.dim4_element_names[0],
            ),
            dimensions=(self.dim1_name, self.dim2_name, self.dim3_name, self.dim4_name),
        )
        rows = [
            DimensionSelection(
                dimension_name=self.dim1_name, elements=(self.dim1_element_names[0],)
            ),
            DimensionSelection(
                dimension_name=self.dim2_name, elements=(self.dim2_element_names[0],)
            ),
        ]
        columns = [
            DimensionSelection(
                dimension_name=self.dim3_name, elements=(self.dim3_element_names[0],)
            ),
            DimensionSelection(
                dimension_name=self.dim4_name, elements=(self.dim4_element_names[0],)
            ),
        ]
        suppress = "Both"
        mdx = MDXUtils.construct_mdx(
            cube_name=self.cube_name, rows=rows, columns=columns, suppress=suppress
        )
        empty_cellset = self.tm1.cubes.cells.execute_mdx(mdx)
        self.assertRaises(
            ValueError, Utils.build_pandas_dataframe_from_cellset, empty_cellset, True
        )
        self.assertRaises(
            ValueError, Utils.build_pandas_dataframe_from_cellset, empty_cellset, False
        )
Beispiel #2
0
 def test_construct_mdx_suppress_zeroes(self):
     rows = [
         DimensionSelection(dimension_name=self.dim1_name),
         DimensionSelection(
             dimension_name=self.dim2_name, elements=self.dim2_element_names
         ),
     ]
     columns = [
         DimensionSelection(
             dimension_name=self.dim3_name,
             expression="TM1SubsetAll([{}])".format(self.dim3_name),
         ),
         DimensionSelection(
             dimension_name=self.dim4_name, subset=self.dim4_subset_Name
         ),
     ]
     mdx = MDXUtils.construct_mdx(
         cube_name=self.cube_name, rows=rows, columns=columns, suppress="BOTH"
     )
     content = self.tm1.cubes.cells.execute_mdx(mdx)
     number_cells = len(content.keys())
     self.assertLess(number_cells, 1000)
Beispiel #3
0
 def test_build_pandas_dataframe_from_cellset(self):
     rows = [DimensionSelection(dimension_name=self.dim1_name),
             DimensionSelection(dimension_name=self.dim2_name, elements=self.dim2_element_names)]
     columns = [
         DimensionSelection(
             dimension_name=self.dim3_name,
             expression="TM1SubsetAll([{}])".format(self.dim3_name)),
         DimensionSelection(
             dimension_name=self.dim4_name,
             subset=self.dim4_subset_Name)]
     suppress = None
     mdx = MDXUtils.construct_mdx(
         cube_name=self.cube_name,
         rows=rows,
         columns=columns,
         suppress=suppress)
     cellset = self.tm1.cubes.cells.execute_mdx(mdx)
     df = Utils.build_pandas_dataframe_from_cellset(cellset, multiindex=False)
     self.assertTrue(df.shape[0] == 1000)
     self.assertTrue(df.shape[1] == 5)
     self.assertIsInstance(df, pd.DataFrame)
     cellset = Utils.build_cellset_from_pandas_dataframe(df)
     self.assertTrue(len(cellset.keys()) == 1000)
     self.assertIsInstance(cellset, Utils.CaseAndSpaceInsensitiveTuplesDict)
Beispiel #4
0
 def test_determine_selection_type(self):
     self.assertEqual(
         DimensionSelection.determine_selection_type(elements=["e1", "e2"],
                                                     subset=None,
                                                     expression=None),
         DimensionSelection.ITERABLE)
     self.assertEqual(
         DimensionSelection.determine_selection_type(["e1", "e2"]),
         DimensionSelection.ITERABLE)
     self.assertEqual(
         DimensionSelection.determine_selection_type(elements=None,
                                                     subset="something",
                                                     expression=None),
         DimensionSelection.SUBSET)
     self.assertEqual(
         DimensionSelection.determine_selection_type(
             None, "something", None), DimensionSelection.SUBSET)
     self.assertEqual(
         DimensionSelection.determine_selection_type(
             elements=None, subset=None, expression="{[d1].[e1]}"),
         DimensionSelection.EXPRESSION)
     self.assertEqual(
         DimensionSelection.determine_selection_type(
             None, None, "{[d1].[e1]}"), DimensionSelection.EXPRESSION)
     self.assertEqual(
         DimensionSelection.determine_selection_type(elements=None,
                                                     subset=None,
                                                     expression=None), None)
     self.assertEqual(
         DimensionSelection.determine_selection_type(None, None, None),
         None)
     self.assertEqual(DimensionSelection.determine_selection_type(), None)
     self.assertRaises(ValueError,
                       DimensionSelection.determine_selection_type, ["e2"],
                       "subset1", "{[d1].[e1]}")
     self.assertRaises(ValueError,
                       DimensionSelection.determine_selection_type, ["e2"],
                       "subset1")
     self.assertRaises(ValueError,
                       DimensionSelection.determine_selection_type, ["e2"],
                       None, "subset1")
Beispiel #5
0
 def test_construct_mdx(self):
     rows = [
         DimensionSelection(dimension_name=self.dim1_name),
         DimensionSelection(
             dimension_name=self.dim2_name, elements=self.dim2_element_names
         ),
     ]
     columns = [
         DimensionSelection(
             dimension_name=self.dim3_name,
             expression="TM1SubsetAll([{}])".format(self.dim3_name),
         )
     ]
     contexts = {self.dim4_name: self.dim4_element_names[0]}
     mdx = MDXUtils.construct_mdx(
         cube_name=self.cube_name,
         rows=rows,
         columns=columns,
         contexts=contexts,
         suppress=None,
     )
     content = self.tm1.cubes.cells.execute_mdx(mdx)
     number_cells = len(content.keys())
     self.assertEqual(number_cells, 1000)