Skip to content

Commit

Permalink
BUG: Move metadata along with data inside of 'remove' (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
cfarrow committed Sep 13, 2017
1 parent b07d3be commit 7b2dd5f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 4 additions & 3 deletions sdafile/sda_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,11 @@ def _copy_visitor(path, source, destination, labels):

# Copy everything else
source_obj = source[path]
destination.attrs.update(source.attrs)
if isinstance(source_obj, h5py.Group):
destination.create_group(path)
dest_obj = destination.create_group(path)
else:
ds = source_obj
destination.create_dataset(
dest_obj = destination.create_dataset(
path,
data=source_obj[()],
chunks=ds.chunks,
Expand All @@ -314,6 +313,8 @@ def _copy_visitor(path, source, destination, labels):
fillvalue=ds.fillvalue,
)

dest_obj.attrs.update(source_obj.attrs)

pid, destination_path = tempfile.mkstemp()
os.close(pid)
with h5py.File(destination_path, 'w') as destination:
Expand Down
11 changes: 11 additions & 0 deletions sdafile/tests/test_sda_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,9 +705,20 @@ def test_remove(self):
sda_file.remove(*removed)
self.assertEqual(sorted(sda_file.labels()), sorted(kept))

# Make sure metadata is preserved and data can be extracted
with sda_file._h5file('r') as h5file:
for label in kept:
attrs = h5file[label].attrs
self.assertIn('Deflate', attrs)
self.assertIn('Description', attrs)
self.assertIn('RecordType', attrs)
self.assertIn('Empty', attrs)
sda_file.extract(label)

sda_file.remove(*kept)
self.assertEqual(sda_file.labels(), [])

self.assertEqual(sda_file.FormatVersion, '1.1')
self.assertNotEqual(sda_file.Updated, 'Unmodified')

def test_probe(self):
Expand Down

0 comments on commit 7b2dd5f

Please sign in to comment.