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 6, 2018
1 parent 6c80c79 commit ea45200
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,7 +247,14 @@ def __call__(self, data, ret=Value):
if isinstance(data, Instance):
data = Table(data.domain, [data])
if data.domain != self.domain:
orig = data
data = data.transform(self.domain)
if data.X.size \
and np.isnan(data.X).all() \
and not np.isnan(orig.X).all() \
and data.domain.attributes != orig.domain.attributes:
raise DomainTransformationError(
"domain transformation produced no defined values")
prediction = self.predict_storage(data)
elif isinstance(data, (list, tuple)):
if not isinstance(data[0], (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 ea45200

Please sign in to comment.