Exemplo n.º 1
0
 def test_guess_formatter(self):
     """Test parsing of strings to floats, ints, nans, infs, bools, and strings"""
     for source,dest in self.tests:
         if isinstance(dest,float):
             if not numpy.isnan(dest):
                 self.assertEquals(guess_formatter(source),dest)
             else:
                 self.assertTrue(numpy.isnan(guess_formatter(source)))
         else: #if isinstance(dest,int):
             self.assertEquals(guess_formatter(source),dest)
Exemplo n.º 2
0
def parse_list(inp):
    """Restore non-nested lists of Python primitives from string representation of list
    Additionally parses `numpy.nan`, `numpy.inf`, and `-numpy.inf` to correct values
    
    Parameters
    ----------
    inp : str
        String representation of list data

    Returns
    -------
    list

    Raises
    ------
    AssertionError
        if String does not represent a list

    Notes
    -----
    Complex types like nested lists or tuples will not be processed,
    and may not be parsed correctly.
    """
    assert inp[0] == '[' and inp[-1] == ']'
    return [
        guess_formatter(X.strip().strip("'")) for X in inp[1:-1].split(",")
    ]
Exemplo n.º 3
0
def parse_list(inp):
    """Restore non-nested lists of Python primitives from string representation of list
    Additionally parses `numpy.nan`, `numpy.inf`, and `-numpy.inf` to correct values
    
    Parameters
    ----------
    inp : str
        String representation of list data

    Returns
    -------
    list

    Raises
    ------
    AssertionError
        if String does not represent a list

    Notes
    -----
    Complex types like nested lists or tuples will not be processed,
    and may not be parsed correctly.
    """
    assert inp[0] == "[" and inp[-1] == "]"
    return [guess_formatter(X.strip().strip("'")) for X in inp[1:-1].split(",")]