Skip to content

Commit 8b34fc9

Browse files
authored
Merge pull request #94 from GeospatialPython/karimbahgat-patch-fixtestfails
Updated docs, tests, and type detection error to fix Travis CI failures
2 parents a91d3b9 + 921200b commit 8b34fc9

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

README.md

+20-13
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ A line must have at least two points.
452452
Because of the similarities between polygon and line types it is possible to create
453453
a line shape using either the "line" or "poly" method.
454454

455+
455456
>>> w = shapefile.Writer()
456457

457458
>>> w.line(parts=[[[1,5],[5,5],[5,1],[3,3],[1,1]]])
@@ -546,14 +547,12 @@ To store very large numbers you must increase the field length size to the total
546547
>>> w.save('shapefiles/test/dtype')
547548

548549
>>> r = shapefile.Reader('shapefiles/test/dtype')
549-
>>> r.record(0)
550-
[1, 1.32, 1.3217328, -3.2302e-25, 1.3217328, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000L]
551-
>>> r.record(1)
552-
[None, None, None, None, None, None]
550+
>>> assert r.record(0) == [1, 1.32, 1.3217328, -3.2302e-25, 1.3217328, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000]
551+
>>> assert r.record(1) == [None, None, None, None, None, None]
553552

554553

555554
Finally, we can create boolean fields by setting the type to 'L'.
556-
This field can take True or False values, or any string whose first character is one of YyTt (True) or NnFf (False).
555+
This field can take True or False values, or 1 (True) or 0 (False).
557556
None is interpreted as missing.
558557

559558

@@ -565,22 +564,30 @@ None is interpreted as missing.
565564
>>> w.null()
566565
>>> w.null()
567566
>>> w.record(True)
568-
>>> w.record("Yes")
567+
>>> w.record(1)
569568
>>> w.record(False)
570-
>>> w.record("No")
569+
>>> w.record(0)
571570
>>> w.record(None)
571+
>>> w.record("Nonesense")
572572
>>> w.save('shapefiles/test/dtype')
573573

574574
>>> r = shapefile.Reader('shapefiles/test/dtype')
575-
>>> assert r.record(0) == [True]
576-
>>> assert r.record(1) == [True]
577-
>>> assert r.record(2) == [False]
578-
>>> assert r.record(3) == [False]
579-
>>> assert r.record(4) == [None]
580-
575+
>>> r.record(0)
576+
[True]
577+
>>> r.record(1)
578+
[True]
579+
>>> r.record(2)
580+
[False]
581+
>>> r.record(3)
582+
[False]
583+
>>> r.record(4)
584+
[None]
585+
>>> r.record(5)
586+
[None]
581587

582588
You can also add attributes using keyword arguments where the keys are field names.
583589

590+
584591
>>> w = shapefile.Writer()
585592
>>> w.field('FIRST_FLD','C','40')
586593
>>> w.field('SECOND_FLD','C','40')

shapefile.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ def __record(self):
516516
except ValueError:
517517
#not parseable as int, set to None
518518
value = None
519-
elif typ == b('D'):
519+
elif typ == 'D':
520520
# date: 8 bytes - date stored as a string in the format YYYYMMDD.
521521
if value.count(b('0')) == len(value): # QGIS NULL is all '0' chars
522522
value = None
@@ -526,17 +526,17 @@ def __record(self):
526526
value = date(y, m, d)
527527
except:
528528
value = value.strip()
529-
elif typ == b('L'):
529+
elif typ == 'L':
530530
# logical: 1 byte - initialized to 0x20 (space) otherwise T or F.
531-
if value == " ":
531+
if value == b(" "):
532532
value = None # space means missing or not yet set
533533
else:
534534
if value in b('YyTt1'):
535535
value = True
536536
elif value in b('NnFf0'):
537537
value = False
538538
else:
539-
value = b('?')
539+
value = None # unknown value is set to missing
540540
else:
541541
# anything else is forced to string/unicode
542542
value = u(value)
@@ -952,9 +952,13 @@ def __dbfRecords(self):
952952
elif fieldType == 'L':
953953
# logical: 1 byte - initialized to 0x20 (space) otherwise T or F.
954954
if value in MISSING:
955-
value = str(' ') # missing is set to space
955+
value = b(' ') # missing is set to space
956+
elif value in [True,1]:
957+
value = b("T")
958+
elif value in [False,0]:
959+
value = b("F")
956960
else:
957-
value = str(value)[0].upper()
961+
value = b(' ') # unknown is set to space
958962
else:
959963
# anything else is forced to string
960964
value = str(value)[:size].ljust(size)
@@ -1116,6 +1120,7 @@ def save(self, target=None, shp=None, shx=None, dbf=None):
11161120
self.dbf.close()
11171121
if generated:
11181122
return target
1123+
11191124
class Editor(Writer):
11201125
def __init__(self, shapefile=None, shapeType=POINT, autoBalance=1):
11211126
self.autoBalance = autoBalance

0 commit comments

Comments
 (0)