Skip to content

Commit

Permalink
Model: Raise an exception if transformation results in all nans
Browse files Browse the repository at this point in the history
  • Loading branch information
janezd committed Nov 18, 2018
1 parent dda3505 commit 866bd9a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Orange/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from Orange.data import Table, Storage, Instance, Value
from Orange.data.filter import HasClass
from Orange.data.table import DomainTransformationError
from Orange.data.util import one_hot
from Orange.misc.wrapper_meta import WrapperMeta
from Orange.preprocess import Continuize, RemoveNaNColumns, SklImpute, Normalize
Expand Down Expand Up @@ -246,6 +247,13 @@ def __call__(self, data, ret=Value):
if isinstance(data, Instance):
data = Table(data.domain, [data])
if data.domain != self.domain:
if self.original_domain.attributes != data.domain.attributes \
and data.X.size \
and not np.isnan(data.X).all():
data = data.transform(self.original_domain)
if np.isnan(data.X).all():
raise DomainTransformationError(
"domain transformation produced no defined values")
data = data.transform(self.domain)
prediction = self.predict_storage(data)
elif isinstance(data, (list, tuple)):
Expand Down
4 changes: 4 additions & 0 deletions Orange/data/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ def get_sample_datasets_dir():
_conversion_cache_lock = RLock()


class DomainTransformationError(Exception):
pass


class RowInstance(Instance):
sparse_x = None
sparse_y = None
Expand Down

0 comments on commit 866bd9a

Please sign in to comment.