pombreda / pysal

Automatically exported from code.google.com/p/pysal
Other
0 stars 0 forks source link

Problem with DBF reader #186

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'm writing dbf's with pysal. It was working and I've changed from writing 
strings to write some of the columns as floats and it now gives me this error:

3442.00000000000000 19 14
Traceback (most recent call last):
  File "scripts/build_tract_csv.py", line 101, in <module>
    map(extract_state, ['11'])
  File "scripts/build_tract_csv.py", line 93, in extract_state
    shp = shp_builder(data, dbf_path[:-3]+'shp', out_shp)
  File "/Users/dani/code/hud/code/census2010/tools.py", line 58, in shp_builder
    db_creation = df2dbf(df, outshp[: -3]+'dbf')
  File "/Users/dani/code/hud/code/census2010/tools.py", line 42, in df2dbf
    db.write(row)
  File "/Users/dani/code/pysal/pysal/core/IOHandlers/pyDbfIO.py", line 228, in write
    assert len(value) == size
AssertionError

The specs for the floats are ('N', 14, 14).

Charlie's hunch is the following (for the record):

it means the values being written to the DBF doesn't match the size specified 
in the spec
which means for some reason it could not be formatted correctly.

line 220, should probably look like this,
s = (("%"+"%d.%d"%(size+1,deci)+"f")%(value))[:size]

Original issue reported on code.google.com by dreamessence on 11 Jan 2012 at 10:55

GoogleCodeExporter commented 9 years ago
Made the change to line 220 of pyDbfIO in r1134.

This should address the problem for the time being.  The real problem is that 
size includes the decimal places.  So the spec ("N",14, 14) isn't technically 
valid.  The size is the length of the field as a str and include the decimal 
place (at least in our implementation).

Original comment by schmi...@gmail.com on 30 Jan 2012 at 2:56