Skip to content

Commit

Permalink
Handle both new and old versions of PyTables
Browse files Browse the repository at this point in the history
  • Loading branch information
apdavison committed Apr 27, 2017
1 parent 74ee428 commit f3a4dc8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pyNN/recording/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,22 @@ def __init__(self, filename, mode='r', title="PyNN data file"):
"""
self.name = filename
self.mode = mode
self.fileobj = tables.openFile(filename, mode=mode, title=title)
try:
self.fileobj = tables.open_file(filename, mode=mode, title=title)
self._new_pytables = True
except AttributeError:
self.fileobj = tables.openFile(filename, mode=mode, title=title)
self._new_pytables = False

# may not work with old versions of PyTables < 1.3, since they only support numarray, not numpy
def write(self, data, metadata):
__doc__ = BaseFile.write.__doc__
if len(data) > 0:
try:
node = self.fileobj.createArray(self.fileobj.root, "data", data)
if self._new_pytables:
node = self.fileobj.create_array(self.fileobj.root, "data", data)
else:
node = self.fileobj.createArray(self.fileobj.root, "data", data)
except tables.HDF5ExtError as e:
raise tables.HDF5ExtError("%s. data.shape=%s, metadata=%s" % (e, data.shape, metadata))
for name, value in metadata.items():
Expand Down

0 comments on commit f3a4dc8

Please sign in to comment.