Skip to content

Commit 1cf587f

Browse files
test: check remap and renumber for in_place support
1 parent deb18f8 commit 1cf587f

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

automated_test.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,21 @@ def test_empty_renumber():
1717
assert np.all(data2 == [])
1818
assert remapdict == {}
1919

20-
def test_1d_renumber():
20+
@pytest.mark.parametrize("in_place", [False, True])
21+
def test_1d_renumber(in_place):
2122
for dtype in DTYPES:
2223
print(dtype)
2324
data = np.arange(8).astype(dtype)
2425
data = np.flip(data)
2526

2627
data2 = np.copy(data)
27-
data2, remapdict = fastremap.renumber(data2, preserve_zero=False)
28+
data2, remapdict = fastremap.renumber(data2, preserve_zero=False, in_place=in_place)
2829

2930
assert np.all(data2 == np.arange(1,9))
3031
assert len(remapdict) > 0
3132

3233
data2 = np.copy(data)
33-
data2, remapdict = fastremap.renumber(data2, preserve_zero=True)
34+
data2, remapdict = fastremap.renumber(data2, preserve_zero=True, in_place=in_place)
3435

3536
assert data2[-1] == 0
3637
assert np.all(data2 == [1,2,3,4,5,6,7,0])
@@ -40,17 +41,22 @@ def test_1d_renumber():
4041
data = np.flip(data)
4142

4243
data2 = np.copy(data)
43-
data2, remapdict = fastremap.renumber(data2, preserve_zero=False)
44+
data2, remapdict = fastremap.renumber(data2, preserve_zero=False, in_place=in_place)
4445

4546
assert np.all(data2 == [1,1,1,1,1,1,1,2])
4647
assert len(remapdict) > 0
4748

4849
data2 = np.copy(data)
49-
data2, remapdict = fastremap.renumber(data2, preserve_zero=True)
50+
data2, remapdict = fastremap.renumber(data2, preserve_zero=True, in_place=in_place)
5051

5152
assert np.all(data2 == [1,1,1,1,1,1,1,0])
5253
assert len(remapdict) > 0
5354

55+
data2 = np.copy(data)
56+
data2.flags.writeable = False
57+
data2, remapdict = fastremap.renumber(data2, preserve_zero=True, in_place=in_place)
58+
59+
5460
def test_2d_renumber():
5561
for dtype in DTYPES:
5662
data = np.array([
@@ -147,7 +153,8 @@ def test_renumber_no_preserve_zero():
147153

148154

149155
@pytest.mark.parametrize("dtype", list(DTYPES) + [ np.float32, np.float64 ])
150-
def test_remap_1d(dtype):
156+
@pytest.mark.parametrize("in_place", [ False, True ])
157+
def test_remap_1d(dtype, in_place):
151158
empty = fastremap.remap([], {})
152159
assert len(empty) == 0
153160

@@ -160,17 +167,17 @@ def test_remap_1d(dtype):
160167
5: 5,
161168
}
162169

163-
result = fastremap.remap(np.copy(data), remap, preserve_missing_labels=False)
170+
result = fastremap.remap(np.copy(data), remap, preserve_missing_labels=False, in_place=in_place)
164171
assert np.all(result == [10, 30, 30, 30, 15, 0, 5])
165172

166173
del remap[2]
167174
try:
168-
result = fastremap.remap(np.copy(data), remap, preserve_missing_labels=False)
175+
result = fastremap.remap(np.copy(data), remap, preserve_missing_labels=False, in_place=in_place)
169176
assert False
170177
except KeyError:
171178
pass
172179

173-
result = fastremap.remap(np.copy(data), remap, preserve_missing_labels=True)
180+
result = fastremap.remap(np.copy(data), remap, preserve_missing_labels=True, in_place=in_place)
174181
assert np.all(result == [10, 2, 2, 2, 15, 0, 5])
175182

176183
@pytest.mark.parametrize("dtype", DTYPES)

0 commit comments

Comments
 (0)