(self)
| 3456 | open_mode = "w" |
| 3457 | |
| 3458 | def test01(self): |
| 3459 | np.random.seed(2) |
| 3460 | n = 700_000 |
| 3461 | cs = 50_000 |
| 3462 | nchunks = n // cs |
| 3463 | |
| 3464 | arr = np.zeros( |
| 3465 | (n,), dtype=[("index", "i8"), ("o", "i8"), ("value", "f8")] |
| 3466 | ) |
| 3467 | arr["index"] = np.arange(n) |
| 3468 | arr["o"] = np.random.randint(-20_000, -15_000, size=n) |
| 3469 | arr["value"] = np.random.randn(n) |
| 3470 | |
| 3471 | node = self.h5file.create_group("/", "foo") |
| 3472 | table = self.h5file.create_table( |
| 3473 | node, |
| 3474 | "table", |
| 3475 | dict( |
| 3476 | index=tb.Int64Col(), |
| 3477 | o=tb.Int64Col(), |
| 3478 | value=tb.FloatCol(shape=()), |
| 3479 | ), |
| 3480 | expectedrows=10_000_000, |
| 3481 | ) |
| 3482 | |
| 3483 | table.append(arr) |
| 3484 | |
| 3485 | self._reopen("a") |
| 3486 | |
| 3487 | v1 = np.unique(arr["o"])[0] |
| 3488 | v2 = np.unique(arr["o"])[1] |
| 3489 | res = np.array([v1, v2]) |
| 3490 | selector = f"((o == {v1}) | (o == {v2}))" |
| 3491 | if common.verbose: |
| 3492 | print("selecting values: %s" % selector) |
| 3493 | |
| 3494 | table = self.h5file.root.foo.table |
| 3495 | |
| 3496 | result = np.unique(table.read_where(selector)["o"]) |
| 3497 | np.testing.assert_almost_equal(result, res) |
| 3498 | if common.verbose: |
| 3499 | print("select entire table:") |
| 3500 | print(f"result: {result}\texpected: {res}") |
| 3501 | |
| 3502 | if common.verbose: |
| 3503 | print("index the column o") |
| 3504 | table.cols.o.create_index() # this was triggering the issue |
| 3505 | |
| 3506 | if common.verbose: |
| 3507 | print("select via chunks") |
| 3508 | for i in range(nchunks): |
| 3509 | result = table.read_where( |
| 3510 | selector, start=i * cs, stop=(i + 1) * cs |
| 3511 | ) |
| 3512 | result = np.unique(result["o"]) |
| 3513 | np.testing.assert_almost_equal(np.unique(result), res) |
| 3514 | if common.verbose: |
| 3515 | print(f"result: {result}\texpected: {res}") |
nothing calls this directly
no test coverage detected