Skip to content

Commit 83ecf71

Browse files
committed
renamed functions
1 parent efbad1f commit 83ecf71

File tree

7 files changed

+45
-45
lines changed

7 files changed

+45
-45
lines changed

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ What is New in ArrayKit
4040
0.7.0
4141
............
4242

43-
Added ``array2d_to_array1d()``.
43+
Added ``array_to_tuple_array()``.
4444

45-
Added ``array2d_tuple_iter()``.
45+
Added ``array_to_tuple_iter()``.
4646

4747

4848
0.6.3

doc/articles/array2d_to_1d.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import timeit
44
import typing as tp
55

6-
from arraykit import array2d_to_array1d
6+
from arraykit import array_to_tuple_array
77
import arraykit as ak
88

99
import matplotlib.pyplot as plt
@@ -21,11 +21,11 @@ def __init__(self, array: np.ndarray):
2121

2222
#-------------------------------------------------------------------------------
2323
class AKArray2D1D(ArrayProcessor):
24-
NAME = 'ak.array2d_to_array1d()'
24+
NAME = 'ak.array_to_tuple_array()'
2525
SORT = 0
2626

2727
def __call__(self):
28-
_ = array2d_to_array1d(self.array)
28+
_ = array_to_tuple_array(self.array)
2929

3030
class PyArray2D1D(ArrayProcessor):
3131
NAME = 'Python construction'
@@ -102,10 +102,10 @@ def plot_performance(frame):
102102
fig.set_size_inches(8, 4) # width, height
103103
fig.legend(post, names_display, loc='center right', fontsize=6)
104104
# horizontal, vertical
105-
fig.text(.05, .96, f'array2d_to_array1d() Performance: {NUMBER} Iterations', fontsize=10)
105+
fig.text(.05, .96, f'array_to_tuple_array() Performance: {NUMBER} Iterations', fontsize=10)
106106
fig.text(.05, .90, get_versions(), fontsize=6)
107107

108-
fp = '/tmp/array2d_to_array1d.png'
108+
fp = '/tmp/array_to_tuple_array.png'
109109
plt.subplots_adjust(
110110
left=0.05,
111111
bottom=0.05,

doc/articles/array2d_tuple_iter.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import timeit
44
import typing as tp
55

6-
from arraykit import array2d_tuple_iter
6+
from arraykit import array_to_tuple_iter
77
import arraykit as ak
88

99
import matplotlib.pyplot as plt
@@ -21,18 +21,18 @@ def __init__(self, array: np.ndarray):
2121

2222
#-------------------------------------------------------------------------------
2323
class AKArray2DTupleList(ArrayProcessor):
24-
NAME = 'list(ak.array2d_tuple_iter(a2d))'
24+
NAME = 'list(ak.array_to_tuple_iter(a2d))'
2525
SORT = 0
2626

2727
def __call__(self):
28-
_ = list(array2d_tuple_iter(self.array))
28+
_ = list(array_to_tuple_iter(self.array))
2929

3030
class AKArray2DTupleNext(ArrayProcessor):
31-
NAME = 'next(ak.array2d_tuple_iter(a2d))'
31+
NAME = 'next(ak.array_to_tuple_iter(a2d))'
3232
SORT = 1
3333

3434
def __call__(self):
35-
it = array2d_tuple_iter(self.array)
35+
it = array_to_tuple_iter(self.array)
3636
while True:
3737
try:
3838
_ = next(it)
@@ -128,10 +128,10 @@ def plot_performance(frame):
128128
fig.set_size_inches(8, 4) # width, height
129129
fig.legend(post, names_display, loc='center right', fontsize=6)
130130
# horizontal, vertical
131-
fig.text(.05, .96, f'array2d_tuple_iter() Performance: {NUMBER} Iterations', fontsize=10)
131+
fig.text(.05, .96, f'array_to_tuple_iter() Performance: {NUMBER} Iterations', fontsize=10)
132132
fig.text(.05, .90, get_versions(), fontsize=6)
133133

134-
fp = '/tmp/array2d_tuple_iter.png'
134+
fp = '/tmp/array_to_tuple_iter.png'
135135
plt.subplots_adjust(
136136
left=0.05,
137137
bottom=0.05,

src/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@
2828
from ._arraykit import first_true_1d as first_true_1d
2929
from ._arraykit import first_true_2d as first_true_2d
3030
from ._arraykit import slice_to_ascending_slice as slice_to_ascending_slice
31-
from ._arraykit import array2d_to_array1d as array2d_to_array1d
32-
from ._arraykit import array2d_tuple_iter as array2d_tuple_iter
31+
from ._arraykit import array_to_tuple_array as array_to_tuple_array
32+
from ._arraykit import array_to_tuple_iter as array_to_tuple_iter
3333
from ._arraykit import nonzero_1d as nonzero_1d

src/__init__.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,5 @@ def first_true_1d(__array: np.ndarray, *, forward: bool) -> int: ...
161161
def first_true_2d(__array: np.ndarray, *, forward: bool, axis: int) -> np.ndarray: ...
162162
def nonzero_1d(__array: np.ndarray, /) -> np.ndarray: ...
163163
def slice_to_ascending_slice(__slice: slice, __size: int) -> slice: ...
164-
def array2d_to_array1d(__array: np.ndarray) -> np.ndarray: ...
165-
def array2d_tuple_iter(__array: np.ndarray) -> tp.Iterator[tp.Tuple[tp.Any, ...]]: ...
164+
def array_to_tuple_array(__array: np.ndarray) -> np.ndarray: ...
165+
def array_to_tuple_iter(__array: np.ndarray) -> tp.Iterator[tp.Tuple[tp.Any, ...]]: ...

src/_arraykit.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3524,9 +3524,9 @@ array_deepcopy(PyObject *m, PyObject *args, PyObject *kwargs)
35243524
}
35253525

35263526
//------------------------------------------------------------------------------
3527-
// Given a 2D array, return a 1D object array of tuples.
3527+
// Given a 1D or 2D array, return a 1D object array of tuples.
35283528
static PyObject *
3529-
array2d_to_array1d(PyObject *Py_UNUSED(m), PyObject *a)
3529+
array_to_tuple_array(PyObject *Py_UNUSED(m), PyObject *a)
35303530
{
35313531
AK_CHECK_NUMPY_ARRAY(a);
35323532
PyArrayObject *input_array = (PyArrayObject *)a;
@@ -3714,7 +3714,7 @@ static PyTypeObject A2DTupleType = {
37143714

37153715
// Given a 2D array, return an iterator of row tuples.
37163716
static PyObject *
3717-
array2d_tuple_iter(PyObject *Py_UNUSED(m), PyObject *a)
3717+
array_to_tuple_iter(PyObject *Py_UNUSED(m), PyObject *a)
37183718
{
37193719
AK_CHECK_NUMPY_ARRAY(a);
37203720
PyArrayObject *array = (PyArrayObject *)a;
@@ -7480,8 +7480,8 @@ static PyMethodDef arraykit_methods[] = {
74807480
(PyCFunction)array_deepcopy,
74817481
METH_VARARGS | METH_KEYWORDS,
74827482
NULL},
7483-
{"array2d_to_array1d", array2d_to_array1d, METH_O, NULL},
7484-
{"array2d_tuple_iter", array2d_tuple_iter, METH_O, NULL},
7483+
{"array_to_tuple_array", array_to_tuple_array, METH_O, NULL},
7484+
{"array_to_tuple_iter", array_to_tuple_iter, METH_O, NULL},
74857485
{"resolve_dtype", resolve_dtype, METH_VARARGS, NULL},
74867486
{"resolve_dtype_iter", resolve_dtype_iter, METH_O, NULL},
74877487
{"first_true_1d",

test/test_util.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
from arraykit import first_true_1d
2323
from arraykit import first_true_2d
2424
from arraykit import slice_to_ascending_slice
25-
from arraykit import array2d_to_array1d
26-
from arraykit import array2d_tuple_iter
25+
from arraykit import array_to_tuple_array
26+
from arraykit import array_to_tuple_iter
2727

2828
from performance.reference.util import get_new_indexers_and_screen_ak as get_new_indexers_and_screen_full
2929
from arraykit import get_new_indexers_and_screen
@@ -288,33 +288,33 @@ def test_array_deepcopy_h(self) -> None:
288288
#---------------------------------------------------------------------------
289289
def test_array2d_to_array1d_1d_a(self) -> None:
290290
a1 = np.arange(10)
291-
a2 = array2d_to_array1d(a1)
291+
a2 = array_to_tuple_array(a1)
292292
self.assertEqual(a2.tolist(), [(0,), (1,), (2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,)])
293293

294294
def test_array2d_to_array1d_1d_b(self) -> None:
295295
a1 = np.array(['aaa', 'b', 'ccc'])
296-
a2 = array2d_to_array1d(a1)
296+
a2 = array_to_tuple_array(a1)
297297
self.assertEqual(a2.tolist(), [('aaa',), ('b',), ('ccc',)])
298298

299299
def test_array2d_to_array1d_1d_c(self) -> None:
300300
a1 = np.array([None, 'b', 30])
301-
a2 = array2d_to_array1d(a1)
301+
a2 = array_to_tuple_array(a1)
302302
self.assertEqual(a2.tolist(), [(None,), ('b',), (30,)])
303303

304304
def test_array2d_to_array1d_1d_d(self) -> None:
305305
a1 = np.array([('a', 10), ('b', 30), ('c', 5)], dtype=object)
306-
a2 = array2d_to_array1d(a1)
306+
a2 = array_to_tuple_array(a1)
307307
self.assertEqual(a2.tolist(), [('a', 10), ('b', 30), ('c', 5)])
308308

309309
def test_array2d_to_array1d_1d_e(self) -> None:
310310
a1 = np.array([True, False, True], dtype=object)
311-
a2 = array2d_to_array1d(a1)
311+
a2 = array_to_tuple_array(a1)
312312
self.assertIs(a2[0][0].__class__, bool)
313313
self.assertEqual(a2.tolist(), [(True,), (False,), (True,)])
314314

315315
def test_array2d_to_array1d_b(self) -> None:
316316
a1 = np.arange(10, dtype=np.int64).reshape(5, 2)
317-
result = array2d_to_array1d(a1)
317+
result = array_to_tuple_array(a1)
318318
assert isinstance(result[0], tuple)
319319
assert result[0] == (0, 1)
320320
self.assertIs(type(result[0][0]), np.int64)
@@ -324,35 +324,35 @@ def test_array2d_to_array1d_b(self) -> None:
324324

325325
def test_array2d_to_array1d_c(self) -> None:
326326
a1 = np.array([["a", "b"], ["ccc", "ddd"], ["ee", "ff"]])
327-
a2 = array2d_to_array1d(a1)
327+
a2 = array_to_tuple_array(a1)
328328
self.assertEqual(a2.tolist(), [('a', 'b'), ('ccc', 'ddd'), ('ee', 'ff')])
329329

330330
def test_array2d_to_array1d_d(self) -> None:
331331
a1 = np.array([[3, 5], [10, 20], [7, 2]], dtype=np.uint8)
332-
a2 = array2d_to_array1d(a1)
332+
a2 = array_to_tuple_array(a1)
333333
self.assertEqual(a2.tolist(), [(3, 5), (10, 20), (7, 2)])
334334
self.assertIs(type(a2[0][0]), np.uint8)
335335

336336
def test_array2d_to_array1d_e(self) -> None:
337337
a1 = np.arange(20, dtype=np.int64).reshape(4, 5)
338-
result = array2d_to_array1d(a1)
338+
result = array_to_tuple_array(a1)
339339
self.assertEqual(result.tolist(), [(0, 1, 2, 3, 4), (5, 6, 7, 8, 9), (10, 11, 12, 13, 14), (15, 16, 17, 18, 19)])
340340

341341
#---------------------------------------------------------------------------
342342
def test_array2d_tuple_iter_a(self) -> None:
343343
a1 = np.arange(20, dtype=np.int64).reshape(4, 5)
344-
result = list(array2d_tuple_iter(a1))
344+
result = list(array_to_tuple_iter(a1))
345345
self.assertEqual(len(result), 4)
346346
self.assertEqual(result, [(0, 1, 2, 3, 4), (5, 6, 7, 8, 9), (10, 11, 12, 13, 14), (15, 16, 17, 18, 19)])
347347

348348
def test_array2d_tuple_iter_b(self) -> None:
349349
a1 = np.arange(20, dtype=np.int64).reshape(10, 2)
350-
result = list(array2d_tuple_iter(a1))
350+
result = list(array_to_tuple_iter(a1))
351351
self.assertEqual(result, [(0, 1), (2, 3), (4, 5), (6, 7), (8, 9), (10, 11), (12, 13), (14, 15), (16, 17), (18, 19)])
352352

353353
def test_array2d_tuple_iter_c(self) -> None:
354354
a1 = np.array([['aaa', 'bb'], ['c', 'dd'], ['ee', 'fffff']])
355-
it = array2d_tuple_iter(a1)
355+
it = array_to_tuple_iter(a1)
356356
self.assertEqual(it.__length_hint__(), 3)
357357
self.assertEqual(next(it), ('aaa', 'bb'))
358358
self.assertEqual(it.__length_hint__(), 2)
@@ -365,48 +365,48 @@ def test_array2d_tuple_iter_c(self) -> None:
365365

366366
def test_array2d_tuple_iter_d(self) -> None:
367367
a1 = np.array([['aaa', 'bb'], ['c', 'dd'], ['ee', 'fffff']])
368-
it = array2d_tuple_iter(a1)
368+
it = array_to_tuple_iter(a1)
369369
# __reversed__ not implemented
370370
with self.assertRaises(TypeError):
371371
reversed(it)
372372

373373
def test_array2d_tuple_iter_e(self) -> None:
374374
a1 = np.array([[None, 'bb'], [None, 'dd'], [3, None]])
375-
it = array2d_tuple_iter(a1)
375+
it = array_to_tuple_iter(a1)
376376
del a1
377377
self.assertEqual(list(it), [(None, 'bb'), (None, 'dd'), (3, None)])
378378

379379
def test_array2d_tuple_iter_f(self) -> None:
380380
a1 = np.array([[None, 'bb'], [None, 'dd'], [3, None]])
381-
it1 = array2d_tuple_iter(a1)
381+
it1 = array_to_tuple_iter(a1)
382382
del a1
383383
it2 = iter(it1)
384384
self.assertEqual(list(it1), [(None, 'bb'), (None, 'dd'), (3, None)])
385385
self.assertEqual(list(it2), []) # expected behavior
386386

387387
def test_array2d_tuple_iter_g(self) -> None:
388388
a1 = np.array([[None, 'bb'], [None, 'dd'], [3, None]])
389-
it1 = array2d_tuple_iter(a1)
390-
it2 = array2d_tuple_iter(a1)
389+
it1 = array_to_tuple_iter(a1)
390+
it2 = array_to_tuple_iter(a1)
391391
del a1
392392
self.assertEqual(list(it1), [(None, 'bb'), (None, 'dd'), (3, None)])
393393
self.assertEqual(list(it2), [(None, 'bb'), (None, 'dd'), (3, None)])
394394

395395
def test_array2d_tuple_iter_1d_a(self) -> None:
396396
a1 = np.array(['bb', 'c', 'aaa'])
397-
result = list(array2d_tuple_iter(a1))
397+
result = list(array_to_tuple_iter(a1))
398398
self.assertEqual(len(result), 3)
399399
self.assertEqual(result, [('bb',), ('c',), ('aaa',)])
400400

401401
def test_array2d_tuple_iter_1d_b(self) -> None:
402402
a1 = np.array([20, -1, 8])
403-
result = list(array2d_tuple_iter(a1))
403+
result = list(array_to_tuple_iter(a1))
404404
self.assertEqual(len(result), 3)
405405
self.assertEqual(result, [(20,), (-1,), (8,)])
406406

407407
def test_array2d_tuple_iter_1d_c(self) -> None:
408408
a1 = np.array([('a', 4), ('c', -1), ('d', 8)], dtype=object)
409-
result = list(array2d_tuple_iter(a1))
409+
result = list(array_to_tuple_iter(a1))
410410
self.assertEqual(len(result), 3)
411411
self.assertEqual(result, [('a', 4), ('c', -1), ('d', 8)])
412412

0 commit comments

Comments
 (0)