def test_render_range_clamp_range(self): table = pd.DataFrame({"A": [1, 2], "B": [2, 3], "C": [3, 4]}) result = render(table, P(select_range=True, column_numbers="-1,2,6")) self.assertEqual( result, i18n_message( "badParam.column_numbers.invalid", {"value": "-1"}, ))
def test_render_range_ignore_empty_range(self): table = pd.DataFrame({"A": [1, 2], "B": [2, 3], "C": [3, 4]}) result = render(table.copy(), P(select_range=True, column_numbers="")) self.assertEqual( result, i18n_message( "badParam.column_numbers.invalid", {"value": ""}, ), )
def test_render_range_non_numeric_ranges(self): table = pd.DataFrame({"A": [1, 2], "B": [2, 3], "C": [3, 4]}) result = render(table, P(select_range=True, column_numbers="2-3,giraffe")) self.assertEqual( result, i18n_message( "badParam.column_numbers.invalid", {"value": "giraffe"}, ), )
def test_render_range_overlapping_ranges(self): table = pd.DataFrame({"A": [1, 2], "B": [2, 3], "C": [3, 4]}) result = render(table, P(select_range=True, column_numbers="2-3,2")) self.assertEqual(result, i18n_message("badParam.column_numbers.overlapping"))
def test_render_range_hyphen_separated(self): table = pd.DataFrame({"A": [1, 2], "B": [2, 3], "C": [3, 4]}) result = render(table, P(select_range=True, column_numbers="2-3", keep=False)) assert_frame_equal(result, pd.DataFrame({"A": [1, 2]}))
def test_render_range_comma_separated(self): table = pd.DataFrame({"A": [1, 2], "B": [2, 3], "C": [3, 4]}) result = render(table, P(select_range=True, column_numbers="1,3")) assert_frame_equal(result, pd.DataFrame({"A": [1, 2], "C": [3, 4]}))
def test_render_drop_columns(self): table = pd.DataFrame({"A": [1, 2], "B": [2, 3], "C": [3, 4]}) result = render(table, P(["B", "C"], keep=False)) assert_frame_equal(result, pd.DataFrame({"A": [1, 2]}))
def test_render_maintain_input_column_order(self): table = pd.DataFrame({"A": [1, 2], "B": [2, 3], "C": [3, 4]}) result = render(table, P(["B"], keep=False)) assert_frame_equal(result, pd.DataFrame({"A": [1, 2], "C": [3, 4]}))
def test_render_single_column(self): table = pd.DataFrame({"A": [1, 2], "B": [2, 3], "C": [3, 4]}) result = render(table, P(["A"])) assert_frame_equal(result, pd.DataFrame({"A": [1, 2]}))