Orange Forum • View topic - Shared class values when having more than one ExampleTable

Shared class values when having more than one ExampleTable

A place to ask questions about methods in Orange and how they are used and other general support.

Shared class values when having more than one ExampleTable

Postby bgbg » Wed Mar 25, 2009 9:56

How can one have more than one ExampleTable without sharing their classes variables?
Consider the following code:
Code: Select all
def test():
    strDirData = r'./'
    lStrFiles = [ 'dataTestZERO.tab', 'dataTestONE.tab']
    data0 = orange.ExampleTable(os.path.normpath(strDirData + '/' + lStrFiles[0]))
    classes0 = data0.domain.classVar.values
    print 'before loading second file'
    print 'classes0', classes0
   
    data1 = orange.ExampleTable(os.path.normpath(strDirData + '/' + lStrFiles[1]))
    classes1 = data1.domain.classVar.values
    print 'after loading second file'
    print 'classes0', classes0
    print 'classes1', classes1
    print 'classes0 is classes1:', (classes0 is classes1)


The class variables in dataTestZERO.tab can have values 'controlZERO' and 'treatedZERO'. The class variables in dataTestONE.tab has the values 'controlONE' and 'treatedONE".

Thus, I expect the above code to produce the following output :
before loading second file
classes0 <treatedZERO, controlZERO>
after loading second file
classes0 <treatedZERO, controlZERO>,
classes1 <controlONE, treatedONE>
classes0 is classes1: False


However, the following output is obtained:
before loading second file
classes0 <treatedZERO, controlZERO>
after loading second file
classes0 <treatedZERO, controlZERO, controlONE, treatedONE>
classes1 <treatedZERO, controlZERO, controlONE, treatedONE>
classes0 is classes1: True


Is this a bug or a feature? how can I overcome this behavior?

Postby Janez » Sat Mar 28, 2009 11:24

We have spent a lot of time discussing this concept, but after all arguments for and against we decided that by default, two attributes (including class attributes) with the same name are the same attributes. Consider this as if all attributes share the same namespace.

The simplest solution for your problem is to rename the class in one of your files. If you want them to have different values, they are obviously not the same thing.

You can also override this default behavior (see Reuse of Attributes in http://www.ailab.si/orange/doc/referenc ... ormats.htm), but I'd recommend the simpler solution.


Return to Questions & Support



cron