Skip to content

Commit d5d1665

Browse files
committed
Matplotlib export: avoid numpy repr because of version differences
1 parent 17169e8 commit d5d1665

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Orange/widgets/utils/matplotlib_export.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,23 @@
1111
def numpy_repr(a):
1212
""" A numpy repr without summarization """
1313
opts = np.get_printoptions()
14+
# avoid numpy repr as it changes between versions
15+
# TODO handle numpy repr differences
16+
if isinstance(a, np.ndarray):
17+
return "array(" + repr(list(a)) + ")"
1418
try:
1519
np.set_printoptions(threshold=10**10)
1620
return repr(a)
1721
finally:
1822
np.set_printoptions(**opts)
1923

2024

25+
def numpy_repr_int(a):
26+
# avoid numpy repr as it changes between versions
27+
# TODO handle numpy repr differences
28+
return "array(" + repr(list(a)) + ", dtype='int')"
29+
30+
2131
def compress_if_all_same(l):
2232
s = set(l)
2333
return s.pop() if len(s) == 1 else l
@@ -113,7 +123,7 @@ def do_colors(code, data_column, show, name):
113123

114124
code.append("{} = {}".format(name, repr(colors)))
115125
if index is not None:
116-
code.append("{}_index = {}".format(name, repr(index)))
126+
code.append("{}_index = {}".format(name, numpy_repr_int(index)))
117127

118128
decompresssed_code = name
119129
if index is not None:
@@ -153,7 +163,7 @@ def matplotlib_marker(m):
153163
if np.all(indices == np.arange(x.shape[0])):
154164
indices = None
155165
if indices is not None:
156-
code.append("indices = {}".format(numpy_repr(indices)))
166+
code.append("indices = {}".format(numpy_repr_int(indices)))
157167

158168
def indexed(data, data_name, indices=indices):
159169
return code_with_indices(data, data_name, indices, "indices")

0 commit comments

Comments
 (0)