Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] DistMatrix should return numpy datatypes #3865

Merged
merged 2 commits into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Orange/misc/distmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __array_finalize__(self, obj):

def __array_wrap__(self, out_arr, context=None):
if out_arr.ndim == 0: # a single scalar
return out_arr.item()
return out_arr[()]
return np.ndarray.__array_wrap__(self, out_arr, context)

"""
Expand Down
11 changes: 11 additions & 0 deletions Orange/tests/test_distances.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,17 @@ def test_save(self):
["danny", "eve", "frank"])
self.assertEqual(m.axis, 0)

def test_numpy_type(self):
"""GH-3658"""
data1 = np.array([1, 2], dtype=np.int64)
data2 = np.array([2, 3], dtype=np.int64)
dm1, dm2 = DistMatrix(data1), DistMatrix(data2)

self.assertIsInstance(dm1.max(), np.int64)
self.assertNotIsInstance(dm1.max(), int)
with self.assertRaises(AssertionError):
np.testing.assert_array_equal(dm1, dm2)


# noinspection PyTypeChecker
class TestEuclidean(TestCase):
Expand Down