Example #1
0
 def test_rename_custom_list_too_many_columns_is_error(self):
     table = pd.DataFrame({"A": ["x"]})
     result = render(table,
                     P(custom_list=True, list_string="X,Y"),
                     input_columns={"A": Column()})
     self.assertEqual(
         result,
         "You supplied 2 column names, but the table has 1 columns.")
Example #2
0
 def test_custom_list(self):
     table = pd.DataFrame({"A": ["x"], "B": [1]})
     result = render(
         table,
         P(custom_list=True, list_string="X\nY"),
         input_columns={
             "A": Column(),
             "B": Column("{:,d}")
         },
     )
     assert_frame_equal(result["dataframe"],
                        pd.DataFrame({
                            "X": ["x"],
                            "Y": [1]
                        }))
     self.assertEqual(result["column_formats"], {"Y": "{:,d}", "X": None})
Example #3
0
 def test_custom_list_disallow_rename_to_null(self):
     table = pd.DataFrame({"A": [1], "B": [2], "C": [3]})
     result = render(
         table,
         P(custom_list=True, list_string="D\n\nF"),
         input_columns={
             "A": Column(),
             "B": Column(),
             "C": Column()
         },
     )
     assert_frame_equal(result["dataframe"],
                        pd.DataFrame({
                            "D": [1],
                            "B": [2],
                            "F": [3]
                        }))
Example #4
0
 def test_rename_swap_columns(self):
     table = pd.DataFrame({"A": ["x"], "B": [1]})
     result = render(
         table,
         P(custom_list=False, renames={
             "A": "B",
             "B": "A"
         }),
         input_columns={
             "A": Column(),
             "B": Column("{:,d}")
         },
     )
     assert_frame_equal(result["dataframe"],
                        pd.DataFrame({
                            "B": ["x"],
                            "A": [1]
                        }))
     self.assertEqual(result["column_formats"], {"A": "{:,d}", "B": None})
Example #5
0
 def test_dict_disallow_rename_to_null(self):
     table = pd.DataFrame({"A": [1]})
     result = render(table,
                     P(renames={"A": ""}),
                     input_columns={"A": Column()})
     assert_frame_equal(result, pd.DataFrame({"A": [1]}))
Example #6
0
 def test_rename_custom_list_empty_is_no_op(self):
     table = pd.DataFrame({"A": ["x"]})
     result = render(table,
                     P(custom_list=True, list_string=""),
                     input_columns={"A": Column()})
     assert_frame_equal(result, pd.DataFrame({"A": ["x"]}))