Skip to content

Commit 9006a6c

Browse files
committed
Formatting
1 parent 3889d30 commit 9006a6c

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

mathics/core/atoms.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,9 @@ def __init__(self, value, dtype=None):
11661166
# TODO: to make it less expensive only look at first 100 bytes - ok? needed?
11671167
def __hash__(self):
11681168
if not self._hash:
1169-
self._hash = hash(("NumericArray", self.value.shape, self.value.tobytes()[:100]))
1169+
self._hash = hash(
1170+
("NumericArray", self.value.shape, self.value.tobytes()[:100])
1171+
)
11701172
return self._hash
11711173

11721174
def __str__(self) -> str:
@@ -1184,6 +1186,7 @@ def default_format(self, evaluation, form) -> str:
11841186
@property
11851187
def items(self) -> tuple:
11861188
from mathics.core.convert.python import from_python
1189+
11871190
if len(self.value.shape) == 1:
11881191
return tuple(from_python(item.item()) for item in self.value)
11891192
else:
@@ -1195,15 +1198,17 @@ def element_order(self) -> tuple:
11951198
BASIC_ATOM_NUMERICARRAY_ELT_ORDER,
11961199
self.value.shape,
11971200
self.value.dtype,
1198-
self.value.tobytes()
1201+
self.value.tobytes(),
11991202
)
12001203

12011204
@property
12021205
def pattern_precedence(self) -> tuple:
12031206
return super().pattern_precedence
12041207

12051208
def sameQ(self, rhs) -> bool:
1206-
return isinstance(rhs, NumericArray) and numpy.array_equal(self.value, rhs.value)
1209+
return isinstance(rhs, NumericArray) and numpy.array_equal(
1210+
self.value, rhs.value
1211+
)
12071212

12081213
def to_sympy(self, **kwargs) -> None:
12091214
return None

test/builtin/test_numericarray.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
from mathics.core.atoms import Integer, NumericArray, String
2-
from mathics.core.convert.python import from_python
31
from test.helper import check_evaluation, evaluate
42

53
import numpy as np
64
import pytest
75

6+
from mathics.core.atoms import Integer, NumericArray, String
7+
from mathics.core.convert.python import from_python
8+
89
#
910
# Python API tests
1011
#
1112

13+
1214
def test_numericarray_atom_preserves_array_reference():
1315
array = np.array([1, 2, 3], dtype=np.int64)
1416
atom = NumericArray(array)
1517
assert atom.value is array
1618

19+
1720
def test_numericarray_atom_preserves_equality():
1821
array = np.array([1, 2, 3], dtype=np.int64)
1922
atom = NumericArray(array, dtype=np.float64)
@@ -26,6 +29,7 @@ def test_numericarray_expression_from_python_array():
2629
assert isinstance(atom, NumericArray)
2730
assert atom.value is array
2831

32+
2933
def test_numericarray_hash():
3034
a = [[1, 2], [3, 4]]
3135
array1a = np.array(a, dtype=np.float32)
@@ -34,16 +38,20 @@ def test_numericarray_hash():
3438
atom1b = from_python(array1a)
3539
array2 = np.array(a, dtype=np.float64)
3640
atom2 = from_python(array2)
37-
assert hash(atom1a) == hash(atom1b), "hashes of different arrays with same value should be same"
38-
assert hash(atom1a) != hash(atom2), "hashes of arrays with different values should be different"
41+
assert hash(atom1a) == hash(
42+
atom1b
43+
), "hashes of different arrays with same value should be same"
44+
assert hash(atom1a) != hash(
45+
atom2
46+
), "hashes of arrays with different values should be different"
3947

4048

4149
#
4250
# WL tests
4351
# Will not work yet
4452
#
4553

46-
#@pytest.mark.parametrize(
54+
# @pytest.mark.parametrize(
4755
# ("str_expr", "str_expected"),
4856
# [
4957
# ("NumericArray[{{1,2},{3,4}}]", "<Integer64, 2×2>"),
@@ -56,15 +64,13 @@ def test_numericarray_hash():
5664
# ("Last[NumericArray[{{1,2}, {3,4}}]]", "<Integer64, 2>"),
5765
# ("Normal[NumericArray[{{1,2}, {3,4}}]]", "{{1, 2}, {3, 4}}"),
5866
# ]
59-
#)
60-
#def test_basics(str_expr, str_expected):
67+
# )
68+
# def test_basics(str_expr, str_expected):
6169
# check_evaluation(str_expr, str_expected, hold_expected=True)
6270
#
63-
#def test_type_conversion():
71+
# def test_type_conversion():
6472
# expr = evaluate("NumericArray[{1,2}]")
6573
# assert isinstance(expr, NumericArray)
6674
# assert expr.value.dtype == np.int64
6775
# expr = evaluate('NumericArray[{1,2}, "ComplexReal32"]')
6876
# assert expr.value.dtype == np.complex64
69-
70-

0 commit comments

Comments
 (0)