(text)
return new_text
Fixes Pandas docstring warning about using * and ** without ending \* and \*\*.

    The fix distinguishes single * and ** by adding \\ to them. No changes for *italic* and **bold** usages.

    :param text: Original text with warnings
    :return: Modified text that fixes warnings
Fixes Pandas docstring warning about using * and ** without ending \* and \*\*.
Fixes Pandas docstring warning about using * and ** without ending \ * and \ * \ * .
def reformat_asterisks(text):
    """
    Fixes Pandas docstring warning about using * and ** without ending \* and \*\*.

    The fix distinguishes single * and ** by adding \\ to them. No changes for *italic* and **bold** usages.

    :param text: Original text with warnings
    :return: Modified text that fixes warnings
    """
    lines = text.split('\n')
    new_text = ''
    for line in lines:
        idx = 0  # Starting parsing position within the ``line``
        while idx < len(line):  # Parsing until end of string reached
            idx1 = line.find('*', idx)
            if idx1 >= idx:
                # There is at least one asterisk in the line
                idx2 = line.find('*', idx1+1)

                if idx2 == -1:
                    # Only one single asterisk in the line - Reformat to `\*`
                    line = line.replace('*', '\\*')
                    idx = len(line)  # Parsed the line. Go to another line
                elif idx2 == idx1+1:
                    # First double asterisk met in the line
                    idx2 = line.find('**', idx1+2)
                    if idx2 == -1:
                        # Only one double asterisk in the line Reformat to `\*\*`. But there could be more asterisks
                        line = line.replace('**', '\\*\\*')
                        idx = idx1+4
                    else:
                        # At least two double asterisks in the line
                        idx = idx2+2  # Deal with remaining asterisks on the next ``while`` loop iteration
                else:
                    # There is another asterisk apart from the first asterisk
                    if idx2+1 < len(line):
                        # There is at least one more symbol in the line after second asterisk
                        if line[idx2+1] == '*':
                            # Situation when double asterisk is met after the first single asterisk - Reformat to `\*`
                            line = line.replace('*', '\\*', 1)  # Replace the first single asterisk
                            idx = idx2  # Handle double asterisk on the next ``while`` iteration
                        else:
                            # Two asterisks met in the line to italize characters between them
                            idx = idx2+1
                    else:
                        # Second asterisk was the last symbol in the line
                        idx = len(line)
            else:
                # No asterisks in the line
                idx = len(line)
        new_text += line + '\n'

    return new_text
def reformat_asterisks ( text ) : lines = text . split ( '\n' ) new_text = '' for line in lines : idx = 0 # Starting parsing position within the ``line`` while idx < len ( line ) : # Parsing until end of string reached idx1 = line . find ( '*' , idx ) if idx1 >= idx : # There is at least one asterisk in the line idx2 = line . find ( '*' , idx1 + 1 ) if idx2 == - 1 : # Only one single asterisk in the line - Reformat to `\*` line = line . replace ( '*' , '\\*' ) idx = len ( line ) # Parsed the line. Go to another line elif idx2 == idx1 + 1 : # First double asterisk met in the line idx2 = line . find ( '**' , idx1 + 2 ) if idx2 == - 1 : # Only one double asterisk in the line Reformat to `\*\*`. But there could be more asterisks line = line . replace ( '**' , '\\*\\*' ) idx = idx1 + 4 else : # At least two double asterisks in the line idx = idx2 + 2 # Deal with remaining asterisks on the next ``while`` loop iteration else : # There is another asterisk apart from the first asterisk if idx2 + 1 < len ( line ) : # There is at least one more symbol in the line after second asterisk if line [ idx2 + 1 ] == '*' : # Situation when double asterisk is met after the first single asterisk - Reformat to `\*` line = line . replace ( '*' , '\\*' , 1 ) # Replace the first single asterisk idx = idx2 # Handle double asterisk on the next ``while`` iteration else : # Two asterisks met in the line to italize characters between them idx = idx2 + 1 else : # Second asterisk was the last symbol in the line idx = len ( line ) else : # No asterisks in the line idx = len ( line ) new_text += line + '\n' return new_text