Skip to content

Gracefully handle NULL numeric, date fields #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions shapefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('?')
Expand Down
Binary file added shapefiles/test/NullTest.dbf
Binary file not shown.
Binary file added shapefiles/test/NullTest.shp
Binary file not shown.
Binary file added shapefiles/test/NullTest.shx
Binary file not shown.