-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import numpy as np | ||
import pytest | ||
from numpy.testing import assert_equal | ||
|
||
from arcae.lib.arrow_tables import merge_np_partitions | ||
|
||
|
||
@pytest.mark.parametrize("seed", [42]) | ||
@pytest.mark.parametrize("n, chunk", [(100, 33), (125, 42)]) | ||
def test_merge_np_partitions(seed, n, chunk): | ||
rng = np.random.default_rng(seed=seed) | ||
ddid = rng.integers(0, 10, n) | ||
field_id = rng.integers(0, 10, n) | ||
time = rng.random(n) | ||
interval = rng.random(n) | ||
ant1 = rng.integers(0, 10, n) | ||
ant2 = rng.integers(0, 10, n) | ||
row = rng.integers(0, 10, n) | ||
|
||
partitions = [ | ||
{ | ||
"DATA_DESC_ID": ddid[start : start + chunk], | ||
"FIELD_ID": field_id[start : start + chunk], | ||
"TIME": time[start : start + chunk], | ||
"ANTENNA1": ant1[start : start + chunk], | ||
"ANTENNA2": ant2[start : start + chunk], | ||
"INTERVAL": interval[start : start + chunk], | ||
"ROW": row[start : start + chunk], | ||
} | ||
for start in range(0, n, chunk) | ||
] | ||
|
||
sorts = [np.lexsort(tuple(reversed(p.values()))) for p in partitions] | ||
partitions = [{k: v[s] for k, v in p.items()} for p, s in zip(partitions, sorts)] | ||
|
||
expected = { | ||
"DATA_DESC_ID": ddid, | ||
"FIELD_ID": field_id, | ||
"TIME": time, | ||
"ANTENNA1": ant1, | ||
"ANTENNA2": ant2, | ||
"INTERVAL": interval, | ||
"ROW": row, | ||
} | ||
|
||
sort = np.lexsort(tuple(reversed(expected.values()))) | ||
expected = {k: v[sort] for k, v in expected.items()} | ||
merged = merge_np_partitions(partitions) | ||
assert_equal(merged, expected) | ||
|
||
|
||
@pytest.mark.parametrize("seed", [42]) | ||
@pytest.mark.parametrize("n, chunk", [(100, 33)]) | ||
def test_merge_fail_1d(seed, n, chunk): | ||
rng = np.random.default_rng(seed=seed) | ||
ddid = rng.integers(0, 10, 100) | ||
field_id = rng.integers(0, 10, (100, 4)) | ||
|
||
partitions = [ | ||
{ | ||
"DATA_DESC_ID": ddid[start : start + chunk], | ||
"FIELD_ID": field_id[start : start + chunk], | ||
} | ||
for start in range(0, n, chunk) | ||
] | ||
|
||
with pytest.raises(ValueError, match="Array must be 1-dimensional"): | ||
merge_np_partitions(partitions) | ||
|
||
|
||
@pytest.mark.parametrize("seed", [42]) | ||
@pytest.mark.parametrize("n, chunk", [(100, 33)]) | ||
def test_merge_fail_array_length(seed, n, chunk): | ||
rng = np.random.default_rng(seed=seed) | ||
ddid = rng.integers(0, 10, 100) | ||
field_id = rng.integers(0, 10, 50) | ||
|
||
partitions = [ | ||
{ | ||
"DATA_DESC_ID": ddid[start : start + chunk], | ||
"FIELD_ID": field_id[start : start + chunk], | ||
} | ||
for start in range(0, n, chunk) | ||
] | ||
|
||
with pytest.raises(ValueError, match="Array lengths do not match"): | ||
merge_np_partitions(partitions) |