Skip to content
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: 2 additions & 0 deletions Orange/statistics/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ def stats(X, weights=None, compute_variance=False):
X.shape[0] - non_zero,
non_zero))
else:
if X.ndim == 1:
X = X[:, None]
nans = (pandas.isnull(X).sum(axis=0) + (X == "").sum(axis=0)) \
if X.size else np.zeros(X.shape[1])
return np.column_stack((
Expand Down
4 changes: 4 additions & 0 deletions Orange/tests/test_basic_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def test_domain_basic_stats(self):
self.assertStatsEqual(domain_stats.stats,
attr_stats + class_var_stats + meta_stats)

def test_empty_table(self):
domain_stats = DomainBasicStats(self.zoo[:0])
self.assertEqual(len(domain_stats.stats), 17)

def test_speed(self):
n, m = 10, 10000
data = Table.from_numpy(None, np.random.rand(n, m))
Expand Down
12 changes: 12 additions & 0 deletions Orange/tests/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,18 @@ def test_stats_non_numeric(self):
[np.inf, -np.inf, 0, 0, 2, 1],
[np.inf, -np.inf, 0, 0, 0, 3]])

def test_stats_empty(self):
X = np.array([])
np.testing.assert_equal(stats(X), [[np.inf, -np.inf, 0, 0, 0, 0]])

X = np.zeros((0,))
np.testing.assert_equal(stats(X), [[np.inf, -np.inf, 0, 0, 0, 0]])

X = np.zeros((0, 4))
np.testing.assert_equal(stats(X), [[np.inf, -np.inf, 0, 0, 0, 0]] * 4)



def test_stats_long_string_mem_use(self):
X = np.full((1000, 1000), "a", dtype=object)
t = time.time()
Expand Down
6 changes: 6 additions & 0 deletions Orange/widgets/data/tests/test_owtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ def test_input_data(self):
self.send_signal(self.widget.Inputs.data, None, 1)
self.assertEqual(self.widget.tabs.count(), 1)

def test_input_data_empty(self):
self.send_signal(self.widget.Inputs.data, self.data[:0])
output = self.get_output(self.widget.Outputs.annotated_data)
self.assertIsInstance(output, Table)
self.assertEqual(len(output), 0)

def test_data_model(self):
self.send_signal(self.widget.Inputs.data, self.data, 1)
self.assertEqual(self.widget.tabs.widget(0).model().rowCount(),
Expand Down