Skip to content

Commit b21fa54

Browse files
committed
adding python array class and test suite
1 parent 07de4f1 commit b21fa54

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from __future__ import absolute_import, print_function, unicode_literals
4+
5+
from functools import partial
6+
7+
from wolframclient.serializers import export
8+
from wolframclient.utils.api import numpy
9+
from wolframclient.utils.pythonarray import PythonArray
10+
from wolframclient.utils.tests import TestCase as BaseTestCase
11+
12+
13+
class TestCase(BaseTestCase):
14+
15+
export = partial(export, target_format="wl")
16+
17+
def test_python_array(self):
18+
19+
for array, numpy_type, wl_type in (([1, 2, 3], numpy.uint64, "Integer64"),):
20+
21+
print(self.export(numpy.array(array, numpy_type)))
22+
print(self.export(PythonArray(array, wl_type)))

wolframclient/utils/pythonarray.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from __future__ import absolute_import, print_function, unicode_literals
2+
3+
from collections.abc import Sequence
4+
5+
6+
class PythonArray(Sequence):
7+
def __init__(self, array, type):
8+
self.array = array
9+
self.type = type
10+
11+
def __getitem__(self, k):
12+
return self.array[k]
13+
14+
def __len__(self):
15+
return len(self.array)

0 commit comments

Comments
 (0)