File: test_array.py

package info (click to toggle)
contourpy 1.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,688 kB
  • sloc: python: 7,998; cpp: 6,241; makefile: 13
file content (574 lines) | stat: -rw-r--r-- 23,853 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
from __future__ import annotations

import numpy as np
from numpy.testing import assert_array_almost_equal, assert_array_equal
import pytest

import contourpy.array as arr
from contourpy.types import code_dtype, offset_dtype, point_dtype

from . import util_test


def test_codes_from_offsets() -> None:
    codes = arr.codes_from_offsets(np.array([0, 3], dtype=offset_dtype))
    util_test.assert_code_array(codes, 3)
    assert_array_equal(codes, [1, 2, 79])

    codes = arr.codes_from_offsets(np.array([0, 3, 7], dtype=offset_dtype))
    util_test.assert_code_array(codes, 7)
    assert_array_equal(codes, [1, 2, 79, 1, 2, 2, 79])

    with pytest.raises(TypeError, match=r"Expected numpy array not <class 'list'>"):
        arr.codes_from_offsets([0, 3, 7])  # type: ignore[arg-type]

    with pytest.raises(ValueError, match=r"Expected numpy array of dtype <class 'numpy.uint32'>"):
        arr.codes_from_offsets(np.array([0, 3, 7], dtype=np.int64))

    with pytest.raises(ValueError, match=r"Expected numpy array of shape"):
        arr.codes_from_offsets(np.array([[0, 3], [7, 10]], dtype=offset_dtype))

    with pytest.raises(ValueError, match=r"First element of offset array must be 0"):
        arr.codes_from_offsets(np.array([1, 2], dtype=offset_dtype))


def test_codes_from_offsets_and_points() -> None:
    codes = arr.codes_from_offsets_and_points(
        np.array([0, 3], dtype=offset_dtype),
        np.array([[0, 1], [2, 3], [4, 5]], dtype=point_dtype),
    )
    util_test.assert_code_array(codes, 3)
    assert_array_equal(codes, [1, 2, 2])

    codes = arr.codes_from_offsets_and_points(
        np.array([0, 3], dtype=offset_dtype),
        np.array([[0, 1], [2, 3], [0, 1]], dtype=point_dtype),
    )
    util_test.assert_code_array(codes, 3)
    assert_array_equal(codes, [1, 2, 79])

    codes = arr.codes_from_offsets_and_points(
        np.array([0, 3, 7], dtype=offset_dtype),
        np.array([[0, 1], [2, 3], [0, 1], [5, 6], [7, 8], [9, 10], [5, 6]], dtype=point_dtype),
    )
    util_test.assert_code_array(codes, 7)
    assert_array_equal(codes, [1, 2, 79, 1, 2, 2, 79])

    with pytest.raises(TypeError, match=r"Expected numpy array not <class 'list'>"):
        arr.codes_from_offsets_and_points(
            [0, 2],  # type: ignore[arg-type]
            np.array([[0, 1], [2, 3]], dtype=point_dtype),
        )

    with pytest.raises(ValueError, match=r"Expected numpy array of dtype <class 'numpy.uint32'>"):
        arr.codes_from_offsets_and_points(
            np.array([0, 2], dtype=np.int64),
            np.array([[0, 1], [2, 3]], dtype=point_dtype),
        )

    with pytest.raises(ValueError, match=r"Expected numpy array of shape"):
        arr.codes_from_offsets_and_points(
            np.array([[0], [2]], dtype=offset_dtype),
            np.array([[0, 1], [2, 3]], dtype=point_dtype),
        )

    with pytest.raises(ValueError, match=r"First element of offset array must be 0"):
        arr.codes_from_offsets_and_points(
            np.array([1, 2], dtype=offset_dtype),
            np.array([[0, 1], [2, 3]], dtype=point_dtype),
        )

    with pytest.raises(TypeError, match=r"Expected numpy array not <class 'list'>"):
        arr.codes_from_offsets_and_points(
            np.array([0, 2],
            dtype=offset_dtype), [[0, 1], [2, 3]],  # type: ignore[arg-type]
        )

    with pytest.raises(ValueError, match=r"Expected numpy array of dtype <class 'numpy.float64'>"):
        arr.codes_from_offsets_and_points(
            np.array([0, 2], dtype=offset_dtype),
            np.array([[0, 1], [2, 3]], dtype=np.float32),
        )

    with pytest.raises(ValueError, match=r"Expected numpy array of shape"):
        arr.codes_from_offsets_and_points(
            np.array([0, 2], dtype=offset_dtype),
            np.array([0, 1, 2, 3], dtype=point_dtype),
        )


def test_codes_from_points() -> None:
    codes = arr.codes_from_points(np.array([[0, 1], [2, 3], [4, 5]], dtype=point_dtype))
    util_test.assert_code_array(codes, 3)
    assert_array_equal(codes, [1, 2, 2])

    codes = arr.codes_from_points(np.array([[0, 1], [2, 3], [0, 1]], dtype=point_dtype))
    util_test.assert_code_array(codes, 3)
    assert_array_equal(codes, [1, 2, 79])

    with pytest.raises(TypeError, match=r"Expected numpy array not <class 'list'>"):
        arr.codes_from_points([[0, 1], [2, 3], [0, 1]])  # type: ignore[arg-type]

    with pytest.raises(ValueError, match=r"Expected numpy array of dtype <class 'numpy.float64'>"):
        arr.codes_from_points(np.array([[0, 1], [2, 3], [4, 5]], dtype=np.float32))

    with pytest.raises(ValueError, match=r"Expected numpy array of shape"):
        arr.codes_from_points(np.array([0, 1, 2, 3], dtype=point_dtype))


def test_concat_codes() -> None:
    codes0 = np.array([1, 2, 79], dtype=code_dtype)
    codes1 = np.array([1, 2, 2, 2], dtype=code_dtype)

    codes = arr.concat_codes([codes0])
    util_test.assert_code_array(codes, 3)
    assert_array_equal(codes, codes0)

    codes = arr.concat_codes([codes1])
    util_test.assert_code_array(codes, 4)
    assert_array_equal(codes, codes1)

    codes = arr.concat_codes([codes0, codes1])
    util_test.assert_code_array(codes, 7)
    assert_array_equal(codes, [1, 2, 79, 1, 2, 2, 2])

    codes = arr.concat_codes([codes1, codes0])
    util_test.assert_code_array(codes, 7)
    assert_array_equal(codes, [1, 2, 2, 2, 1, 2, 79])

    with pytest.raises(ValueError, match=r"Empty list passed to concat_codes"):
        arr.concat_codes([])


def test_concat_codes_or_none() -> None:
    codes0 = np.array([1, 2, 79], dtype=code_dtype)
    codes1 = np.array([1, 2, 2, 2], dtype=code_dtype)

    assert arr.concat_codes_or_none([None]) is None
    assert arr.concat_codes_or_none([None, None]) is None
    assert arr.concat_codes_or_none([None, None, None]) is None

    codes = arr.concat_codes_or_none([None, codes0, None])
    assert codes is not None
    util_test.assert_code_array(codes, 3)
    assert_array_equal(codes, [1, 2, 79])

    codes = arr.concat_codes_or_none([None, codes0, None, codes1, None])
    assert codes is not None
    util_test.assert_code_array(codes, 7)
    assert_array_equal(codes, [1, 2, 79, 1, 2, 2, 2])

    codes = arr.concat_codes_or_none([None, codes1, None, codes0, None])
    assert codes is not None
    util_test.assert_code_array(codes, 7)
    assert_array_equal(codes, [1, 2, 2, 2, 1, 2, 79])


def test_concat_offsets() -> None:
    offsets0 = np.array([0, 2, 5], dtype=offset_dtype)
    offsets1 = np.array([0, 3, 7], dtype=offset_dtype)
    offsets2 = np.array([0, 4, 8], dtype=offset_dtype)

    offsets = arr.concat_offsets([offsets0, offsets1])
    util_test.assert_offset_array(offsets, 12)
    assert_array_equal(offsets, [0, 2, 5, 8, 12])

    offsets = arr.concat_offsets([offsets0, offsets1, offsets2])
    util_test.assert_offset_array(offsets, 20)
    assert_array_equal(offsets, [0, 2, 5, 8, 12, 16, 20])

    with pytest.raises(ValueError, match=r"Empty list passed to concat_offsets"):
        arr.concat_offsets([])


def test_concat_offsets_or_none() -> None:
    offsets0 = np.array([0, 2, 5], dtype=offset_dtype)
    offsets1 = np.array([0, 3, 7], dtype=offset_dtype)
    offsets2 = np.array([0, 4, 8], dtype=offset_dtype)

    assert arr.concat_offsets_or_none([None]) is None
    assert arr.concat_offsets_or_none([None, None]) is None
    assert arr.concat_offsets_or_none([None, None, None]) is None

    offsets = arr.concat_offsets_or_none([None, offsets0, None, offsets1, None])
    assert offsets is not None
    util_test.assert_offset_array(offsets, 12)
    assert_array_equal(offsets, [0, 2, 5, 8, 12])

    offsets = arr.concat_offsets_or_none([None, None, offsets0, offsets1, None, offsets2])
    assert offsets is not None
    util_test.assert_offset_array(offsets, 20)
    assert_array_equal(offsets, [0, 2, 5, 8, 12, 16, 20])


def test_concat_points() -> None:
    points0 = np.array([[0, 1], [2, 3], [4, 5]], dtype=point_dtype)
    points1 = np.array([[6, 7], [8, 9]], dtype=point_dtype)

    points = arr.concat_points([points0])
    util_test.assert_point_array(points)
    assert_array_almost_equal(points, points0)

    points = arr.concat_points([points0, points1])
    util_test.assert_point_array(points)
    assert_array_almost_equal(
        points,
        np.array([[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]], dtype=point_dtype),
    )

    points = arr.concat_points([points1, points0])
    util_test.assert_point_array(points)
    assert_array_almost_equal(points, [[6, 7], [8, 9], [0, 1], [2, 3], [4, 5]])

    with pytest.raises(ValueError, match=r"Empty list passed to concat_points"):
        arr.concat_points([])


def test_concat_points_or_none() -> None:
    points0 = np.array([[0, 1], [2, 3], [4, 5]], dtype=point_dtype)
    points1 = np.array([[6, 7], [8, 9]], dtype=point_dtype)

    assert arr.concat_points_or_none([None]) is None
    assert arr.concat_points_or_none([None, None]) is None
    assert arr.concat_points_or_none([None, None, None]) is None

    points = arr.concat_points_or_none([None, points0, None])
    assert points is not None
    util_test.assert_point_array(points)
    assert_array_almost_equal(points, points0)

    points = arr.concat_points_or_none([None, points0, None, points1, None])
    assert points is not None
    util_test.assert_point_array(points)
    assert_array_almost_equal(points, [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]])

    points = arr.concat_points_or_none([None, None, points1, points0, None])
    assert points is not None
    util_test.assert_point_array(points)
    assert_array_almost_equal(points, [[6, 7], [8, 9], [0, 1], [2, 3], [4, 5]])


def test_concat_points_or_none_with_nan() -> None:
    points0 = np.array([[0, 1], [2, 3], [4, 5]], dtype=point_dtype)
    points1 = np.array([[6, 7], [8, 9]], dtype=point_dtype)
    points2 = np.array([[-1, -2], [-3, -4]], dtype=point_dtype)

    assert arr.concat_points_or_none_with_nan([None]) is None
    assert arr.concat_points_or_none_with_nan([None, None]) is None
    assert arr.concat_points_or_none_with_nan([None, None, None]) is None

    points = arr.concat_points_or_none_with_nan([None, points0, None])
    assert points is not None
    util_test.assert_point_array(points)
    assert_array_almost_equal(points, points0)

    points = arr.concat_points_or_none_with_nan([None, points0, None, None, points1, None])
    assert points is not None
    util_test.assert_point_array(points, allow_nan=True)
    assert_array_almost_equal(
        points,
        np.array([[0, 1], [2, 3], [4, 5], [np.nan, np.nan], [6, 7], [8, 9]], dtype=point_dtype),
    )

    points = arr.concat_points_or_none_with_nan([None, points0, None, points1, None, None, points2])
    assert points is not None
    util_test.assert_point_array(points, allow_nan=True)
    assert_array_almost_equal(
        points,
        np.array([[0, 1], [2, 3], [4, 5], [np.nan, np.nan], [6, 7], [8, 9], [np.nan, np.nan],
                  [-1, -2], [-3, -4]], dtype=point_dtype),
    )


def test_concat_points_with_nan() -> None:
    points0 = np.array([[0, 1], [2, 3], [4, 5]], dtype=point_dtype)
    points1 = np.array([[6, 7], [8, 9]], dtype=point_dtype)
    points2 = np.array([[-1, -2], [-3, -4]], dtype=point_dtype)

    points = arr.concat_points_with_nan([points0])
    util_test.assert_point_array(points)
    assert_array_almost_equal(points, points0)

    points = arr.concat_points_with_nan([points0, points1])
    util_test.assert_point_array(points, allow_nan=True)
    assert_array_almost_equal(
        points,
        np.array([[0, 1], [2, 3], [4, 5], [np.nan, np.nan], [6, 7], [8, 9]], dtype=point_dtype),
    )

    points = arr.concat_points_with_nan([points0, points1, points2])
    util_test.assert_point_array(points, allow_nan=True)
    assert_array_almost_equal(
        points,
        np.array([[0, 1], [2, 3], [4, 5], [np.nan, np.nan], [6, 7], [8, 9], [np.nan, np.nan],
                  [-1, -2], [-3, -4]], dtype=point_dtype),
    )

    with pytest.raises(ValueError, match=r"Empty list passed to concat_points_with_nan"):
        arr.concat_points_with_nan([])


def test_insert_nan_at_offsets() -> None:
    points0 = np.array([[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]], dtype=point_dtype)

    points = arr.insert_nan_at_offsets(points0, np.array([0, 5], dtype=offset_dtype))
    util_test.assert_point_array(points, allow_nan=False)
    assert_array_almost_equal(points, points0)

    points = arr.insert_nan_at_offsets(points0, np.array([0, 1, 5], dtype=offset_dtype))
    util_test.assert_point_array(points, allow_nan=True)
    assert_array_almost_equal(
        points,
        np.array([[0, 1], [np.nan, np.nan], [2, 3], [4, 5], [6, 7], [8, 9]], dtype=point_dtype),
    )

    points = arr.insert_nan_at_offsets(points0, np.array([0, 1, 4, 5], dtype=offset_dtype))
    util_test.assert_point_array(points, allow_nan=True)
    assert_array_almost_equal(
        points,
        np.array([[0, 1], [np.nan, np.nan], [2, 3], [4, 5], [6, 7], [np.nan, np.nan], [8, 9]],
                 dtype=point_dtype),
    )

    with pytest.raises(TypeError, match=r"Expected numpy array not <class 'list'>"):
        arr.insert_nan_at_offsets(
            [[0, 1], [2, 3], [4, 5]],  # type: ignore[arg-type]
            np.array([0, 3], dtype=offset_dtype),
        )

    with pytest.raises(ValueError, match=r"Expected numpy array of dtype <class 'numpy.float64'>"):
        arr.insert_nan_at_offsets(
            np.array([[0, 1], [2, 3], [4, 5]], dtype=np.float32),
            np.array([0, 3], dtype=offset_dtype),
        )

    with pytest.raises(ValueError, match=r"Expected numpy array of shape"):
        arr.insert_nan_at_offsets(
            np.array([0, 1, 2, 3, 4, 5], dtype=point_dtype),
            np.array([0, 3], dtype=offset_dtype),
        )

    with pytest.raises(TypeError, match=r"Expected numpy array not <class 'list'>"):
        arr.insert_nan_at_offsets(
            np.array([[0, 1], [2, 3], [4, 5]], dtype=point_dtype),
            [0, 3],  # type: ignore[arg-type]
        )

    with pytest.raises(ValueError, match=r"Expected numpy array of dtype <class 'numpy.uint32'>"):
        arr.insert_nan_at_offsets(
            np.array([[0, 1], [2, 3], [4, 5]], dtype=point_dtype),
            np.array([0, 3], dtype=np.int64),
        )

    with pytest.raises(ValueError, match=r"Expected numpy array of shape"):
        arr.insert_nan_at_offsets(
            np.array([[0, 1], [2, 3], [4, 5]], dtype=point_dtype),
            np.array([[0, 3]], dtype=offset_dtype),
        )

    with pytest.raises(ValueError, match=r"First element of offset array must be 0"):
        arr.insert_nan_at_offsets(
            np.array([[0, 1], [2, 3], [4, 5]], dtype=point_dtype),
            np.array([1, 3], dtype=offset_dtype),
        )


def test_offsets_from_codes() -> None:
    offsets = arr.offsets_from_codes(np.array([1, 2, 79], dtype=code_dtype))
    util_test.assert_offset_array(offsets, 3)
    assert_array_equal(offsets, [0, 3])

    offsets = arr.offsets_from_codes(np.array([1, 2, 79, 1, 2, 2, 1, 2], dtype=code_dtype))
    util_test.assert_offset_array(offsets, 8)
    assert_array_equal(offsets, [0, 3, 6, 8])

    with pytest.raises(TypeError, match=r"Expected numpy array not <class 'list'>"):
        arr.offsets_from_codes([1, 2, 79])  # type: ignore[arg-type]

    with pytest.raises(ValueError, match=r"Expected numpy array of dtype <class 'numpy.uint8'>"):
        arr.offsets_from_codes(np.array([1, 2, 79], dtype=np.int64))

    with pytest.raises(ValueError, match=r"Expected numpy array of shape"):
        arr.offsets_from_codes(np.array([[1, 2], [2, 79]], dtype=code_dtype))

    with pytest.raises(ValueError, match=r"First element of code array must be 1"):
        arr.offsets_from_codes(np.array([2, 79], dtype=code_dtype))


def test_offsets_from_lengths() -> None:
    points0 = np.array([[0, 1], [2, 3], [4, 5]], dtype=point_dtype)
    points1 = np.array([[6, 7], [8, 9]], dtype=point_dtype)

    offsets = arr.offsets_from_lengths([points0])
    util_test.assert_offset_array(offsets, 3)
    assert_array_equal(offsets, [0, 3])

    offsets = arr.offsets_from_lengths([points0, points1])
    util_test.assert_offset_array(offsets, 5)
    assert_array_equal(offsets, [0, 3, 5])

    offsets = arr.offsets_from_lengths([points1, points0])
    util_test.assert_offset_array(offsets, 5)
    assert_array_equal(offsets, [0, 2, 5])

    with pytest.raises(ValueError, match=r"Empty list passed to offsets_from_lengths"):
        arr.offsets_from_lengths([])


def test_outer_offsets_from_list_of_codes() -> None:
    codes0 = np.array([1, 2, 79, 1, 2], dtype=code_dtype)
    codes1 = np.array([1, 2, 2, 2, 1, 2, 1, 2, 2], dtype=code_dtype)

    outer_offsets = arr.outer_offsets_from_list_of_codes([codes0])
    util_test.assert_offset_array(outer_offsets, 2)
    assert_array_equal(outer_offsets, [0, 2])

    outer_offsets = arr.outer_offsets_from_list_of_codes([codes1])
    util_test.assert_offset_array(outer_offsets, 3)
    assert_array_equal(outer_offsets, [0, 3])

    outer_offsets = arr.outer_offsets_from_list_of_codes([codes0, codes1])
    util_test.assert_offset_array(outer_offsets, 5)
    assert_array_equal(outer_offsets, [0, 2, 5])

    outer_offsets = arr.outer_offsets_from_list_of_codes([codes1, codes0])
    util_test.assert_offset_array(outer_offsets, 5)
    assert_array_equal(outer_offsets, [0, 3, 5])

    with pytest.raises(ValueError, match=r"Empty list passed to outer_offsets_from_list_of_codes"):
        arr.outer_offsets_from_list_of_codes([])


def test_outer_offsets_from_list_of_offsets() -> None:
    offsets0 = np.array([0, 3, 5], dtype=offset_dtype)
    offsets1 = np.array([0, 4, 9, 11], dtype=offset_dtype)

    outer_offsets = arr.outer_offsets_from_list_of_offsets([offsets0])
    util_test.assert_offset_array(outer_offsets, 2)
    assert_array_equal(outer_offsets, [0, 2])

    outer_offsets = arr.outer_offsets_from_list_of_offsets([offsets1])
    util_test.assert_offset_array(outer_offsets, 3)
    assert_array_equal(outer_offsets, [0, 3])

    outer_offsets = arr.outer_offsets_from_list_of_offsets([offsets0, offsets1])
    util_test.assert_offset_array(outer_offsets, 5)
    assert_array_equal(outer_offsets, [0, 2, 5])

    outer_offsets = arr.outer_offsets_from_list_of_offsets([offsets1, offsets0])
    util_test.assert_offset_array(outer_offsets, 5)
    assert_array_equal(outer_offsets, [0, 3, 5])

    with pytest.raises(ValueError,
                       match=r"Empty list passed to outer_offsets_from_list_of_offsets"):
        arr.outer_offsets_from_list_of_offsets([])


def test_remove_nan() -> None:
    points0 = np.array([[1.1, 2.2], [3.3, 4.4], [1.1, 2.2]], dtype=point_dtype)
    points1 = np.array([[0, 1], [2, 3], [4, 5], [np.nan, np.nan], [6, 7], [8, 9], [np.nan, np.nan],
                        [-1, -2], [-3, -4], [-5, -6]], dtype=point_dtype)

    points, offsets = arr.remove_nan(points0)
    util_test.assert_point_array(points, allow_nan=False)
    util_test.assert_offset_array(offsets, 3)
    assert_array_almost_equal(points, points0)
    assert_array_equal(offsets, [0, 3])

    points, offsets = arr.remove_nan(points1)
    util_test.assert_point_array(points, allow_nan=True)
    util_test.assert_offset_array(offsets, 8)
    assert_array_almost_equal(
        points, [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [-1, -2], [-3, -4], [-5, -6]],
    )
    assert_array_equal(offsets, [0, 3, 5, 8])


def test_split_codes_by_offsets() -> None:
    codes = np.array([1, 2, 1, 2, 79], dtype=code_dtype)

    list_of_codes = arr.split_codes_by_offsets(codes, np.array([0, 5], dtype=offset_dtype))
    assert isinstance(list_of_codes, list)
    assert len(list_of_codes) == 1
    util_test.assert_code_array(list_of_codes[0], 5)
    assert_array_equal(list_of_codes[0], codes)

    list_of_codes = arr.split_codes_by_offsets(codes, np.array([0, 2, 5], dtype=offset_dtype))
    assert isinstance(list_of_codes, list)
    assert len(list_of_codes) == 2
    util_test.assert_code_array(list_of_codes[0], 2)
    util_test.assert_code_array(list_of_codes[1], 3)
    assert_array_equal(list_of_codes[0], [1, 2])
    assert_array_equal(list_of_codes[1], [1, 2, 79])

    with pytest.raises(TypeError, match=r"Expected numpy array not <class 'list'>"):
       arr.split_codes_by_offsets(codes, [0, 5])  # type: ignore[arg-type]

    with pytest.raises(ValueError, match=r"Expected numpy array of dtype <class 'numpy.uint32'>"):
        arr.codes_from_offsets(np.array([0, 5], dtype=np.int64))

    with pytest.raises(ValueError, match=r"Expected numpy array of shape"):
        arr.codes_from_offsets(np.array([[0, 5]], dtype=offset_dtype))

    with pytest.raises(ValueError, match=r"First element of offset array must be 0"):
        arr.codes_from_offsets(np.array([1, 2], dtype=offset_dtype))


def test_split_points_at_nan() -> None:
    points0 = np.array([[1.1, 2.2], [3.3, 4.4]], dtype=point_dtype)
    points1 = np.array([[0, 1], [2, 3], [np.nan, np.nan], [4, 5], [6, 7], [8, 9], [np.nan, np.nan],
                        [10, 11], [12, 13]], dtype=point_dtype)

    list_of_points = arr.split_points_at_nan(points0)
    assert isinstance(list_of_points, list)
    assert len(list_of_points) == 1
    util_test.assert_point_array(list_of_points[0])
    assert_array_almost_equal(list_of_points[0], points0)

    list_of_points = arr.split_points_at_nan(points1)
    assert isinstance(list_of_points, list)
    assert len(list_of_points) == 3
    for points in list_of_points:
        util_test.assert_point_array(points)
    assert_array_almost_equal(list_of_points[0], [[0, 1], [2, 3]])
    assert_array_almost_equal(list_of_points[1], [[4, 5], [6, 7], [8, 9]])
    assert_array_almost_equal(list_of_points[2], [[10, 11], [12, 13]])

    with pytest.raises(TypeError, match=r"Expected numpy array not <class 'list'>"):
        arr.split_points_at_nan([[0, 1], [2, 3]])  # type: ignore[arg-type]

    with pytest.raises(ValueError, match=r"Expected numpy array of dtype <class 'numpy.float64'>"):
        arr.split_points_at_nan(np.array([[0, 1], [2, 3]], dtype=np.float32))

    with pytest.raises(ValueError, match=r"Expected numpy array of shape"):
        arr.split_points_at_nan(np.array([[0, 1, 2, 3]], dtype=point_dtype))


def test_split_points_by_offsets() -> None:
    points = np.array([[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11]], dtype=point_dtype)

    list_of_points = arr.split_points_by_offsets(points, np.array([0, 6], dtype=offset_dtype))
    assert isinstance(list_of_points, list)
    assert len(list_of_points) == 1
    util_test.assert_point_array(list_of_points[0])
    assert_array_almost_equal(list_of_points[0], points)

    list_of_points = arr.split_points_by_offsets(points, np.array([0, 2, 6], dtype=offset_dtype))
    assert isinstance(list_of_points, list)
    assert len(list_of_points) == 2
    util_test.assert_point_array(list_of_points[0])
    util_test.assert_point_array(list_of_points[1])
    assert_array_almost_equal(list_of_points[0], [[0, 1], [2, 3]])
    assert_array_almost_equal(list_of_points[1], [[4, 5], [6, 7], [8, 9], [10, 11]])

    with pytest.raises(TypeError, match=r"Expected numpy array not <class 'list'>"):
       arr.split_points_by_offsets(points, [0, 6])  # type: ignore[arg-type]

    with pytest.raises(ValueError, match=r"Expected numpy array of dtype <class 'numpy.uint32'>"):
       arr.split_points_by_offsets(points, np.array([0, 6], dtype=np.int64))

    with pytest.raises(ValueError, match=r"Expected numpy array of shape"):
       arr.split_points_by_offsets(points, np.array([[0, 6]], dtype=offset_dtype))

    with pytest.raises(ValueError, match=r"First element of offset array must be 0"):
       arr.split_points_by_offsets(points, np.array([1, 6], dtype=offset_dtype))