source: orange/Orange/doc/reference/exampletable5.py @ 9671:a7b056375472

Revision 9671:a7b056375472, 1.7 KB checked in by anze <anze.staric@…>, 2 years ago (diff)

Moved orange to Orange (part 2)

Line 
1# Description: Shows and tests differences between ExampleTable's methods select, selectref and selectlist, and filter, filterref and filterlist
2# Category:    basic classes, preprocessing
3# Classes:     ExampleTable
4# Uses:        bridges
5# Referenced:  ExampleTable.htm
6
7import orange, gc
8
9data = orange.ExampleTable("bridges")
10
11mid = data.filter(LENGTH=(1000, 2000))
12del mid
13gc.collect()
14
15def testnonref(mid):
16    pd0 = data[0][1]
17    mid[0][1] += 1
18    if pd0 != data[0][1]:
19        raise Exception("reference when there shouldn't be")
20
21def testref(mid):
22    pd0 = data[0][1]
23    mid[0][1] += 1
24    if pd0 == data[0][1]:
25        raise Exception("not reference when there should be")
26
27filterany = orange.Filter_values()
28filterany.domain = data.domain
29filterany.conditions.append(orange.ValueFilter_continuous(position = data.domain.index("LENGTH"), min=-9999, max=9999, acceptSpecial=True))
30
31# we sometime use LENGT=... and sometimes filterany
32# the former cannot be given the 'acceptSpecial' flag, but we would
33# still like to test the form of the call when we can
34testnonref(data.filter(LENGTH=(-9999, 9999)))
35testref(data.filterref(filterany))
36testref(data.filterlist(filterany))
37
38ll = [1]*len(data)
39testnonref(data.select(ll))
40testref(data.selectref(ll))
41testref(data.selectlist(ll))
42
43testnonref(data.getitems(range(10)))
44testref(data.getitemsref(range(10)))
45
46data = data.selectref(ll)
47print gc.collect()
48
49print data.ownsExamples
50
51testnonref(data.filter(LENGTH=(-9999, 9999)))
52testref(data.filterref(filterany))
53testref(data.filterlist(filterany))
54
55testnonref(data.select(ll))
56testref(data.selectref(ll))
57testref(data.selectlist(ll))
58
59testnonref(data.getitems(range(10)))
60testref(data.getitemsref(range(10)))
61
62print "OK"
Note: See TracBrowser for help on using the repository browser.