~ubuntu-branches/ubuntu/quantal/pytables/quantal

« back to all changes in this revision

Viewing changes to test/test_indexvalues.py

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2005-11-27 20:25:34 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20051127202534-l8jzyd8357krw40h
Tags: 1.1.1-1ubuntu1
* Sync with Debian:
  + Use python 2.4 as default

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
from tables import *
8
8
#from tables.Index import Index
9
9
from tables.IndexArray import calcChunksize
10
 
from test_all import verbose, allequal, heavy
 
10
from test_all import verbose, allequal, heavy, cleanup
 
11
# To delete the internal attributes automagically
 
12
unittest.TestCase.tearDown = cleanup
11
13
 
12
14
# The minimum number of rows that can be indexed
13
15
# Remember to change that if the number is changed in
92
94
    def tearDown(self):
93
95
        self.fileh.close()
94
96
        os.remove(self.file)
 
97
        cleanup(self)
95
98
        
96
99
    #----------------------------------------
97
100
 
445
448
        assert len(results1) == len(results2)
446
449
        assert results1 == results2
447
450
 
 
451
    def test03c(self):
 
452
        """Checking selecting values from an Index (long flavor)"""
 
453
 
 
454
        if verbose:
 
455
            print '\n', '-=' * 30
 
456
            print "Running %s.test03c..." % self.__class__.__name__
 
457
 
 
458
        table1 = self.fileh.root.table1
 
459
        table2 = self.fileh.root.table2
 
460
 
 
461
        # Convert the limits to the appropriate type
 
462
        il = long(self.il)
 
463
        sl = long(self.sl)
 
464
 
 
465
        # Do some selections and check the results
 
466
        t1col = table1.cols.var3
 
467
 
 
468
        # First selection
 
469
        results1 = [p["var3"] for p in table1.where(t1col < sl)]
 
470
        results2 = [p["var3"] for p in table2
 
471
                    if p["var3"] < sl]
 
472
        # sort lists (indexing does not guarantee that rows are returned in
 
473
        # order)
 
474
        results1.sort(); results2.sort()
 
475
        if verbose:
 
476
            print "Limit:", sl
 
477
            print "Selection results (index):", results1
 
478
            print "Should look like:", results2
 
479
            print "Length results:", len(results1)
 
480
            print "Should be:", len(results2)
 
481
        assert len(results1) == len(results2)
 
482
        assert results1 == results2
 
483
 
 
484
        # Second selection
 
485
        results1 = [p["var3"] for p in table1.where(t1col <= sl)]
 
486
        results2 = [p["var3"] for p in table2
 
487
                    if p["var3"] <= sl]
 
488
        # sort lists (indexing does not guarantee that rows are returned in
 
489
        # order)
 
490
        results1.sort(); results2.sort()
 
491
        if verbose:
 
492
            print "Limit:", sl
 
493
#             print "Selection results (index):", results1
 
494
#             print "Should look like:", results2
 
495
            print "Length results:", len(results1)
 
496
            print "Should be:", len(results2)
 
497
        assert len(results1) == len(results2)
 
498
        assert results1 == results2
 
499
 
 
500
        # Third selection
 
501
        results1 = [p["var3"] for p in table1.where(t1col > sl)]
 
502
        results2 = [p["var3"] for p in table2
 
503
                    if p["var3"] > sl]
 
504
        # sort lists (indexing does not guarantee that rows are returned in
 
505
        # order)
 
506
        results1.sort(); results2.sort()
 
507
        if verbose:
 
508
            print "Limit:", sl
 
509
#             print "Selection results (index):", results1
 
510
#             print "Should look like:", results2
 
511
            print "Length results:", len(results1)
 
512
            print "Should be:", len(results2)
 
513
        assert len(results1) == len(results2)
 
514
        assert results1 == results2
 
515
 
 
516
        # Fourth selection
 
517
        results1 = [p["var3"] for p in table1.where(t1col >= sl)]
 
518
        results2 = [p["var3"] for p in table2
 
519
                    if p["var3"] >= sl]
 
520
        # sort lists (indexing does not guarantee that rows are returned in
 
521
        # order)
 
522
        results1.sort(); results2.sort()
 
523
        if verbose:
 
524
            print "Limit:", sl
 
525
#             print "Selection results (index):", results1
 
526
#             print "Should look like:", results2
 
527
            print "Length results:", len(results1)
 
528
            print "Should be:", len(results2)
 
529
        assert len(results1) == len(results2)
 
530
        assert results1 == results2
 
531
 
 
532
    def test03d(self):
 
533
        """Checking selecting values from an Index (long and int flavor)"""
 
534
 
 
535
        if verbose:
 
536
            print '\n', '-=' * 30
 
537
            print "Running %s.test03d..." % self.__class__.__name__
 
538
 
 
539
        table1 = self.fileh.root.table1
 
540
        table2 = self.fileh.root.table2
 
541
 
 
542
        # Convert the limits to the appropriate type
 
543
        il = int(self.il)
 
544
        sl = long(self.sl)
 
545
 
 
546
        # Do some selections and check the results
 
547
        t1col = table1.cols.var3
 
548
 
 
549
        # First selection
 
550
        results1 = [p["var3"] for p in table1.where(t1col < sl)]
 
551
        results2 = [p["var3"] for p in table2
 
552
                    if p["var3"] < sl]
 
553
        # sort lists (indexing does not guarantee that rows are returned in
 
554
        # order)
 
555
        results1.sort(); results2.sort()
 
556
        if verbose:
 
557
            print "Limit:", sl
 
558
            print "Selection results (index):", results1
 
559
            print "Should look like:", results2
 
560
            print "Length results:", len(results1)
 
561
            print "Should be:", len(results2)
 
562
        assert len(results1) == len(results2)
 
563
        assert results1 == results2
 
564
 
 
565
        # Second selection
 
566
        results1 = [p["var3"] for p in table1.where(t1col <= sl)]
 
567
        results2 = [p["var3"] for p in table2
 
568
                    if p["var3"] <= sl]
 
569
        # sort lists (indexing does not guarantee that rows are returned in
 
570
        # order)
 
571
        results1.sort(); results2.sort()
 
572
        if verbose:
 
573
            print "Limit:", sl
 
574
#             print "Selection results (index):", results1
 
575
#             print "Should look like:", results2
 
576
            print "Length results:", len(results1)
 
577
            print "Should be:", len(results2)
 
578
        assert len(results1) == len(results2)
 
579
        assert results1 == results2
 
580
 
 
581
        # Third selection
 
582
        results1 = [p["var3"] for p in table1.where(t1col > sl)]
 
583
        results2 = [p["var3"] for p in table2
 
584
                    if p["var3"] > sl]
 
585
        # sort lists (indexing does not guarantee that rows are returned in
 
586
        # order)
 
587
        results1.sort(); results2.sort()
 
588
        if verbose:
 
589
            print "Limit:", sl
 
590
#             print "Selection results (index):", results1
 
591
#             print "Should look like:", results2
 
592
            print "Length results:", len(results1)
 
593
            print "Should be:", len(results2)
 
594
        assert len(results1) == len(results2)
 
595
        assert results1 == results2
 
596
 
 
597
        # Fourth selection
 
598
        results1 = [p["var3"] for p in table1.where(t1col >= sl)]
 
599
        results2 = [p["var3"] for p in table2
 
600
                    if p["var3"] >= sl]
 
601
        # sort lists (indexing does not guarantee that rows are returned in
 
602
        # order)
 
603
        results1.sort(); results2.sort()
 
604
        if verbose:
 
605
            print "Limit:", sl
 
606
#             print "Selection results (index):", results1
 
607
#             print "Should look like:", results2
 
608
            print "Length results:", len(results1)
 
609
            print "Should be:", len(results2)
 
610
        assert len(results1) == len(results2)
 
611
        assert results1 == results2
 
612
 
448
613
    def test04a(self):
449
614
        """Checking selecting values from an Index (float flavor)"""
450
615
 
1156
1321
 
1157
1322
 
1158
1323
    def test09a(self):
1159
 
        """Checking whereInRange (string flavor)"""
 
1324
        """Checking _whereInRange (string flavor)"""
1160
1325
 
1161
1326
        if verbose:
1162
1327
            print '\n', '-=' * 30
1173
1338
        t1col = table1.cols.var1
1174
1339
        #print "t1col-->", t1col[:]
1175
1340
        # First selection
1176
 
        results1 = [p['var1'] for p in table1.whereInRange(t1col<=sl,2,10)]
 
1341
        results1 = [p['var1'] for p in table1._whereInRange(t1col<=sl,2,10)]
1177
1342
        results2 = [p["var1"] for p in table2.iterrows(2, 10)
1178
1343
                    if p["var1"] <= sl]
1179
1344
        if verbose:
1186
1351
        assert results1 == results2
1187
1352
 
1188
1353
        # Second selection
1189
 
        results1 = [p['var1'] for p in table1.whereInRange(il<t1col<sl,2,30,2)]
 
1354
        results1 = [p['var1'] for p in table1._whereInRange(il<t1col<sl,2,30,2)]
1190
1355
        results2 = [p["var1"] for p in table2.iterrows(2,30,2)
1191
1356
                    if il<p["var1"]<sl]
1192
1357
        if verbose:
1199
1364
        assert results1 == results2
1200
1365
 
1201
1366
        # Third selection
1202
 
        results1 = [p['var1'] for p in table1.whereInRange(il>t1col>sl,2,-5)]
 
1367
        results1 = [p['var1'] for p in table1._whereInRange(il>t1col>sl,2,-5)]
1203
1368
        results2 = [p["var1"] for p in table2.iterrows(2, -5)  # Negative indices
1204
1369
                    if (il > p["var1"] > sl)]
1205
1370
        if verbose:
1213
1378
        assert results1 == results2
1214
1379
 
1215
1380
        # This selection to be commented out
1216
 
#         results1 = [p['var1'] for p in table1.whereInRange(t1col>=sl,2,-1,1)]
 
1381
#         results1 = [p['var1'] for p in table1._whereInRange(t1col>=sl,2,-1,1)]
1217
1382
#         results2 = [p["var1"] for p in table2.iterrows(2, -1, 1)
1218
1383
#                     if p["var1"] >= sl]
1219
1384
#         if verbose:
1227
1392
 
1228
1393
        # Fourth selection
1229
1394
        #print "t1col-->", t1col[:]
1230
 
        #results1 = [p['var1'] for p in table1.whereInRange(t1col>=sl,2,-1,3)]
1231
 
        results1 = [p['var1'] for p in table1.whereInRange(t1col>=sl,2,-1,3)]
 
1395
        #results1 = [p['var1'] for p in table1._whereInRange(t1col>=sl,2,-1,3)]
 
1396
        results1 = [p['var1'] for p in table1._whereInRange(t1col>=sl,2,-1,3)]
1232
1397
        results2 = [p["var1"] for p in table2.iterrows(2, -1, 3)
1233
1398
                    if p["var1"] >= sl]
1234
1399
        if verbose:
1241
1406
        assert results1 == results2
1242
1407
 
1243
1408
    def test09b(self):
1244
 
        """Checking whereInRange (float flavor)"""
 
1409
        """Checking _whereInRange (float flavor)"""
1245
1410
 
1246
1411
        if verbose:
1247
1412
            print '\n', '-=' * 30
1258
1423
        t1col = table1.cols.var4
1259
1424
 
1260
1425
        # First selection
1261
 
        results1 = [p['var4'] for p in table1.whereInRange(t1col < sl, 2, 5)]
 
1426
        results1 = [p['var4'] for p in table1._whereInRange(t1col < sl, 2, 5)]
1262
1427
        results2 = [p["var4"] for p in table2.iterrows(2, 5)
1263
1428
                    if p["var4"] < sl]
1264
1429
        if verbose:
1271
1436
        assert results1 == results2
1272
1437
 
1273
1438
        # Second selection
1274
 
        results1 = [p['var4'] for p in table1.whereInRange(il < t1col<=sl, 2, -1, 2)]
 
1439
        results1 = [p['var4'] for p in table1._whereInRange(il < t1col<=sl, 2, -1, 2)]
1275
1440
        results2 = [p["var4"] for p in table2.iterrows(2,-1,2)
1276
1441
                    if il < p["var4"] <= sl]
1277
1442
        if verbose:
1284
1449
        assert results1 == results2
1285
1450
 
1286
1451
        # Third selection
1287
 
        results1 = [p['var4'] for p in table1.whereInRange(il<=t1col<=sl, 2, -5)]
 
1452
        results1 = [p['var4'] for p in table1._whereInRange(il<=t1col<=sl, 2, -5)]
1288
1453
        results2 = [p["var4"] for p in table2.iterrows(2, -5)  # Negative indices
1289
1454
                    if il <= p["var4"] <= sl]
1290
1455
        if verbose:
1297
1462
        assert results1 == results2
1298
1463
 
1299
1464
        # Fourth selection
1300
 
        results1 = [p['var4'] for p in table1.whereInRange(t1col>=sl, 0, -1, 3)]
 
1465
        results1 = [p['var4'] for p in table1._whereInRange(t1col>=sl, 0, -1, 3)]
1301
1466
        results2 = [p["var4"] for p in table2.iterrows(0, -1, 3)
1302
1467
                    if p["var4"] >= sl]
1303
1468
        if verbose:
1310
1475
        assert results1 == results2
1311
1476
 
1312
1477
    def test09c(self):
1313
 
        """Checking whereInRange with ranges, changing step (string flavor)"""
 
1478
        """Checking _whereInRange with ranges, changing step (string flavor)"""
1314
1479
 
1315
1480
        if verbose:
1316
1481
            print '\n', '-=' * 30
1328
1493
        #print "t1col-->", t1col[:]
1329
1494
 
1330
1495
        # First selection
1331
 
        results1 = [p['var1'] for p in table1.whereInRange(t1col>=sl,2,-1,3)]
 
1496
        results1 = [p['var1'] for p in table1._whereInRange(t1col>=sl,2,-1,3)]
1332
1497
        results2 = [p["var1"] for p in table2.iterrows(2, -1, 3)
1333
1498
                    if p["var1"] >= sl]
1334
1499
        # sort lists (indexing does not guarantee that rows are returned in
1344
1509
        assert results1 == results2
1345
1510
 
1346
1511
        # Second selection
1347
 
        results1 = [p['var1'] for p in table1.whereInRange(t1col>=sl,5,-1,10)]
 
1512
        results1 = [p['var1'] for p in table1._whereInRange(t1col>=sl,5,-1,10)]
1348
1513
        results2 = [p["var1"] for p in table2.iterrows(5, -1, 10)
1349
1514
                    if p["var1"] >= sl]
1350
1515
        # sort lists (indexing does not guarantee that rows are returned in
1360
1525
        assert results1 == results2
1361
1526
 
1362
1527
        # Third selection
1363
 
        results1 = [p['var1'] for p in table1.whereInRange(t1col>=sl,5,-3,11)]
 
1528
        results1 = [p['var1'] for p in table1._whereInRange(t1col>=sl,5,-3,11)]
1364
1529
        results2 = [p["var1"] for p in table2.iterrows(5, -3, 11)
1365
1530
                    if p["var1"] >= sl]
1366
1531
        # sort lists (indexing does not guarantee that rows are returned in
1376
1541
        assert results1 == results2
1377
1542
 
1378
1543
        # Fourth selection
1379
 
        results1 = [p['var1'] for p in table1.whereInRange(t1col>=sl,2,-1,300)]
 
1544
        results1 = [p['var1'] for p in table1._whereInRange(t1col>=sl,2,-1,300)]
1380
1545
        results2 = [p["var1"] for p in table2.iterrows(2, -1, 300)
1381
1546
                    if p["var1"] >= sl]
1382
1547
        # sort lists (indexing does not guarantee that rows are returned in
1410
1575
        #print "t3col-->", t3col[:]
1411
1576
 
1412
1577
        # First selection
1413
 
        results1 = [p['var3'] for p in table1.whereInRange(t3col>=sl,2,-1,3)]
 
1578
        results1 = [p['var3'] for p in table1._whereInRange(t3col>=sl,2,-1,3)]
1414
1579
        results2 = [p["var3"] for p in table2.iterrows(2, -1, 3)
1415
1580
                    if p["var3"] >= sl]
1416
1581
        # sort lists (indexing does not guarantee that rows are returned in
1426
1591
        assert results1 == results2
1427
1592
 
1428
1593
        # Second selection
1429
 
        results1 = [p['var3'] for p in table1.whereInRange(t3col>=sl,5,-1,10)]
 
1594
        results1 = [p['var3'] for p in table1._whereInRange(t3col>=sl,5,-1,10)]
1430
1595
        results2 = [p["var3"] for p in table2.iterrows(5, -1, 10)
1431
1596
                    if p["var3"] >= sl]
1432
1597
        # sort lists (indexing does not guarantee that rows are returned in
1442
1607
        assert results1 == results2
1443
1608
 
1444
1609
        # Third selection
1445
 
        results1 = [p['var3'] for p in table1.whereInRange(t3col>=sl,5,-3,11)]
 
1610
        results1 = [p['var3'] for p in table1._whereInRange(t3col>=sl,5,-3,11)]
1446
1611
        results2 = [p["var3"] for p in table2.iterrows(5, -3, 11)
1447
1612
                    if p["var3"] >= sl]
1448
1613
        # sort lists (indexing does not guarantee that rows are returned in
1458
1623
        assert results1 == results2
1459
1624
 
1460
1625
        # Fourth selection
1461
 
        results1 = [p['var3'] for p in table1.whereInRange(t3col>=sl,2,-1,300)]
 
1626
        results1 = [p['var3'] for p in table1._whereInRange(t3col>=sl,2,-1,300)]
1462
1627
        results2 = [p["var3"] for p in table2.iterrows(2, -1, 300)
1463
1628
                    if p["var3"] >= sl]
1464
1629
        # sort lists (indexing does not guarantee that rows are returned in
1474
1639
        assert results1 == results2
1475
1640
 
1476
1641
    def test10a(self):
1477
 
        """Checking whereIndexed with ranges (string flavor)"""
 
1642
        """Checking _whereIndexed with ranges (string flavor)"""
1478
1643
 
1479
1644
        if verbose:
1480
1645
            print '\n', '-=' * 30
1491
1656
        t1col = table1.cols.var1
1492
1657
        #print "t1col-->", t1col[:]
1493
1658
        # First selection
1494
 
        #print "-->", table1.whereIndexed(t1col<=sl,2,10)
1495
 
        results1 = [p['var1'] for p in table1.whereIndexed(t1col<=sl,2,10)]
 
1659
        #print "-->", table1._whereIndexed(t1col<=sl,2,10)
 
1660
        results1 = [p['var1'] for p in table1._whereIndexed(t1col<=sl,2,10)]
1496
1661
        results2 = [p["var1"] for p in table2.iterrows(2, 10)
1497
1662
                    if p["var1"] <= sl]
1498
1663
        # sort lists (indexing does not guarantee that rows are returned in
1508
1673
        assert results1 == results2
1509
1674
 
1510
1675
        # Selection to be deleted
1511
 
        results1 = [p['var1'] for p in table1.whereIndexed(il<=t1col<=sl,2,30,1)]
 
1676
        results1 = [p['var1'] for p in table1._whereIndexed(il<=t1col<=sl,2,30,1)]
1512
1677
        results2 = [p["var1"] for p in table2.iterrows(2,30,1)
1513
1678
                    if il<=p["var1"]<=sl]
1514
1679
        # sort lists (indexing does not guarantee that rows are returned in
1524
1689
        assert results1 == results2
1525
1690
 
1526
1691
        # Second selection
1527
 
        results1 = [p['var1'] for p in table1.whereIndexed(il<=t1col<=sl,2,30,2)]
 
1692
        results1 = [p['var1'] for p in table1._whereIndexed(il<=t1col<=sl,2,30,2)]
1528
1693
        results2 = [p["var1"] for p in table2.iterrows(2,30,2)
1529
1694
                    if il<=p["var1"]<=sl]
1530
1695
        # sort lists (indexing does not guarantee that rows are returned in
1540
1705
        assert results1 == results2
1541
1706
 
1542
1707
        # Third selection
1543
 
        results1 = [p['var1'] for p in table1.whereIndexed(il<t1col<sl,2,-5)]
 
1708
        results1 = [p['var1'] for p in table1._whereIndexed(il<t1col<sl,2,-5)]
1544
1709
        results2 = [p["var1"] for p in table2.iterrows(2, -5)  # Negative indices
1545
1710
                    if (il < p["var1"] < sl)]
1546
1711
        # sort lists (indexing does not guarantee that rows are returned in
1556
1721
        assert results1 == results2
1557
1722
 
1558
1723
        # Fourth selection
1559
 
        results1 = [p['var1'] for p in table1.whereIndexed(t1col>=sl,1,-1,3)]
 
1724
        results1 = [p['var1'] for p in table1._whereIndexed(t1col>=sl,1,-1,3)]
1560
1725
        #print "results1-->", results1
1561
1726
        results2 = [p["var1"] for p in table2.iterrows(1, -1, 3)
1562
1727
                    if p["var1"] >= sl]
1573
1738
        assert results1 == results2
1574
1739
 
1575
1740
    def test10b(self):
1576
 
        """Checking whereIndexed with ranges (int flavor)"""
 
1741
        """Checking _whereIndexed with ranges (int flavor)"""
1577
1742
 
1578
1743
        if verbose:
1579
1744
            print '\n', '-=' * 30
1589
1754
        # Do some selections and check the results
1590
1755
        t3col = table1.cols.var3
1591
1756
        # First selection
1592
 
        #print "-->", table1.whereIndexed(t3col<=sl,2,10)
1593
 
        results1 = [p['var3'] for p in table1.whereIndexed(t3col<=sl,2,10)]
 
1757
        #print "-->", table1._whereIndexed(t3col<=sl,2,10)
 
1758
        results1 = [p['var3'] for p in table1._whereIndexed(t3col<=sl,2,10)]
1594
1759
        results2 = [p["var3"] for p in table2.iterrows(2, 10)
1595
1760
                    if p["var3"] <= sl]
1596
1761
        # sort lists (indexing does not guarantee that rows are returned in
1606
1771
        assert results1 == results2
1607
1772
 
1608
1773
        # Second selection
1609
 
        results1 = [p['var3'] for p in table1.whereIndexed(il<=t3col<=sl,2,30,2)]
 
1774
        results1 = [p['var3'] for p in table1._whereIndexed(il<=t3col<=sl,2,30,2)]
1610
1775
        results2 = [p["var3"] for p in table2.iterrows(2,30,2)
1611
1776
                    if il<=p["var3"]<=sl]
1612
1777
        # sort lists (indexing does not guarantee that rows are returned in
1622
1787
        assert results1 == results2
1623
1788
 
1624
1789
        # Third selection
1625
 
        results1 = [p['var3'] for p in table1.whereIndexed(il<t3col<sl,2,-5)]
 
1790
        results1 = [p['var3'] for p in table1._whereIndexed(il<t3col<sl,2,-5)]
1626
1791
        results2 = [p["var3"] for p in table2.iterrows(2, -5)  # Negative indices
1627
1792
                    if (il < p["var3"] < sl)]
1628
1793
        # sort lists (indexing does not guarantee that rows are returned in
1639
1804
 
1640
1805
        # Fourth selection
1641
1806
        #print "t3col-->", t3col[:]
1642
 
        results1 = [p['var3'] for p in table1.whereIndexed(t3col>=sl,1,-1,3)]
 
1807
        results1 = [p['var3'] for p in table1._whereIndexed(t3col>=sl,1,-1,3)]
1643
1808
        results2 = [p["var3"] for p in table2.iterrows(1, -1, 3)
1644
1809
                    if p["var3"] >= sl]
1645
1810
        # sort lists (indexing does not guarantee that rows are returned in
1655
1820
        assert results1 == results2
1656
1821
 
1657
1822
    def test10c(self):
1658
 
        """Checking whereIndexed with ranges, changing step (string flavor)"""
 
1823
        """Checking _whereIndexed with ranges, changing step (string flavor)"""
1659
1824
 
1660
1825
        if verbose:
1661
1826
            print '\n', '-=' * 30
1673
1838
        #print "t1col-->", t1col[:]
1674
1839
 
1675
1840
        # First selection
1676
 
        results1 = [p['var1'] for p in table1.whereIndexed(t1col>=sl,2,-1,3)]
 
1841
        results1 = [p['var1'] for p in table1._whereIndexed(t1col>=sl,2,-1,3)]
1677
1842
        results2 = [p["var1"] for p in table2.iterrows(2, -1, 3)
1678
1843
                    if p["var1"] >= sl]
1679
1844
        # sort lists (indexing does not guarantee that rows are returned in
1689
1854
        assert results1 == results2
1690
1855
 
1691
1856
        # Second selection
1692
 
        results1 = [p['var1'] for p in table1.whereIndexed(t1col>=sl,5,-1,10)]
 
1857
        results1 = [p['var1'] for p in table1._whereIndexed(t1col>=sl,5,-1,10)]
1693
1858
        results2 = [p["var1"] for p in table2.iterrows(5, -1, 10)
1694
1859
                    if p["var1"] >= sl]
1695
1860
        # sort lists (indexing does not guarantee that rows are returned in
1705
1870
        assert results1 == results2
1706
1871
 
1707
1872
        # Third selection
1708
 
        results1 = [p['var1'] for p in table1.whereIndexed(t1col>=sl,5,-3,11)]
 
1873
        results1 = [p['var1'] for p in table1._whereIndexed(t1col>=sl,5,-3,11)]
1709
1874
        results2 = [p["var1"] for p in table2.iterrows(5, -3, 11)
1710
1875
                    if p["var1"] >= sl]
1711
1876
        # sort lists (indexing does not guarantee that rows are returned in
1721
1886
        assert results1 == results2
1722
1887
 
1723
1888
        # Fourth selection
1724
 
        results1 = [p['var1'] for p in table1.whereIndexed(t1col>=sl,2,-1,300)]
 
1889
        results1 = [p['var1'] for p in table1._whereIndexed(t1col>=sl,2,-1,300)]
1725
1890
        results2 = [p["var1"] for p in table2.iterrows(2, -1, 300)
1726
1891
                    if p["var1"] >= sl]
1727
1892
        # sort lists (indexing does not guarantee that rows are returned in
1737
1902
        assert results1 == results2
1738
1903
 
1739
1904
    def test10d(self):
1740
 
        """Checking whereIndexed with ranges, changing step (int flavor)"""
 
1905
        """Checking _whereIndexed with ranges, changing step (int flavor)"""
1741
1906
 
1742
1907
        if verbose:
1743
1908
            print '\n', '-=' * 30
1755
1920
        #print "t3col-->", t3col[:]
1756
1921
 
1757
1922
        # First selection
1758
 
        results1 = [p['var3'] for p in table1.whereIndexed(t3col>=sl,2,-1,3)]
 
1923
        results1 = [p['var3'] for p in table1._whereIndexed(t3col>=sl,2,-1,3)]
1759
1924
        results2 = [p["var3"] for p in table2.iterrows(2, -1, 3)
1760
1925
                    if p["var3"] >= sl]
1761
1926
        # sort lists (indexing does not guarantee that rows are returned in
1771
1936
        assert results1 == results2
1772
1937
 
1773
1938
        # Second selection
1774
 
        results1 = [p['var3'] for p in table1.whereIndexed(t3col>=sl,5,-1,10)]
 
1939
        results1 = [p['var3'] for p in table1._whereIndexed(t3col>=sl,5,-1,10)]
1775
1940
        results2 = [p["var3"] for p in table2.iterrows(5, -1, 10)
1776
1941
                    if p["var3"] >= sl]
1777
1942
        # sort lists (indexing does not guarantee that rows are returned in
1787
1952
        assert results1 == results2
1788
1953
 
1789
1954
        # Third selection
1790
 
        results1 = [p['var3'] for p in table1.whereIndexed(t3col>=sl,5,-3,11)]
 
1955
        results1 = [p['var3'] for p in table1._whereIndexed(t3col>=sl,5,-3,11)]
1791
1956
        results2 = [p["var3"] for p in table2.iterrows(5, -3, 11)
1792
1957
                    if p["var3"] >= sl]
1793
1958
        # sort lists (indexing does not guarantee that rows are returned in
1803
1968
        assert results1 == results2
1804
1969
 
1805
1970
        # Fourth selection
1806
 
        results1 = [p['var3'] for p in table1.whereIndexed(t3col>=sl,2,-1,300)]
 
1971
        results1 = [p['var3'] for p in table1._whereIndexed(t3col>=sl,2,-1,300)]
1807
1972
        results2 = [p["var3"] for p in table2.iterrows(2, -1, 300)
1808
1973
                    if p["var3"] >= sl]
1809
1974
        # sort lists (indexing does not guarantee that rows are returned in
1818
1983
        assert len(results1) == len(results2)
1819
1984
        assert results1 == results2
1820
1985
 
 
1986
    def test11a(self):
 
1987
        """Checking selecting values from an Index via readCoordinates()"""
 
1988
 
 
1989
        if verbose:
 
1990
            print '\n', '-=' * 30
 
1991
            print "Running %s.test11a..." % self.__class__.__name__
 
1992
 
 
1993
        table1 = self.fileh.root.table1
 
1994
        table2 = self.fileh.root.table2
 
1995
 
 
1996
        # Convert the limits to the appropriate type
 
1997
        il = str(self.il)
 
1998
        sl = str(self.sl)
 
1999
 
 
2000
        # Do a selection and check the result
 
2001
        t1var1 = table1.cols.var1
 
2002
        coords1 = table1.getWhereList(il <= t1var1 <= sl)
 
2003
        results1 = table1.readCoordinates(coords1, field="var1", flavor="List")
 
2004
        results2 = [p["var1"] for p in table2
 
2005
                    if il <= p["var1"] <= sl]
 
2006
        results1.sort(); results2.sort()
 
2007
        if verbose:
 
2008
#             print "Superior & inferior limits:", il, sl
 
2009
#             print "Selection results (index):", results1
 
2010
#             print "Should look like:", results2
 
2011
            print "Length results:", len(results1)
 
2012
            print "Should be:", len(results2)
 
2013
        assert len(results1) == len(results2)
 
2014
        assert results1 == results2
 
2015
 
1821
2016
 
1822
2017
class SV1aTestCase(SelectValuesTestCase):
1823
2018
    minRowIndex = 10
2071
2266
    niter = 1
2072
2267
    #heavy = 1  # Uncomment this only for testing purposes!
2073
2268
 
2074
 
    #theSuite.addTest(unittest.makeSuite(SV14aTestCase))
2075
 
    #theSuite.addTest(unittest.makeSuite(SV9aTestCase))
2076
 
#     for i in range(100):
2077
 
#         theSuite.addTest(unittest.makeSuite(SV9aTestCase))
2078
2269
    #theSuite.addTest(unittest.makeSuite(SV11aTestCase))
2079
2270
    #theSuite.addTest(unittest.makeSuite(SV4aTestCase))
2080
2271
    for n in range(niter):
2089
2280
        theSuite.addTest(unittest.makeSuite(SV11bTestCase))
2090
2281
        theSuite.addTest(unittest.makeSuite(SV12aTestCase))
2091
2282
        theSuite.addTest(unittest.makeSuite(SV12bTestCase))
2092
 
        theSuite.addTest(unittest.makeSuite(SV13aTestCase))
2093
 
        theSuite.addTest(unittest.makeSuite(SV13bTestCase))
2094
 
        theSuite.addTest(unittest.makeSuite(SV14aTestCase))
2095
2283
    if heavy:
2096
2284
        theSuite.addTest(unittest.makeSuite(SV1bTestCase))
2097
2285
        theSuite.addTest(unittest.makeSuite(SV2bTestCase))
2103
2291
        theSuite.addTest(unittest.makeSuite(SV8bTestCase))
2104
2292
        theSuite.addTest(unittest.makeSuite(SV9bTestCase))
2105
2293
        theSuite.addTest(unittest.makeSuite(SV10bTestCase))
 
2294
        theSuite.addTest(unittest.makeSuite(SV13aTestCase))
 
2295
        theSuite.addTest(unittest.makeSuite(SV13bTestCase))
 
2296
        theSuite.addTest(unittest.makeSuite(SV14aTestCase))
2106
2297
        theSuite.addTest(unittest.makeSuite(SV14bTestCase))
2107
2298
        # The next are too hard to be above
2108
2299
        theSuite.addTest(unittest.makeSuite(SV5aTestCase))
2112
2303
        # """Warning: Encountered invalid numeric result(s)  in less_equal"""
2113
2304
        # series of messages and I don't want to worry normal users
2114
2305
        # about this (I don't think this is grave anyway)
2115
 
        # F. Alted 2004-08-12
 
2306
        # F. Altet 2004-08-12
2116
2307
        theSuite.addTest(unittest.makeSuite(SV7aTestCase))
2117
2308
        theSuite.addTest(unittest.makeSuite(SV9aTestCase))
2118
2309
        theSuite.addTest(unittest.makeSuite(SV10aTestCase))
2119
 
    
 
2310
 
2120
2311
    return theSuite
2121
2312
 
2122
2313
if __name__ == '__main__':