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
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
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
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
def test_detect_float_value_on_custom_nan_text2(): result = detect_float_value("nan", default_float_nan="nan") eq_(str(result), "nan")
def test_detect_float_value_on_custom_nan_text(): result = detect_float_value("NaN", default_float_nan="nan") eq_(result, None)
def test_detect_float_value_on_nan(): result = detect_float_value("NaN", ignore_nan_text=True) eq_(result, None)
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)
def test_detect_float_value(): result = detect_float_value("123.1") eq_(result, 123.1)
def test_detect_float_value_on_custom_nan_text2(): result = detect_float_value("nan", default_float_nan="nan") eq_(str(result), "nan")
def test_detect_float_value_on_custom_nan_text(): result = detect_float_value("NaN", default_float_nan="nan") eq_(result, None)
def test_detect_float_value_on_nan(): result = detect_float_value("NaN", ignore_nan_text=True) eq_(result, None)
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)
def test_detect_float_value(): result = detect_float_value("123.1") eq_(result, 123.1)