arraykit 0.7.1__tar.gz → 0.7.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. {arraykit-0.7.1/arraykit.egg-info → arraykit-0.7.2}/PKG-INFO +1 -1
  2. {arraykit-0.7.1 → arraykit-0.7.2}/README.rst +6 -0
  3. {arraykit-0.7.1 → arraykit-0.7.2/arraykit.egg-info}/PKG-INFO +1 -1
  4. {arraykit-0.7.1 → arraykit-0.7.2}/setup.py +1 -1
  5. {arraykit-0.7.1 → arraykit-0.7.2}/src/_arraykit.c +37 -4
  6. {arraykit-0.7.1 → arraykit-0.7.2}/test/test_util.py +47 -23
  7. {arraykit-0.7.1 → arraykit-0.7.2}/LICENSE.txt +0 -0
  8. {arraykit-0.7.1 → arraykit-0.7.2}/MANIFEST.in +0 -0
  9. {arraykit-0.7.1 → arraykit-0.7.2}/arraykit.egg-info/SOURCES.txt +0 -0
  10. {arraykit-0.7.1 → arraykit-0.7.2}/arraykit.egg-info/dependency_links.txt +0 -0
  11. {arraykit-0.7.1 → arraykit-0.7.2}/arraykit.egg-info/requires.txt +0 -0
  12. {arraykit-0.7.1 → arraykit-0.7.2}/arraykit.egg-info/top_level.txt +0 -0
  13. {arraykit-0.7.1 → arraykit-0.7.2}/setup.cfg +0 -0
  14. {arraykit-0.7.1 → arraykit-0.7.2}/src/__init__.py +0 -0
  15. {arraykit-0.7.1 → arraykit-0.7.2}/src/__init__.pyi +0 -0
  16. {arraykit-0.7.1 → arraykit-0.7.2}/src/py.typed +0 -0
  17. {arraykit-0.7.1 → arraykit-0.7.2}/test/test_array_go.py +0 -0
  18. {arraykit-0.7.1 → arraykit-0.7.2}/test/test_block_index.py +0 -0
  19. {arraykit-0.7.1 → arraykit-0.7.2}/test/test_delimited_to_arrays.py +0 -0
  20. {arraykit-0.7.1 → arraykit-0.7.2}/test/test_delimited_to_arrays_integration.py +0 -0
  21. {arraykit-0.7.1 → arraykit-0.7.2}/test/test_delimited_to_arrays_property.py +0 -0
  22. {arraykit-0.7.1 → arraykit-0.7.2}/test/test_nonzero_1d.py +0 -0
  23. {arraykit-0.7.1 → arraykit-0.7.2}/test/test_nonzero_1d_property.py +0 -0
  24. {arraykit-0.7.1 → arraykit-0.7.2}/test/test_pyi.py +0 -0
  25. {arraykit-0.7.1 → arraykit-0.7.2}/test/test_split_after_count.py +0 -0
  26. {arraykit-0.7.1 → arraykit-0.7.2}/test/test_tri_map.py +0 -0
  27. {arraykit-0.7.1 → arraykit-0.7.2}/test/test_type_discovery.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: arraykit
3
- Version: 0.7.1
3
+ Version: 0.7.2
4
4
  Summary: Array utilities for StaticFrame
5
5
  Home-page: https://github.com/static-frame/arraykit
6
6
  Author: Christopher Ariza, Brandt Bucher, Charles Burkland
@@ -38,6 +38,12 @@ What is New in ArrayKit
38
38
  -------------------------
39
39
 
40
40
 
41
+ 0.7.2
42
+ ............
43
+
44
+ Improved ``array_to_tuple_array()`` and ``array_to_tuple_iter()`` to preserve ``tuple`` in 1D arrays.
45
+
46
+
41
47
  0.7.1
42
48
  ............
43
49
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: arraykit
3
- Version: 0.7.1
3
+ Version: 0.7.2
4
4
  Summary: Array utilities for StaticFrame
5
5
  Home-page: https://github.com/static-frame/arraykit
6
6
  Author: Christopher Ariza, Brandt Bucher, Charles Burkland
@@ -5,7 +5,7 @@ from setuptools import Extension # type: ignore
5
5
  from setuptools import setup
6
6
  from pathlib import Path
7
7
 
8
- AK_VERSION = '0.7.1'
8
+ AK_VERSION = '0.7.2'
9
9
 
10
10
  def get_long_description() -> str:
11
11
  return '''The ArrayKit library provides utilities for creating and transforming NumPy arrays, implementing performance-critical StaticFrame operations as Python C extensions.
@@ -3573,7 +3573,7 @@ array_to_tuple_array(PyObject *Py_UNUSED(m), PyObject *a)
3573
3573
  i++;
3574
3574
  }
3575
3575
  }
3576
- else { // ndim == 1
3576
+ else if (PyArray_TYPE(input_array) != NPY_OBJECT) { // ndim == 1, not object
3577
3577
  while (p < p_end) {
3578
3578
  tuple = PyTuple_New(1);
3579
3579
  if (tuple == NULL) {
@@ -3590,6 +3590,24 @@ array_to_tuple_array(PyObject *Py_UNUSED(m), PyObject *a)
3590
3590
  i++;
3591
3591
  }
3592
3592
  }
3593
+ else { // ndim == 1, object
3594
+ while (p < p_end) {
3595
+ item = *(PyObject**)PyArray_GETPTR1(input_array, i);
3596
+ Py_INCREF(item); // always incref
3597
+ if (PyTuple_Check(item)) {
3598
+ tuple = item; // do not double pack
3599
+ }
3600
+ else {
3601
+ tuple = PyTuple_New(1);
3602
+ if (tuple == NULL) {
3603
+ goto error;
3604
+ }
3605
+ PyTuple_SET_ITEM(tuple, 0, item); // steals reference to item
3606
+ }
3607
+ *p++ = tuple; // assign with new ref, no incr needed
3608
+ i++;
3609
+ }
3610
+ }
3593
3611
  PyArray_CLEARFLAGS((PyArrayObject *)output, NPY_ARRAY_WRITEABLE);
3594
3612
  return output;
3595
3613
  error:
@@ -3664,10 +3682,10 @@ ATT_iternext(ATTObject *self) {
3664
3682
  Py_DECREF(tuple);
3665
3683
  return NULL;
3666
3684
  }
3667
- PyTuple_SET_ITEM(tuple, j, item); // steals reference to item
3685
+ PyTuple_SET_ITEM(tuple, j, item); // steals ref
3668
3686
  }
3669
3687
  }
3670
- else { // ndim == 1
3688
+ else if (PyArray_TYPE(array) != NPY_OBJECT) { // ndim == 1, not object
3671
3689
  tuple = PyTuple_New(1);
3672
3690
  if (tuple == NULL) {
3673
3691
  return NULL;
@@ -3677,7 +3695,22 @@ ATT_iternext(ATTObject *self) {
3677
3695
  Py_DECREF(tuple);
3678
3696
  return NULL;
3679
3697
  }
3680
- PyTuple_SET_ITEM(tuple, 0, item); // steals reference to item
3698
+ PyTuple_SET_ITEM(tuple, 0, item); // steals ref
3699
+ }
3700
+ else { // ndim == 1, object
3701
+ item = *(PyObject**)PyArray_GETPTR1(array, i);
3702
+ Py_INCREF(item); // always incref
3703
+ if (PyTuple_Check(item)) {
3704
+ tuple = item; // do not double pack
3705
+ }
3706
+ else {
3707
+ tuple = PyTuple_New(1);
3708
+ if (tuple == NULL) {
3709
+ Py_DECREF(item);
3710
+ return NULL;
3711
+ }
3712
+ PyTuple_SET_ITEM(tuple, 0, item); // steals ref
3713
+ }
3681
3714
  }
3682
3715
  self->pos++;
3683
3716
  return tuple;
@@ -286,33 +286,47 @@ class TestUnit(unittest.TestCase):
286
286
  a2 = array_deepcopy(a1, ())
287
287
 
288
288
  #---------------------------------------------------------------------------
289
- def test_array2d_to_array1d_1d_a(self) -> None:
289
+ def test_array_to_tuple_array_1d_a(self) -> None:
290
290
  a1 = np.arange(10)
291
291
  a2 = array_to_tuple_array(a1)
292
292
  self.assertEqual(a2.tolist(), [(0,), (1,), (2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,)])
293
293
 
294
- def test_array2d_to_array1d_1d_b(self) -> None:
294
+ def test_array_to_tuple_array_1d_b(self) -> None:
295
295
  a1 = np.array(['aaa', 'b', 'ccc'])
296
296
  a2 = array_to_tuple_array(a1)
297
297
  self.assertEqual(a2.tolist(), [('aaa',), ('b',), ('ccc',)])
298
298
 
299
- def test_array2d_to_array1d_1d_c(self) -> None:
299
+ def test_array_to_tuple_array_1d_c(self) -> None:
300
300
  a1 = np.array([None, 'b', 30])
301
301
  a2 = array_to_tuple_array(a1)
302
302
  self.assertEqual(a2.tolist(), [(None,), ('b',), (30,)])
303
303
 
304
- def test_array2d_to_array1d_1d_d(self) -> None:
304
+ def test_array_to_tuple_array_1d_d(self) -> None:
305
305
  a1 = np.array([('a', 10), ('b', 30), ('c', 5)], dtype=object)
306
- a2 = array_to_tuple_array(a1)
306
+ a2 = array_to_tuple_array(a1) # from 2d
307
307
  self.assertEqual(a2.tolist(), [('a', 10), ('b', 30), ('c', 5)])
308
+ a3 = array_to_tuple_array(a2) # from 1d
309
+ self.assertEqual(a3.tolist(), [('a', 10), ('b', 30), ('c', 5)])
308
310
 
309
- def test_array2d_to_array1d_1d_e(self) -> None:
311
+ def test_array_to_tuple_array_1d_e(self) -> None:
310
312
  a1 = np.array([True, False, True], dtype=object)
311
313
  a2 = array_to_tuple_array(a1)
312
314
  self.assertIs(a2[0][0].__class__, bool)
313
315
  self.assertEqual(a2.tolist(), [(True,), (False,), (True,)])
314
316
 
315
- def test_array2d_to_array1d_b(self) -> None:
317
+ def test_array_to_tuple_array_1d_f(self) -> None:
318
+ a1 = np.array([None, None, None], dtype=object)
319
+ a1[0] = 3
320
+ a1[1] = ('a', 30)
321
+ a1[2] = (None, True, 90000000)
322
+
323
+ a2 = array_to_tuple_array(a1)
324
+ self.assertEqual(a2.tolist(), [(3,), ('a', 30), (None, True, 90000000)])
325
+
326
+ a3 = array_to_tuple_array(a2)
327
+ self.assertEqual(a3.tolist(), [(3,), ('a', 30), (None, True, 90000000)])
328
+
329
+ def test_array_to_tuple_array_b(self) -> None:
316
330
  a1 = np.arange(10, dtype=np.int64).reshape(5, 2)
317
331
  result = array_to_tuple_array(a1)
318
332
  assert isinstance(result[0], tuple)
@@ -322,35 +336,35 @@ class TestUnit(unittest.TestCase):
322
336
  self.assertEqual(tuple(result), ((0, 1), (2, 3), (4, 5), (6, 7), (8, 9)))
323
337
 
324
338
 
325
- def test_array2d_to_array1d_c(self) -> None:
339
+ def test_array_to_tuple_array_c(self) -> None:
326
340
  a1 = np.array([["a", "b"], ["ccc", "ddd"], ["ee", "ff"]])
327
341
  a2 = array_to_tuple_array(a1)
328
342
  self.assertEqual(a2.tolist(), [('a', 'b'), ('ccc', 'ddd'), ('ee', 'ff')])
329
343
 
330
- def test_array2d_to_array1d_d(self) -> None:
344
+ def test_array_to_tuple_array_d(self) -> None:
331
345
  a1 = np.array([[3, 5], [10, 20], [7, 2]], dtype=np.uint8)
332
346
  a2 = array_to_tuple_array(a1)
333
347
  self.assertEqual(a2.tolist(), [(3, 5), (10, 20), (7, 2)])
334
348
  self.assertIs(type(a2[0][0]), np.uint8)
335
349
 
336
- def test_array2d_to_array1d_e(self) -> None:
350
+ def test_array_to_tuple_array_e(self) -> None:
337
351
  a1 = np.arange(20, dtype=np.int64).reshape(4, 5)
338
352
  result = array_to_tuple_array(a1)
339
353
  self.assertEqual(result.tolist(), [(0, 1, 2, 3, 4), (5, 6, 7, 8, 9), (10, 11, 12, 13, 14), (15, 16, 17, 18, 19)])
340
354
 
341
355
  #---------------------------------------------------------------------------
342
- def test_array2d_tuple_iter_a(self) -> None:
356
+ def test_array_to_tuple_iter_a(self) -> None:
343
357
  a1 = np.arange(20, dtype=np.int64).reshape(4, 5)
344
358
  result = list(array_to_tuple_iter(a1))
345
359
  self.assertEqual(len(result), 4)
346
360
  self.assertEqual(result, [(0, 1, 2, 3, 4), (5, 6, 7, 8, 9), (10, 11, 12, 13, 14), (15, 16, 17, 18, 19)])
347
361
 
348
- def test_array2d_tuple_iter_b(self) -> None:
362
+ def test_array_to_tuple_iter_b(self) -> None:
349
363
  a1 = np.arange(20, dtype=np.int64).reshape(10, 2)
350
364
  result = list(array_to_tuple_iter(a1))
351
365
  self.assertEqual(result, [(0, 1), (2, 3), (4, 5), (6, 7), (8, 9), (10, 11), (12, 13), (14, 15), (16, 17), (18, 19)])
352
366
 
353
- def test_array2d_tuple_iter_c(self) -> None:
367
+ def test_array_to_tuple_iter_c(self) -> None:
354
368
  a1 = np.array([['aaa', 'bb'], ['c', 'dd'], ['ee', 'fffff']])
355
369
  it = array_to_tuple_iter(a1)
356
370
  self.assertEqual(it.__length_hint__(), 3)
@@ -363,20 +377,20 @@ class TestUnit(unittest.TestCase):
363
377
  with self.assertRaises(StopIteration):
364
378
  next(it)
365
379
 
366
- def test_array2d_tuple_iter_d(self) -> None:
380
+ def test_array_to_tuple_iter_d(self) -> None:
367
381
  a1 = np.array([['aaa', 'bb'], ['c', 'dd'], ['ee', 'fffff']])
368
382
  it = array_to_tuple_iter(a1)
369
383
  # __reversed__ not implemented
370
384
  with self.assertRaises(TypeError):
371
385
  reversed(it)
372
386
 
373
- def test_array2d_tuple_iter_e(self) -> None:
387
+ def test_array_to_tuple_iter_e(self) -> None:
374
388
  a1 = np.array([[None, 'bb'], [None, 'dd'], [3, None]])
375
389
  it = array_to_tuple_iter(a1)
376
390
  del a1
377
391
  self.assertEqual(list(it), [(None, 'bb'), (None, 'dd'), (3, None)])
378
392
 
379
- def test_array2d_tuple_iter_f(self) -> None:
393
+ def test_array_to_tuple_iter_f(self) -> None:
380
394
  a1 = np.array([[None, 'bb'], [None, 'dd'], [3, None]])
381
395
  it1 = array_to_tuple_iter(a1)
382
396
  del a1
@@ -384,7 +398,7 @@ class TestUnit(unittest.TestCase):
384
398
  self.assertEqual(list(it1), [(None, 'bb'), (None, 'dd'), (3, None)])
385
399
  self.assertEqual(list(it2), []) # expected behavior
386
400
 
387
- def test_array2d_tuple_iter_g(self) -> None:
401
+ def test_array_to_tuple_iter_g(self) -> None:
388
402
  a1 = np.array([[None, 'bb'], [None, 'dd'], [3, None]])
389
403
  it1 = array_to_tuple_iter(a1)
390
404
  it2 = array_to_tuple_iter(a1)
@@ -392,23 +406,33 @@ class TestUnit(unittest.TestCase):
392
406
  self.assertEqual(list(it1), [(None, 'bb'), (None, 'dd'), (3, None)])
393
407
  self.assertEqual(list(it2), [(None, 'bb'), (None, 'dd'), (3, None)])
394
408
 
395
- def test_array2d_tuple_iter_1d_a(self) -> None:
409
+ def test_array_to_tuple_iter_1d_a(self) -> None:
396
410
  a1 = np.array(['bb', 'c', 'aaa'])
397
411
  result = list(array_to_tuple_iter(a1))
398
412
  self.assertEqual(len(result), 3)
399
413
  self.assertEqual(result, [('bb',), ('c',), ('aaa',)])
400
414
 
401
- def test_array2d_tuple_iter_1d_b(self) -> None:
415
+ def test_array_to_tuple_iter_1d_b(self) -> None:
402
416
  a1 = np.array([20, -1, 8])
403
417
  result = list(array_to_tuple_iter(a1))
404
418
  self.assertEqual(len(result), 3)
405
419
  self.assertEqual(result, [(20,), (-1,), (8,)])
406
420
 
407
- def test_array2d_tuple_iter_1d_c(self) -> None:
421
+ def test_array_to_tuple_iter_1d_c(self) -> None:
408
422
  a1 = np.array([('a', 4), ('c', -1), ('d', 8)], dtype=object)
409
- result = list(array_to_tuple_iter(a1))
410
- self.assertEqual(len(result), 3)
411
- self.assertEqual(result, [('a', 4), ('c', -1), ('d', 8)])
423
+ a2 = list(array_to_tuple_iter(a1))
424
+ self.assertEqual(len(a2), 3)
425
+ self.assertEqual(a2, [('a', 4), ('c', -1), ('d', 8)])
426
+
427
+ def test_array_to_tuple_iter_1d_d(self) -> None:
428
+ a1 = np.array([None, None, None], dtype=object)
429
+ a1[0] = 3
430
+ a1[1] = ('a', 30)
431
+ a1[2] = (None, True, 90000000)
432
+
433
+ a2 = list(array_to_tuple_iter(a1))
434
+ self.assertEqual(a2, [(3,), ('a', 30), (None, True, 90000000)])
435
+
412
436
 
413
437
  #---------------------------------------------------------------------------
414
438
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes