Skip to content

Commit e3e3650

Browse files
authored
Merge pull request #1969 from ales-erjavec/fixes/distribution-meta-object-array
[FIX] Table: Ensure correct dtype in `_compute_distributions`
2 parents 5cbac0e + e5c1dc3 commit e3e3650

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Orange/data/table.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,8 @@ def _get_matrix(M, cachedM, col):
13091309
m, W, Xcsc = _get_matrix(self.X, Xcsc, col)
13101310
elif col < 0:
13111311
m, W, Xcsc = _get_matrix(self.metas, Xcsc, col * (-1) - 1)
1312+
if np.issubdtype(m.dtype, np.dtype(object)):
1313+
m = m.astype(float)
13121314
else:
13131315
m, W, Ycsc = _get_matrix(self._Y, Ycsc, col - self.X.shape[1])
13141316
if var.is_discrete:

Orange/tests/test_distribution.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Test methods with long descriptive names can omit docstrings
2-
# pylint: disable=missing-docstring
2+
# Test internal methods
3+
# pylint: disable=missing-docstring, protected-access
34

45
import unittest
56
from unittest.mock import Mock
@@ -430,7 +431,13 @@ def test_compute_distributions_metas(self):
430431
variable = d.domain[-2]
431432
dist, _ = d._compute_distributions([variable])[0]
432433
np.testing.assert_almost_equal(dist, [3, 3, 2])
433-
434+
# repeat with nan values
435+
assert d.metas.dtype.kind == "O"
436+
assert d.metas[0, 1] == 0
437+
d.metas[0, 1] = np.nan
438+
dist, nanc = d._compute_distributions([variable])[0]
439+
np.testing.assert_almost_equal(dist, [2, 3, 2])
440+
self.assertEqual(nanc, 1)
434441

435442
if __name__ == "__main__":
436443
unittest.main()

0 commit comments

Comments
 (0)