diff --git a/shapefile.py b/shapefile.py index f57ef31..c677484 100644 --- a/shapefile.py +++ b/shapefile.py @@ -482,18 +482,22 @@ def __record(self): continue elif typ == "N": value = value.replace(b('\0'), b('')).strip() + value = value.replace(b('*'), b('')) # QGIS NULL is all '*' chars if value == b(''): - value = 0 + value = None elif deci: value = float(value) else: value = int(value) elif typ == b('D'): - try: - y, m, d = int(value[:4]), int(value[4:6]), int(value[6:8]) - value = [y, m, d] - except: - value = value.strip() + if value.count(b('0')) == len(value): # QGIS NULL is all '0' chars + value = None + else: + try: + y, m, d = int(value[:4]), int(value[4:6]), int(value[6:8]) + value = [y, m, d] + except: + value = value.strip() elif typ == b('L'): value = (value in b('YyTt') and b('T')) or \ (value in b('NnFf') and b('F')) or b('?') diff --git a/shapefiles/test/NullTest.dbf b/shapefiles/test/NullTest.dbf new file mode 100644 index 0000000..84f8aa6 Binary files /dev/null and b/shapefiles/test/NullTest.dbf differ diff --git a/shapefiles/test/NullTest.shp b/shapefiles/test/NullTest.shp new file mode 100644 index 0000000..216feda Binary files /dev/null and b/shapefiles/test/NullTest.shp differ diff --git a/shapefiles/test/NullTest.shx b/shapefiles/test/NullTest.shx new file mode 100644 index 0000000..b00b9a8 Binary files /dev/null and b/shapefiles/test/NullTest.shx differ