Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: raise if kwds are ignored in require_dataset #897

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion h5py/_hl/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,12 @@ def require_dataset(self, name, shape, dtype, exact=False, **kwds):
shape or dtype don't match according to the above rules.
"""
with phil:
if not name in self:
if name not in self:
return self.create_dataset(name, *(shape, dtype), **kwds)

if kwds:
raise RuntimeError('Keyword arguments are ignored')

dset = self[name]
if not isinstance(dset, dataset.Dataset):
raise TypeError("Incompatible object (%s) already exists" % dset.__class__.__name__)
Expand Down
6 changes: 6 additions & 0 deletions h5py/tests/old/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ def test_create_existing(self):
dset2 = self.f.require_dataset('foo', (10, 3), 'f')
self.assertEqual(dset, dset2)

def test_kwds_fail(self):
""" require_dataset yields existing dataset """
self.f.require_dataset('foo', (10, 3), 'f', data=np.ones((10, 3)))
with self.assertRaises(RuntimeError):
self.f.require_dataset('foo', (10, 3), 'f', data=np.ones((10, 3)))

def test_shape_conflict(self):
""" require_dataset with shape conflict yields TypeError """
self.f.create_dataset('foo', (10, 3), 'f')
Expand Down