Skip to content

Commit

Permalink
Merge pull request #3865 from robertcv/fix/distmatrix_datatype
Browse files Browse the repository at this point in the history
[FIX] DistMatrix should return numpy datatypes
  • Loading branch information
lanzagar authored Jun 7, 2019
2 parents d672ab7 + 1fd6a65 commit 74ffccc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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

0 comments on commit 74ffccc

Please sign in to comment.