Exemplo n.º 1
0
def nullable_int(num):
    """
    casts input to an int if not an accepted null value. See :func:tab.tab.cast_null
    """
    try:
        return cast_null(num)
    except TypeError:
        pass
    return int(num)
Exemplo n.º 2
0
 def test_cast_null_error(self):
     with self.assertRaises(TypeError):
         cast_null('f')
Exemplo n.º 3
0
 def test_cast_null_ok(self):
     self.assertEqual(None, cast_null('none'))
     self.assertEqual(None, cast_null(None))
Exemplo n.º 4
0
 def nullable_int(row):
     try:
         row = int(row)
     except ValueError:
         row = tab.cast_null(row)
     return row
Exemplo n.º 5
0
def soft_cast_null(value):
    try:
        return tab.cast_null(value)
    except TypeError:
        return value