Skip to content

Commit a480971

Browse files
committed
OWFile: Warning when setting a discrete variable with more than 100 values
1 parent ee4dd2c commit a480971

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Orange/widgets/data/owfile.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import logging
3+
from itertools import chain
34
from warnings import catch_warnings
45
from urllib.parse import urlparse
56
from typing import List
@@ -123,6 +124,8 @@ class Warning(widget.OWWidget.Warning):
123124
file_too_big = widget.Msg("The file is too large to load automatically."
124125
" Press Reload to load.")
125126
load_warning = widget.Msg("Read warning:\n{}")
127+
performance_warning = widget.Msg(
128+
"Categorical variables with >100 values may decrease performance.")
126129

127130
class Error(widget.OWWidget.Error):
128131
file_not_found = widget.Msg("File not found.")
@@ -468,7 +471,13 @@ def reset_domain_edit(self):
468471
self.domain_editor.reset_domain()
469472
self.apply_domain_edit()
470473

474+
def _inspect_discrete_variables(self, domain):
475+
for var in chain(domain.variables, domain.metas):
476+
if var.is_discrete and len(var.values) > 100:
477+
self.Warning.performance_warning()
478+
471479
def apply_domain_edit(self):
480+
self.Warning.performance_warning.clear()
472481
if self.data is None:
473482
table = None
474483
else:
@@ -481,6 +490,7 @@ def apply_domain_edit(self):
481490
table.name = self.data.name
482491
table.ids = np.array(self.data.ids)
483492
table.attributes = getattr(self.data, 'attributes', {})
493+
self._inspect_discrete_variables(domain)
484494

485495
self.Outputs.data.send(table)
486496
self.apply_button.setEnabled(False)

0 commit comments

Comments
 (0)