def get_description(self, input_column_descriptions, slice_num=None, template_override=None): template = template_override or self.description_template if template: if isinstance(template, list): if slice_num is not None: slice_index = slice_num + 1 if slice_index < len(template): return template[slice_index].format(*input_column_descriptions, nth_slice=convert_to_nth(slice_index)) else: if len(template) > 2: raise IndexError('Slice out of range of template') return template[1].format(*input_column_descriptions, nth_slice=convert_to_nth(slice_index)) else: template = template[0] return template.format(*input_column_descriptions) # generic case: name = self.name.upper() if self.name is not None else type(self).__name__ if slice_num is not None: nth_slice = convert_to_nth(slice_num + 1) description = "the {} output from applying {} to {}".format(nth_slice, name, ', '.join(input_column_descriptions)) else: description = "the result of applying {} to {}".format(name, ', '.join(input_column_descriptions)) return description
def test_nth(): assert convert_to_nth(4) == "4th" assert convert_to_nth(11) == "11th" assert convert_to_nth(12) == "12th" assert convert_to_nth(13) == "13th" assert convert_to_nth(111) == "111th" assert convert_to_nth(112) == "112th" assert convert_to_nth(113) == "113th"
def test_nth(): assert convert_to_nth(4) == '4th' assert convert_to_nth(11) == '11th' assert convert_to_nth(12) == '12th' assert convert_to_nth(13) == '13th' assert convert_to_nth(111) == '111th' assert convert_to_nth(112) == '112th' assert convert_to_nth(113) == '113th'
def test_second(): assert convert_to_nth(2) == "2nd" assert convert_to_nth(22) == "22nd" assert convert_to_nth(232) == "232nd"
def test_first(): assert convert_to_nth(1) == "1st" assert convert_to_nth(21) == "21st" assert convert_to_nth(131) == "131st"
def test_third(): assert convert_to_nth(3) == "3rd" assert convert_to_nth(23) == "23rd" assert convert_to_nth(133) == "133rd"
def test_second(): assert convert_to_nth(2) == '2nd' assert convert_to_nth(22) == '22nd' assert convert_to_nth(232) == '232nd'
def test_first(): assert convert_to_nth(1) == '1st' assert convert_to_nth(21) == '21st' assert convert_to_nth(131) == '131st'
def test_third(): assert convert_to_nth(3) == '3rd' assert convert_to_nth(23) == '23rd' assert convert_to_nth(133) == '133rd'