test_dataset_getitem.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. # This file is part of h5py, a Python interface to the HDF5 library.
  2. #
  3. # http://www.h5py.org
  4. #
  5. # Copyright 2008-2013 Andrew Collette and contributors
  6. #
  7. # License: Standard 3-clause BSD; see "license.txt" for full license terms
  8. # and contributor agreement.
  9. """
  10. Tests the h5py.Dataset.__getitem__ method.
  11. This module does not specifically test type conversion. The "type" axis
  12. therefore only tests objects which interact with the slicing system in
  13. unreliable ways; for example, compound and array types.
  14. See test_dataset_getitem_types for type-conversion tests.
  15. Tests are organized into TestCases by dataset shape and type. Test
  16. methods vary by slicing arg type.
  17. 1. Dataset shape:
  18. Empty
  19. Scalar
  20. 1D
  21. 3D
  22. 2. Type:
  23. Float
  24. Compound
  25. Array
  26. 3. Slicing arg types:
  27. Ellipsis
  28. Empty tuple
  29. Regular slice
  30. MultiBlockSlice
  31. Indexing
  32. Index list
  33. Boolean mask
  34. Field names
  35. """
  36. import sys
  37. import numpy as np
  38. import pytest
  39. import h5py
  40. from .common import ut, TestCase, make_name
  41. class TestEmpty(TestCase):
  42. def setUp(self):
  43. TestCase.setUp(self)
  44. sid = h5py.h5s.create(h5py.h5s.NULL)
  45. tid = h5py.h5t.C_S1.copy()
  46. tid.set_size(10)
  47. dsid = h5py.h5d.create(self.f.id, b'x', tid, sid)
  48. self.dset = h5py.Dataset(dsid)
  49. self.empty_obj = h5py.Empty(np.dtype("S10"))
  50. def test_ndim(self):
  51. """ Verify number of dimensions """
  52. self.assertEqual(self.dset.ndim, 0)
  53. def test_shape(self):
  54. """ Verify shape """
  55. self.assertEqual(self.dset.shape, None)
  56. def test_size(self):
  57. """ Verify shape """
  58. self.assertEqual(self.dset.size, None)
  59. def test_nbytes(self):
  60. """ Verify nbytes """
  61. self.assertEqual(self.dset.nbytes, 0)
  62. def test_ellipsis(self):
  63. self.assertEqual(self.dset[...], self.empty_obj)
  64. def test_tuple(self):
  65. self.assertEqual(self.dset[()], self.empty_obj)
  66. def test_slice(self):
  67. """ slice -> ValueError """
  68. with self.assertRaises(ValueError):
  69. self.dset[0:4]
  70. def test_multi_block_slice(self):
  71. """ MultiBlockSlice -> ValueError """
  72. with self.assertRaises(ValueError):
  73. self.dset[h5py.MultiBlockSlice()]
  74. def test_index(self):
  75. """ index -> ValueError """
  76. with self.assertRaises(ValueError):
  77. self.dset[0]
  78. def test_indexlist(self):
  79. """ index list -> ValueError """
  80. with self.assertRaises(ValueError):
  81. self.dset[[1,2,5]]
  82. def test_mask(self):
  83. """ mask -> ValueError """
  84. mask = np.array(True, dtype='bool')
  85. with self.assertRaises(ValueError):
  86. self.dset[mask]
  87. def test_fieldnames(self):
  88. """ field name -> ValueError """
  89. with self.assertRaises(ValueError):
  90. self.dset['field']
  91. class TestScalarFloat(TestCase):
  92. def setUp(self):
  93. TestCase.setUp(self)
  94. self.data = np.array(42.5, dtype=np.double)
  95. self.dset = self.f.create_dataset('x', data=self.data)
  96. def test_ndim(self):
  97. """ Verify number of dimensions """
  98. self.assertEqual(self.dset.ndim, 0)
  99. def test_size(self):
  100. """ Verify size """
  101. self.assertEqual(self.dset.size, 1)
  102. def test_nbytes(self):
  103. """ Verify nbytes """
  104. self.assertEqual(self.dset.nbytes, self.data.dtype.itemsize) # not sure if 'f' is always alias for 'f4'
  105. def test_shape(self):
  106. """ Verify shape """
  107. self.assertEqual(self.dset.shape, tuple())
  108. def test_ellipsis(self):
  109. """ Ellipsis -> scalar ndarray """
  110. out = self.dset[...]
  111. self.assertArrayEqual(out, self.data)
  112. def test_tuple(self):
  113. """ () -> bare item """
  114. out = self.dset[()]
  115. self.assertArrayEqual(out, self.data.item())
  116. def test_slice(self):
  117. """ slice -> ValueError """
  118. with self.assertRaises(ValueError):
  119. self.dset[0:4]
  120. def test_multi_block_slice(self):
  121. """ MultiBlockSlice -> ValueError """
  122. with self.assertRaises(ValueError):
  123. self.dset[h5py.MultiBlockSlice()]
  124. def test_index(self):
  125. """ index -> ValueError """
  126. with self.assertRaises(ValueError):
  127. self.dset[0]
  128. # FIXME: NumPy has IndexError instead
  129. def test_indexlist(self):
  130. """ index list -> ValueError """
  131. with self.assertRaises(ValueError):
  132. self.dset[[1,2,5]]
  133. # FIXME: NumPy permits this
  134. def test_mask(self):
  135. """ mask -> ValueError """
  136. mask = np.array(True, dtype='bool')
  137. with self.assertRaises(ValueError):
  138. self.dset[mask]
  139. def test_fieldnames(self):
  140. """ field name -> ValueError (no fields) """
  141. with self.assertRaises(ValueError):
  142. self.dset['field']
  143. class TestScalarCompound(TestCase):
  144. def setUp(self):
  145. TestCase.setUp(self)
  146. self.data = np.array((42.5, -118, "Hello"), dtype=[('a', 'f'), ('b', 'i'), ('c', '|S10')])
  147. self.dset = self.f.create_dataset('x', data=self.data)
  148. def test_ndim(self):
  149. """ Verify number of dimensions """
  150. self.assertEqual(self.dset.ndim, 0)
  151. def test_shape(self):
  152. """ Verify shape """
  153. self.assertEqual(self.dset.shape, tuple())
  154. def test_size(self):
  155. """ Verify size """
  156. self.assertEqual(self.dset.size, 1)
  157. def test_nbytes(self):
  158. """ Verify nbytes """
  159. self.assertEqual(self.dset.nbytes, self.data.dtype.itemsize)
  160. def test_ellipsis(self):
  161. """ Ellipsis -> scalar ndarray """
  162. out = self.dset[...]
  163. # assertArrayEqual doesn't work with compounds; do manually
  164. self.assertIsInstance(out, np.ndarray)
  165. self.assertEqual(out.shape, self.data.shape)
  166. self.assertEqual(out.dtype, self.data.dtype)
  167. def test_tuple(self):
  168. """ () -> np.void instance """
  169. out = self.dset[()]
  170. self.assertIsInstance(out, np.void)
  171. self.assertEqual(out.dtype, self.data.dtype)
  172. def test_slice(self):
  173. """ slice -> ValueError """
  174. with self.assertRaises(ValueError):
  175. self.dset[0:4]
  176. def test_multi_block_slice(self):
  177. """ MultiBlockSlice -> ValueError """
  178. with self.assertRaises(ValueError):
  179. self.dset[h5py.MultiBlockSlice()]
  180. def test_index(self):
  181. """ index -> ValueError """
  182. with self.assertRaises(ValueError):
  183. self.dset[0]
  184. # FIXME: NumPy has IndexError instead
  185. def test_indexlist(self):
  186. """ index list -> ValueError """
  187. with self.assertRaises(ValueError):
  188. self.dset[[1,2,5]]
  189. # FIXME: NumPy permits this
  190. def test_mask(self):
  191. """ mask -> ValueError """
  192. mask = np.array(True, dtype='bool')
  193. with self.assertRaises(ValueError):
  194. self.dset[mask]
  195. # FIXME: NumPy returns a scalar ndarray
  196. def test_fieldnames(self):
  197. """ field name -> bare value """
  198. out = self.dset['a']
  199. self.assertIsInstance(out, np.float32)
  200. self.assertEqual(out, self.dset['a'])
  201. class TestScalarArray(TestCase):
  202. def setUp(self):
  203. TestCase.setUp(self)
  204. self.dt = np.dtype('(3,2)f')
  205. self.data = np.array([(3.2, -119), (42, 99.8), (3.14, 0)], dtype='f')
  206. self.dset = self.f.create_dataset('x', (), dtype=self.dt)
  207. self.dset[...] = self.data
  208. def test_ndim(self):
  209. """ Verify number of dimensions """
  210. self.assertEqual(self.data.ndim, 2)
  211. self.assertEqual(self.dset.ndim, 0)
  212. def test_size(self):
  213. """ Verify size """
  214. self.assertEqual(self.dset.size, 1)
  215. def test_nbytes(self):
  216. """ Verify nbytes """
  217. self.assertEqual(self.dset.nbytes, self.dset.dtype.itemsize) # not sure if 'f' is always alias for 'f4'
  218. def test_shape(self):
  219. """ Verify shape """
  220. self.assertEqual(self.data.shape, (3, 2))
  221. self.assertEqual(self.dset.shape, tuple())
  222. def test_ellipsis(self):
  223. """ Ellipsis -> ndarray promoted to underlying shape """
  224. out = self.dset[...]
  225. self.assertArrayEqual(out, self.data)
  226. def test_tuple(self):
  227. """ () -> same as ellipsis """
  228. out = self.dset[...]
  229. self.assertArrayEqual(out, self.data)
  230. def test_slice(self):
  231. """ slice -> ValueError """
  232. with self.assertRaises(ValueError):
  233. self.dset[0:4]
  234. def test_multi_block_slice(self):
  235. """ MultiBlockSlice -> ValueError """
  236. with self.assertRaises(ValueError):
  237. self.dset[h5py.MultiBlockSlice()]
  238. def test_index(self):
  239. """ index -> ValueError """
  240. with self.assertRaises(ValueError):
  241. self.dset[0]
  242. def test_indexlist(self):
  243. """ index list -> ValueError """
  244. with self.assertRaises(ValueError):
  245. self.dset[[]]
  246. def test_mask(self):
  247. """ mask -> ValueError """
  248. mask = np.array(True, dtype='bool')
  249. with self.assertRaises(ValueError):
  250. self.dset[mask]
  251. def test_fieldnames(self):
  252. """ field name -> ValueError (no fields) """
  253. with self.assertRaises(ValueError):
  254. self.dset['field']
  255. class Test1DZeroFloat(TestCase):
  256. def setUp(self):
  257. TestCase.setUp(self)
  258. self.data = np.ones((0,), dtype='f')
  259. self.dset = self.f.create_dataset('x', data=self.data)
  260. def test_ndim(self):
  261. """ Verify number of dimensions """
  262. self.assertEqual(self.dset.ndim, 1)
  263. def test_shape(self):
  264. """ Verify shape """
  265. self.assertEqual(self.dset.shape, (0,))
  266. def test_ellipsis(self):
  267. """ Ellipsis -> ndarray of matching shape """
  268. self.assertNumpyBehavior(self.dset, self.data, np.s_[...])
  269. def test_tuple(self):
  270. """ () -> same as ellipsis """
  271. self.assertNumpyBehavior(self.dset, self.data, np.s_[()])
  272. def test_slice(self):
  273. """ slice -> ndarray of shape (0,) """
  274. self.assertNumpyBehavior(self.dset, self.data, np.s_[0:4])
  275. def test_slice_stop_less_than_start(self):
  276. self.assertNumpyBehavior(self.dset, self.data, np.s_[7:5])
  277. def test_index(self):
  278. """ index -> out of range """
  279. with self.assertRaises(IndexError):
  280. self.dset[0]
  281. def test_indexlist(self):
  282. """ index list """
  283. self.assertNumpyBehavior(self.dset, self.data, np.s_[[]])
  284. def test_mask(self):
  285. """ mask -> ndarray of matching shape """
  286. mask = np.ones((0,), dtype='bool')
  287. self.assertNumpyBehavior(
  288. self.dset,
  289. self.data,
  290. np.s_[mask],
  291. # Fast reader doesn't work with boolean masks
  292. skip_fast_reader=True,
  293. )
  294. def test_fieldnames(self):
  295. """ field name -> ValueError (no fields) """
  296. with self.assertRaises(ValueError):
  297. self.dset['field']
  298. class Test1DFloat(TestCase):
  299. def setUp(self):
  300. TestCase.setUp(self)
  301. self.data = np.arange(50).astype('f')
  302. self.dset = self.f.create_dataset('x', data=self.data)
  303. def test_ndim(self):
  304. """ Verify number of dimensions """
  305. self.assertEqual(self.dset.ndim, 1)
  306. def test_shape(self):
  307. """ Verify shape """
  308. self.assertEqual(self.dset.shape, (50,))
  309. def test_ellipsis(self):
  310. self.assertNumpyBehavior(self.dset, self.data, np.s_[...])
  311. def test_tuple(self):
  312. self.assertNumpyBehavior(self.dset, self.data, np.s_[()])
  313. def test_slice_simple(self):
  314. self.assertNumpyBehavior(self.dset, self.data, np.s_[0:4])
  315. def test_slice_zerosize(self):
  316. self.assertNumpyBehavior(self.dset, self.data, np.s_[4:4])
  317. def test_slice_strides(self):
  318. self.assertNumpyBehavior(self.dset, self.data, np.s_[1:7:3])
  319. def test_slice_negindexes(self):
  320. self.assertNumpyBehavior(self.dset, self.data, np.s_[-8:-2:3])
  321. def test_slice_stop_less_than_start(self):
  322. self.assertNumpyBehavior(self.dset, self.data, np.s_[7:5])
  323. def test_slice_outofrange(self):
  324. self.assertNumpyBehavior(self.dset, self.data, np.s_[100:400:3])
  325. def test_slice_backwards(self):
  326. """ we disallow negative steps """
  327. with self.assertRaises(ValueError):
  328. self.dset[::-1]
  329. def test_slice_zerostride(self):
  330. self.assertNumpyBehavior(self.dset, self.data, np.s_[::0])
  331. def test_index_simple(self):
  332. self.assertNumpyBehavior(self.dset, self.data, np.s_[3])
  333. def test_index_neg(self):
  334. self.assertNumpyBehavior(self.dset, self.data, np.s_[-4])
  335. # FIXME: NumPy permits this... it adds a new axis in front
  336. def test_index_none(self):
  337. with self.assertRaises(TypeError):
  338. self.dset[None]
  339. def test_index_illegal(self):
  340. """ Illegal slicing argument """
  341. with self.assertRaises(TypeError):
  342. self.dset[{}]
  343. def test_index_outofrange(self):
  344. with self.assertRaises(IndexError):
  345. self.dset[100]
  346. def test_indexlist_simple(self):
  347. self.assertNumpyBehavior(self.dset, self.data, np.s_[[1,2,5]])
  348. def test_indexlist_numpyarray(self):
  349. self.assertNumpyBehavior(self.dset, self.data, np.s_[np.array([1, 2, 5])])
  350. def test_indexlist_long(self):
  351. # selection logic changes with >16 indices
  352. self.assertNumpyBehavior(self.dset, self.data, np.s_[range(0, 50, 2)])
  353. def test_indexlist_single_index_ellipsis(self):
  354. self.assertNumpyBehavior(self.dset, self.data, np.s_[[0], ...])
  355. def test_indexlist_numpyarray_single_index_ellipsis(self):
  356. self.assertNumpyBehavior(self.dset, self.data, np.s_[np.array([0]), ...])
  357. def test_indexlist_long_ellipsis(self):
  358. # selection logic changes with >16 indices
  359. self.assertNumpyBehavior(self.dset, self.data, np.s_[range(0, 50, 2), ...])
  360. def test_indexlist_numpyarray_ellipsis(self):
  361. self.assertNumpyBehavior(self.dset, self.data, np.s_[np.array([1, 2, 5]), ...])
  362. def test_indexlist_empty(self):
  363. self.assertNumpyBehavior(self.dset, self.data, np.s_[[]])
  364. def test_indexlist_outofrange(self):
  365. with self.assertRaises(IndexError):
  366. self.dset[[100]]
  367. def test_indexlist_nonmonotonic(self):
  368. """ we require index list values to be strictly increasing """
  369. with self.assertRaises(TypeError):
  370. self.dset[[1,3,2]]
  371. def test_indexlist_monotonic_negative(self):
  372. # This should work: indices are logically increasing
  373. self.assertNumpyBehavior(self.dset, self.data, np.s_[[0, 2, -2]])
  374. with self.assertRaises(TypeError):
  375. self.dset[[-2, -3]]
  376. def test_indexlist_repeated(self):
  377. """ we forbid repeated index values """
  378. with self.assertRaises(TypeError):
  379. self.dset[[1,1,2]]
  380. def test_mask_true(self):
  381. self.assertNumpyBehavior(
  382. self.dset,
  383. self.data,
  384. np.s_[self.data > -100],
  385. # Fast reader doesn't work with boolean masks
  386. skip_fast_reader=True,
  387. )
  388. def test_mask_false(self):
  389. self.assertNumpyBehavior(
  390. self.dset,
  391. self.data,
  392. np.s_[self.data > 100],
  393. # Fast reader doesn't work with boolean masks
  394. skip_fast_reader=True,
  395. )
  396. def test_mask_partial(self):
  397. self.assertNumpyBehavior(
  398. self.dset,
  399. self.data,
  400. np.s_[self.data > 5],
  401. # Fast reader doesn't work with boolean masks
  402. skip_fast_reader=True,
  403. )
  404. def test_mask_wrongsize(self):
  405. """ we require the boolean mask shape to match exactly """
  406. with self.assertRaises(TypeError):
  407. self.dset[np.ones((2,), dtype='bool')]
  408. def test_fieldnames(self):
  409. """ field name -> ValueError (no fields) """
  410. with self.assertRaises(ValueError):
  411. self.dset['field']
  412. class Test2DZeroFloat(TestCase):
  413. def setUp(self):
  414. TestCase.setUp(self)
  415. self.data = np.ones((0,3), dtype='f')
  416. self.dset = self.f.create_dataset('x', data=self.data)
  417. def test_ndim(self):
  418. """ Verify number of dimensions """
  419. self.assertEqual(self.dset.ndim, 2)
  420. def test_shape(self):
  421. """ Verify shape """
  422. self.assertEqual(self.dset.shape, (0, 3))
  423. def test_indexlist(self):
  424. """ see issue #473 """
  425. self.assertNumpyBehavior(self.dset, self.data, np.s_[:,[0,1,2]])
  426. class Test2DFloat(TestCase):
  427. def setUp(self):
  428. TestCase.setUp(self)
  429. self.data = np.ones((5,3), dtype='f')
  430. self.dset = self.f.create_dataset('x', data=self.data)
  431. def test_ndim(self):
  432. """ Verify number of dimensions """
  433. self.assertEqual(self.dset.ndim, 2)
  434. def test_size(self):
  435. """ Verify size """
  436. self.assertEqual(self.dset.size, 15)
  437. def test_nbytes(self):
  438. """ Verify nbytes """
  439. self.assertEqual(self.dset.nbytes, 15*self.data.dtype.itemsize) # not sure if 'f' is always alias for 'f4'
  440. def test_shape(self):
  441. """ Verify shape """
  442. self.assertEqual(self.dset.shape, (5, 3))
  443. def test_indexlist(self):
  444. """ see issue #473 """
  445. self.assertNumpyBehavior(self.dset, self.data, np.s_[:,[0,1,2]])
  446. def test_index_emptylist(self):
  447. self.assertNumpyBehavior(self.dset, self.data, np.s_[:, []])
  448. self.assertNumpyBehavior(self.dset, self.data, np.s_[[]])
  449. class TestVeryLargeArray(TestCase):
  450. def setUp(self):
  451. TestCase.setUp(self)
  452. self.dset = self.f.create_dataset('x', shape=(2**15, 2**16), dtype='f4')
  453. @ut.skipIf(sys.maxsize < 2**31, 'Maximum integer size >= 2**31 required')
  454. def test_size(self):
  455. self.assertEqual(self.dset.size, 2**31)
  456. def test_read_no_fill_value(writable_file):
  457. # With FILL_TIME_NEVER, HDF5 doesn't write zeros in the output array for
  458. # unallocated chunks. If we read into uninitialized memory, it can appear
  459. # to read random values. https://github.com/h5py/h5py/issues/2069
  460. dcpl = h5py.h5p.create(h5py.h5p.DATASET_CREATE)
  461. dcpl.set_chunk((1,))
  462. dcpl.set_fill_time(h5py.h5d.FILL_TIME_NEVER)
  463. ds = h5py.Dataset(h5py.h5d.create(
  464. writable_file.id,
  465. make_name().encode("utf-8"),
  466. h5py.h5t.IEEE_F64LE,
  467. h5py.h5s.create_simple((5,)),
  468. dcpl,
  469. ))
  470. np.testing.assert_array_equal(ds[:3], np.zeros(3, np.float64))
  471. class TestBoolIndex(TestCase):
  472. """
  473. Tests for indexing with Boolean arrays
  474. """
  475. def setUp(self):
  476. super().setUp()
  477. self.arr = np.arange(9).reshape(3,-1)
  478. self.dset = self.f.create_dataset('x', data=self.arr)
  479. def test_select_first_axis(self):
  480. sel = np.s_[[False, True, False],:]
  481. self.assertNumpyBehavior(self.dset, self.arr, sel)
  482. def test_wrong_size(self):
  483. sel = np.s_[[False, True, False, False],:]
  484. with self.assertRaises(TypeError):
  485. self.dset[sel]
  486. def test_error_newaxis(writable_file):
  487. ds = writable_file.create_dataset(make_name(), data=np.arange(5))
  488. with pytest.raises(TypeError, match="newaxis"):
  489. ds[np.newaxis, :]
  490. @pytest.mark.parametrize(
  491. "arr", [
  492. np.arange(9),
  493. np.array([s.encode() for s in 'abcdefghi'], dtype=object),
  494. ]
  495. )
  496. def test_bool_selection_1d(writable_file, arr):
  497. """https://github.com/h5py/h5py/issues/2674"""
  498. arr = arr.reshape(3, 3)
  499. name = make_name()
  500. writable_file[name] = arr
  501. dset = writable_file[name]
  502. sel = np.array([True, False, True])
  503. np.testing.assert_array_equal(dset[sel], arr[sel])
  504. np.testing.assert_array_equal(dset[sel, :], arr[sel, :])
  505. class TestZeroSizeSelectionResizableDataset(TestCase):
  506. """
  507. Tests for indexing of zero Resizable Datasets
  508. see https://github.com/h5py/h5py/issues/2549
  509. """
  510. def setUp(self):
  511. super().setUp()
  512. self.dset0 = self.f.create_dataset('x', (0,), 'f4', maxshape=(None,))
  513. self.dset1 = self.f.create_dataset('y', (1,), 'f4', maxshape=(None,))
  514. def test_set_with_scalar(self):
  515. sel = np.s_[:]
  516. self.dset0[sel] = 1
  517. self.arr = np.array([], dtype=np.float32)
  518. self.assertNumpyBehavior(self.dset0, self.arr, sel)
  519. def test_set_with_array(self):
  520. sel = np.s_[:]
  521. with self.assertRaises(TypeError, msg="Can't broadcast (4,) -> (0,)"):
  522. self.dset0[sel] = np.arange(4)
  523. def test_set_zerosel_with_scalar(self):
  524. sel = np.s_[0:0]
  525. self.dset1[sel] = 1
  526. self.arr = np.array([], dtype=np.float32)
  527. self.assertNumpyBehavior(self.dset1, self.arr, sel)
  528. def test_set_zerosel_with_array(self):
  529. sel = np.s_[0:0]
  530. with self.assertRaises(TypeError, msg="Can't broadcast (4,) -> (0,)"):
  531. self.dset1[sel] = np.arange(4)