pombreda / pysal

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

problem opening (and closing fully) dbfs #158

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Pick your favorite DBF and attempt to open using the following code. I may 
be doing something wrong but it gives me the error pasted below. 

>>> import pysal
>>> path="dbfnoextension"
>>> f = pysal.open(path + '.dbf','r')
>>> f.close()

This gives me the following error...

In [4]: f = pysal.open(path + '.dbf')
---------------------------------------------------------------------------
error                                     Traceback (most recent call last)

/Users/Nick/<ipython console> in <module>()

/Users/Nick/Public/Code/pysal/pysal/core/IOHandlers/pyDbfIO.pyc in 
__init__(self, *args, **kwargs)
     53         if self.mode == 'r':
     54             self.f = f = open(self.dataPath,'rb')
---> 55             numrec, lenheader = struct.unpack('<xxxxLH22x', f.read(32))
     56             numfields = (lenheader - 33) // 32
     57             self.n_records = numrec

error: unpack requires a string argument of length 32

2. Also, I've been having an issue where I get an error saying too many files 
are open when I have large N loops open a dbf multiple times. This is even 
after explicitly closing the file (using close()) as well. Here's my code for 
that. Is it reproducible or am I doing something wrong? I'd report the error 
message but the above is preventing that code from even running any more. If 
this is a separate ticket I'll post that after we get the above resolved. 

>>> import pysal
>>> path="dbfnoextension"
>>> for i in range(99999):
>>>    # for pysal dbf testing
>>>    f = pysal.open(path + '.dbf','r')
>>>    f.close()

What is the expected output? What do you see instead?

Please use labels and text to provide additional information.

Original issue reported on code.google.com by nmali...@gmail.com on 19 May 2011 at 10:09

GoogleCodeExporter commented 9 years ago
Please post the dbf you're using as no one here can replicate this error.  The 
second issue you raised was resolved by issue 155 two days ago. When was your 
last update?

Original comment by phil.stp...@gmail.com on 19 May 2011 at 10:21

GoogleCodeExporter commented 9 years ago
I guess the problem was with the DBF because when I opened it this morning in 
Qgis it was indeed corrupt. I've restored the file to its original splendor and 
now the above code works fine. Thanks for your help. Sorry to muddy the water. 

Original comment by nmali...@gmail.com on 20 May 2011 at 1:08

GoogleCodeExporter commented 9 years ago

Original comment by nmali...@gmail.com on 20 May 2011 at 1:10