Exemplo n.º 1
0
 def __convert_cell(self, csv_cell_text):
     ret = None
     if self.__auto_detect_int:
         ret = service.detect_int_value(csv_cell_text)
     if ret is None and self.__auto_detect_float:
         ret = service.detect_float_value(csv_cell_text)
         shall_we_ignore_the_conversion = (
             (ret in [float('inf'), float('-inf')])
             and self.__ignore_infinity)
         if shall_we_ignore_the_conversion:
             ret = None
     if ret is None and self.__auto_detect_datetime:
         ret = service.detect_date_value(csv_cell_text)
     if ret is None:
         ret = csv_cell_text
     return ret
Exemplo n.º 2
0
 def __convert_cell(self, cell):
     if cell is None:
         return None
     if isinstance(cell, (datetime, date, time)):
         return cell
     ret = None
     if isinstance(cell, str):
         if self.__auto_detect_int:
             ret = service.detect_int_value(cell)
         if ret is None and self.__auto_detect_float:
             ret = service.detect_float_value(cell)
             shall_we_ignore_the_conversion = (ret in [
                 float("inf"), float("-inf")
             ]) and self.__ignore_infinity
             if shall_we_ignore_the_conversion:
                 ret = None
     if ret is None:
         ret = cell
     return ret
Exemplo n.º 3
0
 def __convert_cell(self, csv_cell_text):
     ret = None
     if self.__auto_detect_int:
         ret = service.detect_int_value(csv_cell_text, self.__pep_0515_off)
     if ret is None and self.__auto_detect_float:
         ret = service.detect_float_value(
             csv_cell_text,
             self.__pep_0515_off,
             ignore_nan_text=self.__ignore_nan_text,
             default_float_nan=self.__default_float_nan,
         )
         shall_we_ignore_the_conversion = (
             ret in [float("inf"), float("-inf")]
         ) and self.__ignore_infinity
         if shall_we_ignore_the_conversion:
             ret = None
     if ret is None and self.__auto_detect_datetime:
         ret = service.detect_date_value(csv_cell_text)
     if ret is None:
         ret = csv_cell_text
     return ret
Exemplo n.º 4
0
 def __convert_cell(self, csv_cell_text):
     ret = None
     if self.__auto_detect_int:
         ret = service.detect_int_value(csv_cell_text, self.__pep_0515_off)
     if ret is None and self.__auto_detect_float:
         ret = service.detect_float_value(
             csv_cell_text,
             self.__pep_0515_off,
             ignore_nan_text=self.__ignore_nan_text,
             default_float_nan=self.__default_float_nan,
         )
         shall_we_ignore_the_conversion = (
             ret in [float("inf"), float("-inf")]
         ) and self.__ignore_infinity
         if shall_we_ignore_the_conversion:
             ret = None
     if ret is None and self.__auto_detect_datetime:
         ret = service.detect_date_value(csv_cell_text)
     if ret is None:
         ret = csv_cell_text
     return ret
Exemplo n.º 5
0
def test_detect_float_value_on_custom_nan_text2():
    result = detect_float_value("nan", default_float_nan="nan")
    eq_(str(result), "nan")
Exemplo n.º 6
0
def test_detect_float_value_on_custom_nan_text():
    result = detect_float_value("NaN", default_float_nan="nan")
    eq_(result, None)
Exemplo n.º 7
0
def test_detect_float_value_on_nan():
    result = detect_float_value("NaN", ignore_nan_text=True)
    eq_(result, None)
Exemplo n.º 8
0
def test_suppression_of_pep_0515_float():
    result = detect_float_value("123_123.")
    eq_(result, None)
    result = detect_float_value("123_123.1")
    eq_(result, None)
Exemplo n.º 9
0
def test_detect_float_value():
    result = detect_float_value("123.1")
    eq_(result, 123.1)
Exemplo n.º 10
0
def test_detect_float_value_on_custom_nan_text2():
    result = detect_float_value("nan", default_float_nan="nan")
    eq_(str(result), "nan")
Exemplo n.º 11
0
def test_detect_float_value_on_custom_nan_text():
    result = detect_float_value("NaN", default_float_nan="nan")
    eq_(result, None)
Exemplo n.º 12
0
def test_detect_float_value_on_nan():
    result = detect_float_value("NaN", ignore_nan_text=True)
    eq_(result, None)
Exemplo n.º 13
0
def test_suppression_of_pep_0515_float():
    result = detect_float_value("123_123.")
    eq_(result, None)
    result = detect_float_value("123_123.1")
    eq_(result, None)
Exemplo n.º 14
0
def test_detect_float_value():
    result = detect_float_value("123.1")
    eq_(result, 123.1)