Orange Forum • View topic - Bug in orange.ExampleTable()

Bug in orange.ExampleTable()

Report bugs (or imagined bugs).
(Archived/read-only, please use our ticketing system for reporting bugs and their discussion.)
Forum rules
Archived/read-only, please use our ticketing system for reporting bugs and their discussion.

Bug in orange.ExampleTable()

Postby aonlazio » Sun May 10, 2009 0:34

The output below shows that the objects from orange.ExampleTable links together such that when I remove classVar.values from t, it effects the classVar.values of data also. This may implicate in C++ code, could you take a look at it? This is not a good signs of oop programming

>>> import orange
>>> from copy import deepcopy
>>> data=orange.ExampleTable("vehicle")
>>> data.classVar.values
<bus,van,saab,opel>
>>> t=orange.ExampleTable("vehicle")
>>> t.domain.classVar.values.remove("bus")
>>> t.domain.classVar.values
<van, saab, opel>
>>> data.domain.classVar.values
<van, saab, opel>

Postby Janez » Fri May 22, 2009 21:16

This is not poor OOP design, it is quite intentional and required quite some coding to work the way it does (and should).

Imagine you have some data; for sake of simplicity let it have a single attribute A and the class. You build a classifier. Then you pickle the classifier, unpickle it, and then try to use it on the same data. Should it work?

I assume you answered 'yes'. The original classifier obviously refers to the value of the data's attribute A. The unpickled classifier has to refer to the same attribute A. If it referred to another attribute A which only incidentally had the same name and values, the unpickled classifier would not work on this data.

Hence, if you pickle and then unpickle an attribute, you get the same attribute, not its copy. This somewhat peculiar behaviour is by design - if it wasn't like this, pickling Orange objects would be useless. The case I described is simple, but there are even more basic things which would break if pickling created new attribute instances. This behaviour is limited to attributes only.

The reason why deepcopy does not work as you expected is that it is based on pickling. You cannot deepcopy an attribute, you can just create a new one if you will.

Re: Bug in orange.ExampleTable()

Postby chungwu » Sat Feb 19, 2011 5:03

But suppose I do this:

table1 = orange.ExampleTable('table1')
table2 = orange.ExampleTable('table2')

And that, table1 has classes "Good", "Bad", and table2 has classes "Right", "Wrong". Now, both of them are using the same classVar:

table1.domain.classVar.values == table2.domain.classVar.values == ["Good", "Bad", "Right", "Wrong"]

What can I do to avoid this, so that the respective classVar for each table actually contains the proper values?

Re: Bug in orange.ExampleTable()

Postby Janez » Sat Feb 19, 2011 11:06

Load it like this:

table2 = orange.ExmapleTable("table2", createNewOn=orange.Variable.MakeStatus.OK)

This will always create new attributes for the second table (not only the class attribute but all others as well). See http://orange.biolab.si/doc/reference/V ... etExisting for other options.

Re: Bug in orange.ExampleTable()

Postby yang » Wed Mar 02, 2011 6:50

I've also been bitten by this. Not exactly the best design IMO either, and I would not have guessed that workaround, even after reading the reference documentation.


Return to Bugs



cron