mirror of
				https://github.com/gristlabs/grist-core.git
				synced 2025-06-13 20:53:59 +00:00 
			
		
		
		
	Fix columns with falsy cells wrongly parsed as dates (#276)
Eg. before this commit, this table would result in Date columns: | A | B | | ----- | -- | | FALSE | 0 | For now, even FALSE is parsed as Numeric (not sure why we don't have a BooleanConverter).
This commit is contained in:
		
							parent
							
								
									c9a81ea7ea
								
							
						
					
					
						commit
						8bc5c7d595
					
				
							
								
								
									
										
											BIN
										
									
								
								sandbox/grist/imports/fixtures/test_falsy_cells.xlsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								sandbox/grist/imports/fixtures/test_falsy_cells.xlsx
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							@ -189,5 +189,22 @@ class TestImportXLS(unittest.TestCase):
 | 
			
		||||
      ],
 | 
			
		||||
    }])
 | 
			
		||||
 | 
			
		||||
  def test_falsy_cells(self):
 | 
			
		||||
    # Falsy cells should be parsed as Numeric, not Date.
 | 
			
		||||
    parsed_file = import_xls.parse_file(*_get_fixture('test_falsy_cells.xlsx'))
 | 
			
		||||
    tables = parsed_file[1]
 | 
			
		||||
    self.assertEqual(tables, [{
 | 
			
		||||
      'table_name': 'Sheet1',
 | 
			
		||||
      'column_metadata': [
 | 
			
		||||
        {'id': u'A', 'type': 'Numeric'},
 | 
			
		||||
        {'id': u'B', 'type': 'Numeric'},
 | 
			
		||||
      ],
 | 
			
		||||
      'table_data': [
 | 
			
		||||
        [0, 0],
 | 
			
		||||
        [0, 0],
 | 
			
		||||
      ],
 | 
			
		||||
    }])
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
  unittest.main()
 | 
			
		||||
 | 
			
		||||
@ -83,7 +83,7 @@ class SimpleDateTimeConverter(BaseConverter):
 | 
			
		||||
  def convert(cls, value):
 | 
			
		||||
    if type(value) is datetime.datetime:
 | 
			
		||||
      return value
 | 
			
		||||
    elif not value:
 | 
			
		||||
    elif value is None:
 | 
			
		||||
      return None
 | 
			
		||||
    raise ValueError()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user