/usr/lib/python2.7/dist-packages/tables/tests/test_indexes.py is in python-tables 3.1.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 | # -*- coding: utf-8 -*-
from __future__ import print_function
import unittest
import os
import tempfile
import copy
from tables import *
from tables.index import Index, default_auto_index, default_index_filters
from tables.idxutils import calc_chunksize
from tables.tests.common import verbose, allequal, heavy, cleanup, \
PyTablesTestCase, TempFileMixin
from tables.exceptions import OldIndexWarning
# To delete the internal attributes automagically
unittest.TestCase.tearDown = cleanup
import numpy
# Sensible parameters for indexing with small blocksizes
minRowIndex = 10
small_blocksizes = (96, 24, 6, 3)
class TDescr(IsDescription):
var1 = StringCol(itemsize=4, dflt=b"", pos=1)
var2 = BoolCol(dflt=0, pos=2)
var3 = IntCol(dflt=0, pos=3)
var4 = FloatCol(dflt=0, pos=4)
class BasicTestCase(PyTablesTestCase):
compress = 0
complib = "zlib"
shuffle = 0
fletcher32 = 0
nrows = minRowIndex
ss = small_blocksizes[2]
def setUp(self):
# Create an instance of an HDF5 Table
self.file = tempfile.mktemp(".h5")
self.fileh = open_file(self.file, "w")
self.rootgroup = self.fileh.root
self.populateFile()
# Close the file
self.fileh.close()
def populateFile(self):
group = self.rootgroup
# Create a table
title = "This is the IndexArray title"
self.filters = Filters(complevel=self.compress,
complib=self.complib,
shuffle=self.shuffle,
fletcher32=self.fletcher32)
table = self.fileh.create_table(group, 'table', TDescr, title,
self.filters, self.nrows)
for i in range(self.nrows):
table.row['var1'] = str(i).encode('ascii')
# table.row['var2'] = i > 2
table.row['var2'] = i % 2
table.row['var3'] = i
table.row['var4'] = float(self.nrows - i - 1)
table.row.append()
table.flush()
# Index all entries:
for col in table.colinstances.itervalues():
indexrows = col.create_index(_blocksizes=small_blocksizes)
if verbose:
print("Number of written rows:", self.nrows)
print("Number of indexed rows:", indexrows)
return
def tearDown(self):
self.fileh.close()
# print "File %s not removed!" % self.file
os.remove(self.file)
cleanup(self)
#----------------------------------------
def test00_flushLastRow(self):
"""Checking flushing an Index incrementing only the last row."""
if verbose:
print('\n', '-=' * 30)
print("Running %s.test00_flushLastRow..." %
self.__class__.__name__)
# Open the HDF5 file in append mode
self.fileh = open_file(self.file, mode="a")
table = self.fileh.root.table
# Add just 3 rows more
for i in range(3):
table.row['var1'] = str(i).encode('ascii')
table.row.append()
table.flush() # redo the indexes
idxcol = table.cols.var1.index
if verbose:
print("Max rows in buf:", table.nrowsinbuf)
print("Number of elements per slice:", idxcol.slicesize)
print("Chunk size:", idxcol.sorted.chunksize)
print("Elements in last row:", idxcol.indicesLR[-1])
# Do a selection
results = [p["var1"] for p in table.where('var1 == b"1"')]
self.assertEqual(len(results), 2)
self.assertEqual(results, [b'1']*2)
def test00_update(self):
"""Checking automatic re-indexing after an update operation."""
if verbose:
print('\n', '-=' * 30)
print("Running %s.test00_update..." % self.__class__.__name__)
# Open the HDF5 file in append mode
self.fileh = open_file(self.file, mode="a")
table = self.fileh.root.table
# Modify a couple of columns
for i, row in enumerate(table.where("(var3>1) & (var3<5)")):
row['var1'] = str(i)
row['var3'] = i
row.update()
table.flush() # redo the indexes
idxcol1 = table.cols.var1.index
idxcol3 = table.cols.var3.index
if verbose:
print("Dirtyness of var1 col:", idxcol1.dirty)
print("Dirtyness of var3 col:", idxcol3.dirty)
self.assertEqual(idxcol1.dirty, False)
self.assertEqual(idxcol3.dirty, False)
# Do a couple of selections
results = [p["var1"] for p in table.where('var1 == b"1"')]
self.assertEqual(len(results), 2)
self.assertEqual(results, [b'1']*2)
results = [p["var3"] for p in table.where('var3 == 0')]
self.assertEqual(len(results), 2)
self.assertEqual(results, [0]*2)
def test01_readIndex(self):
"""Checking reading an Index (string flavor)"""
if verbose:
print('\n', '-=' * 30)
print("Running %s.test01_readIndex..." % self.__class__.__name__)
# Open the HDF5 file in read-only mode
self.fileh = open_file(self.file, mode="r")
table = self.fileh.root.table
idxcol = table.cols.var1.index
if verbose:
print("Max rows in buf:", table.nrowsinbuf)
print("Number of elements per slice:", idxcol.slicesize)
print("Chunk size:", idxcol.sorted.chunksize)
# Do a selection
results = [p["var1"] for p in table.where('var1 == b"1"')]
self.assertEqual(len(results), 1)
self.assertEqual(results, [b'1'])
def test02_readIndex(self):
"""Checking reading an Index (bool flavor)"""
if verbose:
print('\n', '-=' * 30)
print("Running %s.test02_readIndex..." % self.__class__.__name__)
# Open the HDF5 file in read-only mode
self.fileh = open_file(self.file, mode="r")
table = self.fileh.root.table
idxcol = table.cols.var2.index
if verbose:
print("Rows in table:", table.nrows)
print("Max rows in buf:", table.nrowsinbuf)
print("Number of elements per slice:", idxcol.slicesize)
print("Chunk size:", idxcol.sorted.chunksize)
# Do a selection
results = [p["var2"] for p in table.where('var2 == True')]
if verbose:
print("Selected values:", results)
self.assertEqual(len(results), self.nrows // 2)
self.assertEqual(results, [True]*(self.nrows // 2))
def test03_readIndex(self):
"""Checking reading an Index (int flavor)"""
if verbose:
print('\n', '-=' * 30)
print("Running %s.test03_readIndex..." % self.__class__.__name__)
# Open the HDF5 file in read-only mode
self.fileh = open_file(self.file, mode="r")
table = self.fileh.root.table
idxcol = table.cols.var3.index
if verbose:
print("Max rows in buf:", table.nrowsinbuf)
print("Number of elements per slice:", idxcol.slicesize)
print("Chunk size:", idxcol.sorted.chunksize)
# Do a selection
results = [p["var3"] for p in table.where('(1<var3)&(var3<10)')]
if verbose:
print("Selected values:", results)
self.assertEqual(len(results), min(10, table.nrows) - 2)
self.assertEqual(results, range(2, min(10, table.nrows)))
def test04_readIndex(self):
"""Checking reading an Index (float flavor)"""
if verbose:
print('\n', '-=' * 30)
print("Running %s.test04_readIndex..." % self.__class__.__name__)
# Open the HDF5 file in read-only mode
self.fileh = open_file(self.file, mode="r")
table = self.fileh.root.table
idxcol = table.cols.var4.index
if verbose:
print("Max rows in buf:", table.nrowsinbuf)
print("Number of rows in table:", table.nrows)
print("Number of elements per slice:", idxcol.slicesize)
print("Chunk size:", idxcol.sorted.chunksize)
# Do a selection
results = [p["var4"] for p in table.where('var4 < 10')]
# results = [p["var4"] for p in table.where('(1<var4)&(var4<10)')]
if verbose:
print("Selected values:", results)
self.assertEqual(len(results), min(10, table.nrows))
self.assertEqual(results, [float(i) for i in
reversed(range(min(10, table.nrows)))])
def test05_getWhereList(self):
"""Checking reading an Index with get_where_list (string flavor)"""
if verbose:
print('\n', '-=' * 30)
print("Running %s.test05_getWhereList..." %
self.__class__.__name__)
# Open the HDF5 file in read-write mode
self.fileh = open_file(self.file, mode="a")
table = self.fileh.root.table
idxcol = table.cols.var4.index
if verbose:
print("Max rows in buf:", table.nrowsinbuf)
print("Number of elements per slice:", idxcol.slicesize)
print("Chunk size:", idxcol.sorted.chunksize)
# Do a selection
table.flavor = "python"
rowList1 = table.get_where_list('var1 < b"10"')
rowList2 = [p.nrow for p in table if p['var1'] < b"10"]
if verbose:
print("Selected values:", rowList1)
print("Should look like:", rowList2)
self.assertEqual(len(rowList1), len(rowList2))
self.assertEqual(rowList1, rowList2)
def test06_getWhereList(self):
"""Checking reading an Index with get_where_list (bool flavor)"""
if verbose:
print('\n', '-=' * 30)
print("Running %s.test06_getWhereList..." %
self.__class__.__name__)
# Open the HDF5 file in read-write mode
self.fileh = open_file(self.file, mode="a")
table = self.fileh.root.table
idxcol = table.cols.var2.index
if verbose:
print("Max rows in buf:", table.nrowsinbuf)
print("Rows in tables:", table.nrows)
print("Number of elements per slice:", idxcol.slicesize)
print("Chunk size:", idxcol.sorted.chunksize)
# Do a selection
table.flavor = "numpy"
rowList1 = table.get_where_list('var2 == False', sort=True)
rowList2 = [p.nrow for p in table if p['var2'] is False]
# Convert to a NumPy object
rowList2 = numpy.array(rowList2, numpy.int64)
if verbose:
print("Selected values:", rowList1)
print("Should look like:", rowList2)
self.assertEqual(len(rowList1), len(rowList2))
self.assertTrue(allequal(rowList1, rowList2))
def test07_getWhereList(self):
"""Checking reading an Index with get_where_list (int flavor)"""
if verbose:
print('\n', '-=' * 30)
print("Running %s.test07_getWhereList..." %
self.__class__.__name__)
# Open the HDF5 file in read-write mode
self.fileh = open_file(self.file, mode="a")
table = self.fileh.root.table
idxcol = table.cols.var4.index
if verbose:
print("Max rows in buf:", table.nrowsinbuf)
print("Number of elements per slice:", idxcol.slicesize)
print("Chunk size:", idxcol.sorted.chunksize)
# Do a selection
table.flavor = "python"
rowList1 = table.get_where_list('var3 < 15', sort=True)
rowList2 = [p.nrow for p in table if p["var3"] < 15]
if verbose:
print("Selected values:", rowList1)
print("Should look like:", rowList2)
self.assertEqual(len(rowList1), len(rowList2))
self.assertEqual(rowList1, rowList2)
def test08_getWhereList(self):
"""Checking reading an Index with get_where_list (float flavor)"""
if verbose:
print('\n', '-=' * 30)
print("Running %s.test08_getWhereList..." %
self.__class__.__name__)
# Open the HDF5 file in read-write mode
self.fileh = open_file(self.file, mode="a")
table = self.fileh.root.table
idxcol = table.cols.var4.index
if verbose:
print("Max rows in buf:", table.nrowsinbuf)
print("Number of elements per slice:", idxcol.slicesize)
print("Chunk size:", idxcol.sorted.chunksize)
# Do a selection
table.flavor = "python"
rowList1 = table.get_where_list('var4 < 10', sort=True)
rowList2 = [p.nrow for p in table if p['var4'] < 10]
if verbose:
print("Selected values:", rowList1)
print("Should look like:", rowList2)
self.assertEqual(len(rowList1), len(rowList2))
self.assertEqual(rowList1, rowList2)
def test09a_removeIndex(self):
"""Checking removing an index."""
if verbose:
print('\n', '-=' * 30)
print("Running %s.test09a_removeIndex..." %
self.__class__.__name__)
# Open the HDF5 file in read-write mode
self.fileh = open_file(self.file, mode="a")
table = self.fileh.root.table
idxcol = table.cols.var1.index
if verbose:
print("Before deletion")
print("var1 column:", table.cols.var1)
self.assertEqual(table.colindexed["var1"], 1)
self.assertTrue(idxcol is not None)
# delete the index
table.cols.var1.remove_index()
if verbose:
print("After deletion")
print("var1 column:", table.cols.var1)
self.assertTrue(table.cols.var1.index is None)
self.assertEqual(table.colindexed["var1"], 0)
# re-create the index again
indexrows = table.cols.var1.create_index(_blocksizes=small_blocksizes)
self.assertTrue(indexrows is not None)
idxcol = table.cols.var1.index
if verbose:
print("After re-creation")
print("var1 column:", table.cols.var1)
self.assertTrue(idxcol is not None)
self.assertEqual(table.colindexed["var1"], 1)
def test09b_removeIndex(self):
"""Checking removing an index (persistent version)"""
if verbose:
print('\n', '-=' * 30)
print("Running %s.test09b_removeIndex..." %
self.__class__.__name__)
# Open the HDF5 file in read-write mode
self.fileh = open_file(self.file, mode="a")
table = self.fileh.root.table
idxcol = table.cols.var1.index
if verbose:
print("Before deletion")
print("var1 index column:", table.cols.var1)
self.assertTrue(idxcol is not None)
self.assertEqual(table.colindexed["var1"], 1)
# delete the index
table.cols.var1.remove_index()
# close and reopen the file
self.fileh.close()
self.fileh = open_file(self.file, mode="a")
table = self.fileh.root.table
idxcol = table.cols.var1.index
if verbose:
print("After deletion")
print("var1 column:", table.cols.var1)
self.assertTrue(table.cols.var1.index is None)
self.assertEqual(table.colindexed["var1"], 0)
# re-create the index again
indexrows = table.cols.var1.create_index(_blocksizes=small_blocksizes)
self.assertTrue(indexrows is not None)
idxcol = table.cols.var1.index
if verbose:
print("After re-creation")
print("var1 column:", table.cols.var1)
self.assertTrue(idxcol is not None)
self.assertEqual(table.colindexed["var1"], 1)
def test10a_moveIndex(self):
"""Checking moving a table with an index."""
if verbose:
print('\n', '-=' * 30)
print("Running %s.test10a_moveIndex..." % self.__class__.__name__)
# Open the HDF5 file in read-write mode
self.fileh = open_file(self.file, mode="a")
table = self.fileh.root.table
idxcol = table.cols.var1.index
if verbose:
print("Before move")
print("var1 column:", idxcol)
self.assertEqual(table.colindexed["var1"], 1)
self.assertTrue(idxcol is not None)
# Create a new group called "agroup"
agroup = self.fileh.create_group("/", "agroup")
# move the table to "agroup"
table.move(agroup, "table2")
if verbose:
print("After move")
print("var1 column:", idxcol)
self.assertTrue(table.cols.var1.index is not None)
self.assertEqual(table.colindexed["var1"], 1)
# Some sanity checks
table.flavor = "python"
rowList1 = table.get_where_list('var1 < b"10"')
rowList2 = [p.nrow for p in table if p['var1'] < b"10"]
if verbose:
print("Selected values:", rowList1)
print("Should look like:", rowList2)
self.assertEqual(len(rowList1), len(rowList2))
self.assertEqual(rowList1, rowList2)
def test10b_moveIndex(self):
"""Checking moving a table with an index (persistent version)"""
if verbose:
print('\n', '-=' * 30)
print("Running %s.test10b_moveIndex..." % self.__class__.__name__)
# Open the HDF5 file in read-write mode
self.fileh = open_file(self.file, mode="a")
table = self.fileh.root.table
idxcol = table.cols.var1.index
if verbose:
print("Before move")
print("var1 index column:", idxcol)
self.assertTrue(idxcol is not None)
self.assertEqual(table.colindexed["var1"], 1)
# Create a new group called "agroup"
agroup = self.fileh.create_group("/", "agroup")
# move the table to "agroup"
table.move(agroup, "table2")
# close and reopen the file
self.fileh.close()
self.fileh = open_file(self.file, mode="a")
table = self.fileh.root.agroup.table2
idxcol = table.cols.var1.index
if verbose:
print("After move")
print("var1 column:", idxcol)
self.assertTrue(table.cols.var1.index is not None)
self.assertEqual(table.colindexed["var1"], 1)
# Some sanity checks
table.flavor = "python"
rowList1 = table.get_where_list('var1 < b"10"')
rowList2 = [p.nrow for p in table if p['var1'] < b"10"]
if verbose:
print("Selected values:", rowList1, type(rowList1))
print("Should look like:", rowList2, type(rowList2))
self.assertEqual(len(rowList1), len(rowList2))
self.assertEqual(rowList1, rowList2)
def test10c_moveIndex(self):
"""Checking moving a table with an index (small node cache)."""
if verbose:
print('\n', '-=' * 30)
print("Running %s.test10c_moveIndex..." % self.__class__.__name__)
# Open the HDF5 file in read-write mode
self.fileh = open_file(self.file, mode="a", node_cache_slots=10)
table = self.fileh.root.table
idxcol = table.cols.var1.index
if verbose:
print("Before move")
print("var1 column:", idxcol)
self.assertEqual(table.colindexed["var1"], 1)
self.assertTrue(idxcol is not None)
# Create a new group called "agroup"
agroup = self.fileh.create_group("/", "agroup")
# move the table to "agroup"
table.move(agroup, "table2")
if verbose:
print("After move")
print("var1 column:", idxcol)
self.assertTrue(table.cols.var1.index is not None)
self.assertEqual(table.colindexed["var1"], 1)
# Some sanity checks
table.flavor = "python"
rowList1 = table.get_where_list('var1 < b"10"')
rowList2 = [p.nrow for p in table if p['var1'] < b"10"]
if verbose:
print("Selected values:", rowList1)
print("Should look like:", rowList2)
self.assertEqual(len(rowList1), len(rowList2))
self.assertEqual(rowList1, rowList2)
def test10d_moveIndex(self):
"""Checking moving a table with an index (no node cache)."""
if verbose:
print('\n', '-=' * 30)
print("Running %s.test10d_moveIndex..." % self.__class__.__name__)
# Open the HDF5 file in read-write mode
self.fileh = open_file(self.file, mode="a", node_cache_slots=0)
table = self.fileh.root.table
idxcol = table.cols.var1.index
if verbose:
print("Before move")
print("var1 column:", idxcol)
self.assertEqual(table.colindexed["var1"], 1)
self.assertTrue(idxcol is not None)
# Create a new group called "agroup"
agroup = self.fileh.create_group("/", "agroup")
# move the table to "agroup"
table.move(agroup, "table2")
if verbose:
print("After move")
print("var1 column:", idxcol)
self.assertTrue(table.cols.var1.index is not None)
self.assertEqual(table.colindexed["var1"], 1)
# Some sanity checks
table.flavor = "python"
rowList1 = table.get_where_list('var1 < b"10"')
rowList2 = [p.nrow for p in table if p['var1'] < b"10"]
if verbose:
print("Selected values:", rowList1)
print("Should look like:", rowList2)
self.assertEqual(len(rowList1), len(rowList2))
self.assertEqual(rowList1, rowList2)
def test11a_removeTableWithIndex(self):
"""Checking removing a table with indexes."""
if verbose:
print('\n', '-=' * 30)
print("Running %s.test11a_removeTableWithIndex..." %
self.__class__.__name__)
# Open the HDF5 file in read-write mode
self.fileh = open_file(self.file, mode="a")
table = self.fileh.root.table
idxcol = table.cols.var1.index
if verbose:
print("Before deletion")
print("var1 column:", table.cols.var1)
self.assertEqual(table.colindexed["var1"], 1)
self.assertTrue(idxcol is not None)
# delete the table
self.fileh.remove_node("/table")
if verbose:
print("After deletion")
self.assertTrue("table" not in self.fileh.root)
# re-create the table and the index again
table = self.fileh.create_table("/", 'table', TDescr, "New table",
self.filters, self.nrows)
for i in range(self.nrows):
table.row['var1'] = str(i)
table.row['var2'] = i % 2
table.row['var3'] = i
table.row['var4'] = float(self.nrows - i - 1)
table.row.append()
table.flush()
# Index all entries:
for col in table.colinstances.itervalues():
indexrows = col.create_index(_blocksizes=small_blocksizes)
self.assertTrue(indexrows is not None)
idxcol = table.cols.var1.index
if verbose:
print("After re-creation")
print("var1 column:", table.cols.var1)
self.assertTrue(idxcol is not None)
self.assertEqual(table.colindexed["var1"], 1)
def test11b_removeTableWithIndex(self):
"""Checking removing a table with indexes (persistent version 2)"""
if verbose:
print('\n', '-=' * 30)
print("Running %s.test11b_removeTableWithIndex..." %
self.__class__.__name__)
self.fileh = open_file(self.file, mode="a")
table = self.fileh.root.table
idxcol = table.cols.var1.index
if verbose:
print("Before deletion")
print("var1 column:", table.cols.var1)
self.assertEqual(table.colindexed["var1"], 1)
self.assertTrue(idxcol is not None)
# delete the table
self.fileh.remove_node("/table")
if verbose:
print("After deletion")
self.assertTrue("table" not in self.fileh.root)
# close and reopen the file
self.fileh.close()
self.fileh = open_file(self.file, mode="r+")
# re-create the table and the index again
table = self.fileh.create_table("/", 'table', TDescr, "New table",
self.filters, self.nrows)
for i in range(self.nrows):
table.row['var1'] = str(i)
table.row['var2'] = i % 2
table.row['var3'] = i
table.row['var4'] = float(self.nrows - i - 1)
table.row.append()
table.flush()
# Index all entries:
for col in table.colinstances.itervalues():
indexrows = col.create_index(_blocksizes=small_blocksizes)
self.assertTrue(indexrows is not None)
idxcol = table.cols.var1.index
if verbose:
print("After re-creation")
print("var1 column:", table.cols.var1)
self.assertTrue(idxcol is not None)
self.assertEqual(table.colindexed["var1"], 1)
# Test provided by Andrew Straw
def test11c_removeTableWithIndex(self):
"""Checking removing a table with indexes (persistent version 3)"""
if verbose:
print('\n', '-=' * 30)
print("Running %s.test11c_removeTableWithIndex..." %
self.__class__.__name__)
class Distance(IsDescription):
frame = Int32Col(pos=0)
distance = FloatCol(pos=1)
# Delete the old temporal file
os.remove(self.file)
self.file = tempfile.mktemp(".h5")
self.fileh = open_file(self.file, mode='w')
table = self.fileh.create_table(
self.fileh.root, 'distance_table', Distance)
table.cols.frame.create_index(_blocksizes=small_blocksizes)
r = table.row
for i in range(10):
r['frame'] = i
r['distance'] = float(i**2)
r.append()
table.flush()
self.fileh.close()
self.fileh = open_file(self.file, mode='r+')
self.fileh.remove_node(self.fileh.root.distance_table)
small_ss = small_blocksizes[2]
class BasicReadTestCase(BasicTestCase):
compress = 0
complib = "zlib"
shuffle = 0
fletcher32 = 0
nrows = small_ss
class ZlibReadTestCase(BasicTestCase):
compress = 1
complib = "zlib"
shuffle = 0
fletcher32 = 0
nrows = small_ss
class BloscReadTestCase(BasicTestCase):
compress = 1
complib = "blosc"
shuffle = 0
fletcher32 = 0
nrows = small_ss
class LZOReadTestCase(BasicTestCase):
compress = 1
complib = "lzo"
shuffle = 0
fletcher32 = 0
nrows = small_ss
class Bzip2ReadTestCase(BasicTestCase):
compress = 1
complib = "bzip2"
shuffle = 0
fletcher32 = 0
nrows = small_ss
class ShuffleReadTestCase(BasicTestCase):
compress = 1
complib = "zlib"
shuffle = 1
fletcher32 = 0
nrows = small_ss
class Fletcher32ReadTestCase(BasicTestCase):
compress = 1
complib = "zlib"
shuffle = 0
fletcher32 = 1
nrows = small_ss
class ShuffleFletcher32ReadTestCase(BasicTestCase):
compress = 1
complib = "zlib"
shuffle = 1
fletcher32 = 1
nrows = small_ss
class OneHalfTestCase(BasicTestCase):
nrows = small_ss + small_ss//2
class UpperBoundTestCase(BasicTestCase):
nrows = small_ss + 1
class LowerBoundTestCase(BasicTestCase):
nrows = small_ss * 2-1
class DeepTableIndexTestCase(unittest.TestCase):
nrows = minRowIndex
def test01(self):
"Checking the indexing of a table in a 2nd level hierarchy"
# Create an instance of an HDF5 Table
self.file = tempfile.mktemp(".h5")
self.fileh = open_file(self.file, "w")
group = self.fileh.create_group(self.fileh.root, "agroup")
# Create a table
title = "This is the IndexArray title"
table = self.fileh.create_table(group, 'table', TDescr, title,
None, self.nrows)
for i in range(self.nrows):
# Fill rows with defaults
table.row.append()
table.flush()
# Index some column
indexrows = table.cols.var1.create_index()
self.assertTrue(indexrows is not None)
idxcol = table.cols.var1.index
# Some sanity checks
self.assertEqual(table.colindexed["var1"], 1)
self.assertTrue(idxcol is not None)
self.assertEqual(idxcol.nelements, self.nrows)
self.fileh.close()
os.remove(self.file)
def test01b(self):
"Checking the indexing of a table in 2nd level (persistent version)"
# Create an instance of an HDF5 Table
self.file = tempfile.mktemp(".h5")
self.fileh = open_file(self.file, "w")
group = self.fileh.create_group(self.fileh.root, "agroup")
# Create a table
title = "This is the IndexArray title"
table = self.fileh.create_table(group, 'table', TDescr, title,
None, self.nrows)
for i in range(self.nrows):
# Fill rows with defaults
table.row.append()
table.flush()
# Index some column
indexrows = table.cols.var1.create_index()
self.assertTrue(indexrows is not None)
idxcol = table.cols.var1.index
# Close and re-open this file
self.fileh.close()
self.fileh = open_file(self.file, "a")
table = self.fileh.root.agroup.table
idxcol = table.cols.var1.index
# Some sanity checks
self.assertEqual(table.colindexed["var1"], 1)
self.assertTrue(idxcol is not None)
self.assertEqual(idxcol.nelements, self.nrows)
self.fileh.close()
os.remove(self.file)
def test02(self):
"Checking the indexing of a table in a 4th level hierarchy"
# Create an instance of an HDF5 Table
self.file = tempfile.mktemp(".h5")
self.fileh = open_file(self.file, "w")
group = self.fileh.create_group(self.fileh.root, "agroup")
group = self.fileh.create_group(group, "agroup")
group = self.fileh.create_group(group, "agroup")
# Create a table
title = "This is the IndexArray title"
table = self.fileh.create_table(group, 'table', TDescr, title,
None, self.nrows)
for i in range(self.nrows):
# Fill rows with defaults
table.row.append()
table.flush()
# Index some column
indexrows = table.cols.var1.create_index()
self.assertTrue(indexrows is not None)
idxcol = table.cols.var1.index
# Some sanity checks
self.assertEqual(table.colindexed["var1"], 1)
self.assertTrue(idxcol is not None)
self.assertEqual(idxcol.nelements, self.nrows)
self.fileh.close()
os.remove(self.file)
def test02b(self):
"Checking the indexing of a table in a 4th level (persistent version)"
# Create an instance of an HDF5 Table
self.file = tempfile.mktemp(".h5")
self.fileh = open_file(self.file, "w")
group = self.fileh.create_group(self.fileh.root, "agroup")
group = self.fileh.create_group(group, "agroup")
group = self.fileh.create_group(group, "agroup")
# Create a table
title = "This is the IndexArray title"
table = self.fileh.create_table(group, 'table', TDescr, title,
None, self.nrows)
for i in range(self.nrows):
# Fill rows with defaults
table.row.append()
table.flush()
# Index some column
indexrows = table.cols.var1.create_index()
self.assertTrue(indexrows is not None)
idxcol = table.cols.var1.index
# Close and re-open this file
self.fileh.close()
self.fileh = open_file(self.file, "a")
table = self.fileh.root.agroup.agroup.agroup.table
idxcol = table.cols.var1.index
# Some sanity checks
self.assertEqual(table.colindexed["var1"], 1)
self.assertTrue(idxcol is not None)
self.assertEqual(idxcol.nelements, self.nrows)
self.fileh.close()
os.remove(self.file)
def test03(self):
"Checking the indexing of a table in a 100th level hierarchy"
# Create an instance of an HDF5 Table
self.file = tempfile.mktemp(".h5")
self.fileh = open_file(self.file, "w")
group = self.fileh.root
for i in range(100):
group = self.fileh.create_group(group, "agroup")
# Create a table
title = "This is the IndexArray title"
table = self.fileh.create_table(group, 'table', TDescr, title,
None, self.nrows)
for i in range(self.nrows):
# Fill rows with defaults
table.row.append()
table.flush()
# Index some column
indexrows = table.cols.var1.create_index()
self.assertTrue(indexrows is not None)
idxcol = table.cols.var1.index
# Some sanity checks
self.assertEqual(table.colindexed["var1"], 1)
self.assertTrue(idxcol is not None)
self.assertEqual(idxcol.nelements, self.nrows)
self.fileh.close()
os.remove(self.file)
class IndexProps(object):
def __init__(self, auto=default_auto_index, filters=default_index_filters):
self.auto = auto
self.filters = filters
DefaultProps = IndexProps()
NoAutoProps = IndexProps(auto=False)
ChangeFiltersProps = IndexProps(
filters=Filters(complevel=6, complib="zlib",
shuffle=False, fletcher32=False))
class AutomaticIndexingTestCase(unittest.TestCase):
reopen = 1
iprops = NoAutoProps
colsToIndex = ['var1', 'var2', 'var3']
small_blocksizes = (16, 8, 4, 2)
def setUp(self):
# Create an instance of an HDF5 Table
self.file = tempfile.mktemp(".h5")
self.fileh = open_file(self.file, "w")
# Create a table
title = "This is the IndexArray title"
root = self.fileh.root
# Make the chunkshape smaller or equal than small_blocksizes[-1]
chunkshape = (2,)
self.table = self.fileh.create_table(root, 'table', TDescr, title,
None, self.nrows,
chunkshape=chunkshape)
self.table.autoindex = self.iprops.auto
for colname in self.colsToIndex:
self.table.colinstances[colname].create_index(
_blocksizes=self.small_blocksizes)
for i in range(self.nrows):
# Fill rows with defaults
self.table.row.append()
self.table.flush()
if self.reopen:
self.fileh.close()
self.fileh = open_file(self.file, "a")
self.table = self.fileh.root.table
def tearDown(self):
self.fileh.close()
os.remove(self.file)
cleanup(self)
def test01_attrs(self):
"Checking indexing attributes (part1)"
if verbose:
print('\n', '-=' * 30)
print("Running %s.test01_attrs..." % self.__class__.__name__)
table = self.table
if self.iprops is DefaultProps:
self.assertEqual(table.indexed, 0)
else:
self.assertEqual(table.indexed, 1)
if self.iprops is DefaultProps:
self.assertEqual(table.colindexed["var1"], 0)
self.assertTrue(table.cols.var1.index is None)
self.assertEqual(table.colindexed["var2"], 0)
self.assertTrue(table.cols.var2.index is None)
self.assertEqual(table.colindexed["var3"], 0)
self.assertTrue(table.cols.var3.index is None)
self.assertEqual(table.colindexed["var4"], 0)
self.assertTrue(table.cols.var4.index is None)
else:
# Check that the var1, var2 and var3 (and only these)
# has been indexed
self.assertEqual(table.colindexed["var1"], 1)
self.assertTrue(table.cols.var1.index is not None)
self.assertEqual(table.colindexed["var2"], 1)
self.assertTrue(table.cols.var2.index is not None)
self.assertEqual(table.colindexed["var3"], 1)
self.assertTrue(table.cols.var3.index is not None)
self.assertEqual(table.colindexed["var4"], 0)
self.assertTrue(table.cols.var4.index is None)
def test02_attrs(self):
"Checking indexing attributes (part2)"
if verbose:
print('\n', '-=' * 30)
print("Running %s.test02_attrs..." % self.__class__.__name__)
table = self.table
# Check the policy parameters
if verbose:
if table.indexed:
print("index props:", table.autoindex)
else:
print("Table is not indexed")
# Check non-default values for index saving policy
if self.iprops is NoAutoProps:
self.assertFalse(table.autoindex)
elif self.iprops is ChangeFiltersProps:
self.assertTrue(table.autoindex)
# Check Index() objects exists and are properly placed
if self.iprops is DefaultProps:
self.assertEqual(table.cols.var1.index, None)
self.assertEqual(table.cols.var2.index, None)
self.assertEqual(table.cols.var3.index, None)
self.assertEqual(table.cols.var4.index, None)
else:
self.assertTrue(isinstance(table.cols.var1.index, Index))
self.assertTrue(isinstance(table.cols.var2.index, Index))
self.assertTrue(isinstance(table.cols.var3.index, Index))
self.assertEqual(table.cols.var4.index, None)
def test03_counters(self):
"Checking indexing counters"
if verbose:
print('\n', '-=' * 30)
print("Running %s.test03_counters..." % self.__class__.__name__)
table = self.table
# Check the counters for indexes
if verbose:
if table.indexed:
print("indexedrows:", table._indexedrows)
print("unsavedindexedrows:", table._unsaved_indexedrows)
index = table.cols.var1.index
print("table rows:", table.nrows)
print("computed indexed rows:", index.nrows * index.slicesize)
else:
print("Table is not indexed")
if self.iprops is not DefaultProps:
index = table.cols.var1.index
indexedrows = index.nelements
self.assertEqual(table._indexedrows, indexedrows)
indexedrows = index.nelements
self.assertEqual(table._unsaved_indexedrows,
self.nrows - indexedrows)
def test04_noauto(self):
"Checking indexing counters (non-automatic mode)"
if verbose:
print('\n', '-=' * 30)
print("Running %s.test04_noauto..." % self.__class__.__name__)
table = self.table
# Force a sync in indexes
table.flush_rows_to_index()
# Check the counters for indexes
if verbose:
if table.indexed:
print("indexedrows:", table._indexedrows)
print("unsavedindexedrows:", table._unsaved_indexedrows)
index = table.cols.var1.index
print("computed indexed rows:", index.nelements)
else:
print("Table is not indexed")
# No unindexated rows should remain
index = table.cols.var1.index
if self.iprops is DefaultProps:
self.assertTrue(index is None)
else:
indexedrows = index.nelements
self.assertEqual(table._indexedrows, index.nelements)
self.assertEqual(table._unsaved_indexedrows,
self.nrows - indexedrows)
# Check non-default values for index saving policy
if self.iprops is NoAutoProps:
self.assertFalse(table.autoindex)
elif self.iprops is ChangeFiltersProps:
self.assertTrue(table.autoindex)
def test05_icounters(self):
"Checking indexing counters (remove_rows)"
if verbose:
print('\n', '-=' * 30)
print("Running %s.test05_icounters..." % self.__class__.__name__)
table = self.table
# Force a sync in indexes
table.flush_rows_to_index()
# Non indexated rows should remain here
if self.iprops is not DefaultProps:
indexedrows = table._indexedrows
unsavedindexedrows = table._unsaved_indexedrows
# Now, remove some rows:
table.remove_rows(2, 4)
if self.reopen:
self.fileh.close()
self.fileh = open_file(self.file, "a")
table = self.fileh.root.table
# Check the counters for indexes
if verbose:
if table.indexed:
print("indexedrows:", table._indexedrows)
print("original indexedrows:", indexedrows)
print("unsavedindexedrows:", table._unsaved_indexedrows)
print("original unsavedindexedrows:", unsavedindexedrows)
# index = table.cols.var1.index
print("index dirty:", table.cols.var1.index.dirty)
else:
print("Table is not indexed")
# Check the counters
self.assertEqual(table.nrows, self.nrows - 2)
if self.iprops is NoAutoProps:
self.assertTrue(table.cols.var1.index.dirty)
# Check non-default values for index saving policy
if self.iprops is NoAutoProps:
self.assertFalse(table.autoindex)
elif self.iprops is ChangeFiltersProps:
self.assertTrue(table.autoindex)
def test06_dirty(self):
"Checking dirty flags (remove_rows action)"
if verbose:
print('\n', '-=' * 30)
print("Running %s.test06_dirty..." % self.__class__.__name__)
table = self.table
# Force a sync in indexes
table.flush_rows_to_index()
# Now, remove some rows:
table.remove_rows(3, 5)
if self.reopen:
self.fileh.close()
self.fileh = open_file(self.file, "a")
table = self.fileh.root.table
# Check the dirty flag for indexes
if verbose:
print("auto flag:", table.autoindex)
for colname in table.colnames:
if table.cols._f_col(colname).index:
print("dirty flag col %s: %s" %
(colname, table.cols._f_col(colname).index.dirty))
# Check the flags
for colname in table.colnames:
if table.cols._f_col(colname).index:
if not table.autoindex:
self.assertEqual(table.cols._f_col(colname).index.dirty,
True)
else:
self.assertEqual(table.cols._f_col(colname).index.dirty,
False)
def test07_noauto(self):
"Checking indexing counters (modify_rows, no-auto mode)"
if verbose:
print('\n', '-=' * 30)
print("Running %s.test07_noauto..." % self.__class__.__name__)
table = self.table
# Force a sync in indexes
table.flush_rows_to_index()
# No unindexated rows should remain here
if self.iprops is not DefaultProps:
indexedrows = table._indexedrows
unsavedindexedrows = table._unsaved_indexedrows
# Now, modify just one row:
table.modify_rows(3, None, 1, [["asa", 0, 3, 3.1]])
if self.reopen:
self.fileh.close()
self.fileh = open_file(self.file, "a")
table = self.fileh.root.table
# Check the counters for indexes
if verbose:
if table.indexed:
print("indexedrows:", table._indexedrows)
print("original indexedrows:", indexedrows)
print("unsavedindexedrows:", table._unsaved_indexedrows)
print("original unsavedindexedrows:", unsavedindexedrows)
index = table.cols.var1.index
print("computed indexed rows:", index.nelements)
else:
print("Table is not indexed")
# Check the counters
self.assertEqual(table.nrows, self.nrows)
if self.iprops is NoAutoProps:
self.assertTrue(table.cols.var1.index.dirty)
# Check the dirty flag for indexes
if verbose:
for colname in table.colnames:
if table.cols._f_col(colname).index:
print("dirty flag col %s: %s" %
(colname, table.cols._f_col(colname).index.dirty))
for colname in table.colnames:
if table.cols._f_col(colname).index:
if not table.autoindex:
self.assertEqual(table.cols._f_col(colname).index.dirty,
True)
else:
self.assertEqual(table.cols._f_col(colname).index.dirty,
False)
def test07b_noauto(self):
"Checking indexing queries (modify in iterator, no-auto mode)"
if verbose:
print('\n', '-=' * 30)
print("Running %s.test07b_noauto..." % self.__class__.__name__)
table = self.table
# Force a sync in indexes
table.flush_rows_to_index()
# Do a query that uses indexes
res = [row.nrow for row in table.where('(var2 == True) & (var3 > 0)')]
# Now, modify just one row:
for row in table:
if row.nrow == 3:
row['var1'] = "asa"
row['var2'] = True
row['var3'] = 3
row['var4'] = 3.1
row.update()
table.flush()
if self.reopen:
self.fileh.close()
self.fileh = open_file(self.file, "a")
table = self.fileh.root.table
# Do a query that uses indexes
resq = [row.nrow for row in table.where('(var2 == True) & (var3 > 0)')]
res_ = res + [3]
if verbose:
print("AutoIndex?:", table.autoindex)
print("Query results (original):", res)
print("Query results (after modifying table):", resq)
print("Should look like:", res_)
self.assertEqual(res_, resq)
def test07c_noauto(self):
"Checking indexing queries (append, no-auto mode)"
if verbose:
print('\n', '-=' * 30)
print("Running %s.test07c_noauto..." % self.__class__.__name__)
table = self.table
# Force a sync in indexes
table.flush_rows_to_index()
# Do a query that uses indexes
res = [row.nrow for row in table.where('(var2 == True) & (var3 > 0)')]
# Now, append three rows
table.append([("asa", True, 1, 3.1)])
table.append([("asb", True, 2, 3.1)])
table.append([("asc", True, 3, 3.1)])
table.flush()
if self.reopen:
self.fileh.close()
self.fileh = open_file(self.file, "a")
table = self.fileh.root.table
# Do a query that uses indexes
resq = [row.nrow for row in table.where('(var2 == True) & (var3 > 0)')]
res_ = res + [table.nrows-3, table.nrows-2, table.nrows-1]
if verbose:
print("AutoIndex?:", table.autoindex)
print("Query results (original):", res)
print("Query results (after modifying table):", resq)
print("Should look like:", res_)
self.assertEqual(res_, resq)
def test08_dirty(self):
"Checking dirty flags (modify_columns)"
if verbose:
print('\n', '-=' * 30)
print("Running %s.test08_dirty..." % self.__class__.__name__)
table = self.table
# Force a sync in indexes
table.flush_rows_to_index()
# Non indexated rows should remain here
if self.iprops is not DefaultProps:
indexedrows = table._indexedrows
self.assertTrue(indexedrows is not None)
unsavedindexedrows = table._unsaved_indexedrows
self.assertTrue(unsavedindexedrows is not None)
# Now, modify a couple of rows:
table.modify_columns(1, columns=[["asa", "asb"], [1., 2.]],
names=["var1", "var4"])
if self.reopen:
self.fileh.close()
self.fileh = open_file(self.file, "a")
table = self.fileh.root.table
# Check the counters
self.assertEqual(table.nrows, self.nrows)
if self.iprops is NoAutoProps:
self.assertTrue(table.cols.var1.index.dirty)
# Check the dirty flag for indexes
if verbose:
for colname in table.colnames:
if table.cols._f_col(colname).index:
print("dirty flag col %s: %s" %
(colname, table.cols._f_col(colname).index.dirty))
for colname in table.colnames:
if table.cols._f_col(colname).index:
if not table.autoindex:
if colname in ["var1"]:
self.assertEqual(
table.cols._f_col(colname).index.dirty, True)
else:
self.assertEqual(
table.cols._f_col(colname).index.dirty, False)
else:
self.assertEqual(table.cols._f_col(colname).index.dirty,
False)
def test09a_propIndex(self):
"Checking propagate Index feature in Table.copy() (attrs)"
if verbose:
print('\n', '-=' * 30)
print("Running %s.test09a_propIndex..." % self.__class__.__name__)
table = self.table
# Don't force a sync in indexes
# table.flush_rows_to_index()
# Non indexated rows should remain here
if self.iprops is not DefaultProps:
indexedrows = table._indexedrows
self.assertTrue(indexedrows is not None)
unsavedindexedrows = table._unsaved_indexedrows
self.assertTrue(unsavedindexedrows is not None)
# Now, remove some rows to make columns dirty
# table.remove_rows(3,5)
# Copy a Table to another location
table2 = table.copy("/", 'table2', propindexes=True)
if self.reopen:
self.fileh.close()
self.fileh = open_file(self.file, "a")
table = self.fileh.root.table
table2 = self.fileh.root.table2
index1 = table.cols.var1.index
index2 = table2.cols.var1.index
if verbose:
print("Copied index:", index2)
print("Original index:", index1)
if index1:
print("Elements in copied index:", index2.nelements)
print("Elements in original index:", index1.nelements)
# Check the counters
self.assertEqual(table.nrows, table2.nrows)
if table.indexed:
self.assertTrue(table2.indexed)
if self.iprops is DefaultProps:
# No index: the index should not exist
self.assertTrue(index1 is None)
self.assertTrue(index2 is None)
elif self.iprops is NoAutoProps:
self.assertTrue(index2 is not None)
# Check the dirty flag for indexes
if verbose:
for colname in table2.colnames:
if table2.cols._f_col(colname).index:
print("dirty flag col %s: %s" %
(colname, table2.cols._f_col(colname).index.dirty))
for colname in table2.colnames:
if table2.cols._f_col(colname).index:
self.assertEqual(table2.cols._f_col(colname).index.dirty,
False)
def test09b_propIndex(self):
"Checking that propindexes=False works"
if verbose:
print('\n', '-=' * 30)
print("Running %s.test09b_propIndex..." % self.__class__.__name__)
table = self.table
# Don't force a sync in indexes
# table.flush_rows_to_index()
# Non indexated rows should remain here
if self.iprops is not DefaultProps:
indexedrows = table._indexedrows
self.assertTrue(indexedrows is not None)
unsavedindexedrows = table._unsaved_indexedrows
self.assertTrue(unsavedindexedrows is not None)
# Now, remove some rows to make columns dirty
# table.remove_rows(3,5)
# Copy a Table to another location
table2 = table.copy("/", 'table2', propindexes=False)
if self.reopen:
self.fileh.close()
self.fileh = open_file(self.file, "a")
table = self.fileh.root.table
table2 = self.fileh.root.table2
if verbose:
print("autoindex?:", self.iprops.auto)
print("Copied index indexed?:", table2.cols.var1.is_indexed)
print("Original index indexed?:", table.cols.var1.is_indexed)
if self.iprops is DefaultProps:
# No index: the index should not exist
self.assertFalse(table2.cols.var1.is_indexed)
self.assertFalse(table.cols.var1.is_indexed)
elif self.iprops is NoAutoProps:
self.assertFalse(table2.cols.var1.is_indexed)
self.assertTrue(table.cols.var1.is_indexed)
def test10_propIndex(self):
"Checking propagate Index feature in Table.copy() (values)"
if verbose:
print('\n', '-=' * 30)
print("Running %s.test10_propIndex..." % self.__class__.__name__)
table = self.table
# Don't force a sync in indexes
# table.flush_rows_to_index()
# Non indexated rows should remain here
if self.iprops is not DefaultProps:
indexedrows = table._indexedrows
self.assertTrue(indexedrows is not None)
unsavedindexedrows = table._unsaved_indexedrows
self.assertTrue(unsavedindexedrows is not None)
# Now, remove some rows to make columns dirty
# table.remove_rows(3,5)
# Copy a Table to another location
table2 = table.copy("/", 'table2', propindexes=True)
if self.reopen:
self.fileh.close()
self.fileh = open_file(self.file, "a")
table = self.fileh.root.table
table2 = self.fileh.root.table2
index1 = table.cols.var3.index
index2 = table2.cols.var3.index
if verbose:
print("Copied index:", index2)
print("Original index:", index1)
if index1:
print("Elements in copied index:", index2.nelements)
print("Elements in original index:", index1.nelements)
def test11_propIndex(self):
"Checking propagate Index feature in Table.copy() (dirty flags)"
if verbose:
print('\n', '-=' * 30)
print("Running %s.test11_propIndex..." % self.__class__.__name__)
table = self.table
# Force a sync in indexes
table.flush_rows_to_index()
# Non indexated rows should remain here
if self.iprops is not DefaultProps:
indexedrows = table._indexedrows
self.assertTrue(indexedrows is not None)
unsavedindexedrows = table._unsaved_indexedrows
self.assertTrue(unsavedindexedrows is not None)
# Now, modify an indexed column and an unindexed one
# to make the "var1" dirty
table.modify_columns(1, columns=[["asa", "asb"], [1., 2.]],
names=["var1", "var4"])
# Copy a Table to another location
table2 = table.copy("/", 'table2', propindexes=True)
if self.reopen:
self.fileh.close()
self.fileh = open_file(self.file, "a")
table = self.fileh.root.table
table2 = self.fileh.root.table2
index1 = table.cols.var1.index
index2 = table2.cols.var1.index
if verbose:
print("Copied index:", index2)
print("Original index:", index1)
if index1:
print("Elements in copied index:", index2.nelements)
print("Elements in original index:", index1.nelements)
# Check the dirty flag for indexes
if verbose:
for colname in table2.colnames:
if table2.cols._f_col(colname).index:
print("dirty flag col %s: %s" %
(colname, table2.cols._f_col(colname).index.dirty))
for colname in table2.colnames:
if table2.cols._f_col(colname).index:
if table2.autoindex:
# All the destination columns should be non-dirty because
# the copy removes the dirty state and puts the
# index in a sane state
self.assertEqual(table2.cols._f_col(colname).index.dirty,
False)
# minRowIndex = 10000 # just if one wants more indexed rows to be checked
class AI1TestCase(AutomaticIndexingTestCase):
# nrows = 10002
nrows = 102
reopen = 0
iprops = NoAutoProps
colsToIndex = ['var1', 'var2', 'var3']
class AI2TestCase(AutomaticIndexingTestCase):
# nrows = 10002
nrows = 102
reopen = 1
iprops = NoAutoProps
colsToIndex = ['var1', 'var2', 'var3']
class AI4bTestCase(AutomaticIndexingTestCase):
# nrows = 10012
nrows = 112
reopen = 1
iprops = NoAutoProps
colsToIndex = ['var1', 'var2', 'var3']
class AI5TestCase(AutomaticIndexingTestCase):
sbs, bs, ss, cs = calc_chunksize(minRowIndex, memlevel=1)
nrows = ss * 11-1
reopen = 0
iprops = NoAutoProps
colsToIndex = ['var1', 'var2', 'var3']
class AI6TestCase(AutomaticIndexingTestCase):
sbs, bs, ss, cs = calc_chunksize(minRowIndex, memlevel=1)
nrows = ss * 21 + 1
reopen = 1
iprops = NoAutoProps
colsToIndex = ['var1', 'var2', 'var3']
class AI7TestCase(AutomaticIndexingTestCase):
sbs, bs, ss, cs = calc_chunksize(minRowIndex, memlevel=1)
nrows = ss * 12-1
# nrows = ss * 1-1 # faster test
reopen = 0
iprops = NoAutoProps
colsToIndex = ['var1', 'var2', 'var3']
class AI8TestCase(AutomaticIndexingTestCase):
sbs, bs, ss, cs = calc_chunksize(minRowIndex, memlevel=1)
nrows = ss * 15 + 100
# nrows = ss * 1 + 100 # faster test
reopen = 1
iprops = NoAutoProps
colsToIndex = ['var1', 'var2', 'var3']
class AI9TestCase(AutomaticIndexingTestCase):
sbs, bs, ss, cs = calc_chunksize(minRowIndex, memlevel=1)
nrows = ss
reopen = 0
iprops = DefaultProps
colsToIndex = []
class AI10TestCase(AutomaticIndexingTestCase):
# nrows = 10002
nrows = 102
reopen = 1
iprops = DefaultProps
colsToIndex = []
class AI11TestCase(AutomaticIndexingTestCase):
# nrows = 10002
nrows = 102
reopen = 0
iprops = ChangeFiltersProps
colsToIndex = ['var1', 'var2', 'var3']
class AI12TestCase(AutomaticIndexingTestCase):
# nrows = 10002
nrows = 102
reopen = 0
iprops = ChangeFiltersProps
colsToIndex = ['var1', 'var2', 'var3']
class ManyNodesTestCase(PyTablesTestCase):
def setUp(self):
self.file = tempfile.mktemp(".h5")
self.fileh = open_file(self.file, "w", node_cache_slots=64)
def test00(self):
"""Indexing many nodes in one single session (based on bug #26)"""
IdxRecord = {
'f0': Int8Col(),
'f1': Int8Col(),
'f2': Int8Col(),
}
h5 = self.fileh
for qn in range(5):
for sn in range(5):
qchr = 'chr' + str(qn)
name = 'chr' + str(sn)
path = "/at/%s/pt" % (qchr)
table = h5.create_table(path, name, IdxRecord, createparents=1)
table.cols.f0.create_index()
table.cols.f1.create_index()
table.cols.f2.create_index()
table.row.append()
table.flush()
def tearDown(self):
self.fileh.close()
os.remove(self.file)
cleanup(self)
class IndexPropsChangeTestCase(TempFileMixin, PyTablesTestCase):
"""Test case for changing index properties in a table."""
class MyDescription(IsDescription):
icol = IntCol()
oldIndexProps = IndexProps()
newIndexProps = IndexProps(auto=False, filters=Filters(complevel=9))
def setUp(self):
super(IndexPropsChangeTestCase, self).setUp()
table = self.h5file.create_table('/', 'test', self.MyDescription)
table.autoindex = self.oldIndexProps.auto
row = table.row
for i in xrange(100):
row['icol'] = i % 25
row.append()
table.flush()
self.table = table
def tearDown(self):
super(IndexPropsChangeTestCase, self).tearDown()
def test_attributes(self):
"""Storing index properties as table attributes."""
for refprops in [self.oldIndexProps, self.newIndexProps]:
self.assertEqual(self.table.autoindex, refprops.auto)
self.table.autoindex = self.newIndexProps.auto
def test_copyattrs(self):
"""Copying index properties attributes."""
oldtable = self.table
newtable = oldtable.copy('/', 'test2')
self.assertEqual(oldtable.autoindex, newtable.autoindex)
class IndexFiltersTestCase(TempFileMixin, PyTablesTestCase):
"""Test case for setting index filters."""
def setUp(self):
super(IndexFiltersTestCase, self).setUp()
description = {'icol': IntCol()}
self.table = self.h5file.create_table('/', 'test', description)
def test_createIndex(self):
"""Checking input parameters in new indexes."""
# Different from default.
argfilters = copy.copy(default_index_filters)
argfilters.shuffle = not default_index_filters.shuffle
# Different both from default and the previous one.
idxfilters = copy.copy(default_index_filters)
idxfilters.shuffle = not default_index_filters.shuffle
idxfilters.fletcher32 = not default_index_filters.fletcher32
icol = self.table.cols.icol
# First create
icol.create_index(kind='ultralight', optlevel=4)
self.assertEqual(icol.index.kind, 'ultralight')
self.assertEqual(icol.index.optlevel, 4)
self.assertEqual(icol.index.filters, default_index_filters)
icol.remove_index()
# Second create
icol.create_index(kind='medium', optlevel=3, filters=argfilters)
self.assertEqual(icol.index.kind, 'medium')
self.assertEqual(icol.index.optlevel, 3)
self.assertEqual(icol.index.filters, argfilters)
icol.remove_index()
def test_reindex(self):
"""Checking input parameters in recomputed indexes."""
icol = self.table.cols.icol
icol.create_index(
kind='full', optlevel=5, filters=Filters(complevel=3))
kind = icol.index.kind
optlevel = icol.index.optlevel
filters = icol.index.filters
icol.reindex()
ni = icol.index
if verbose:
print("Old parameters: %s, %s, %s" % (kind, optlevel, filters))
print("New parameters: %s, %s, %s" % (
ni.kind, ni.optlevel, ni.filters))
self.assertEqual(ni.kind, kind)
self.assertEqual(ni.optlevel, optlevel)
self.assertEqual(ni.filters, filters)
class OldIndexTestCase(PyTablesTestCase):
def test1_x(self):
"""Check that files with 1.x indexes are recognized and warned."""
fname = self._testFilename("idx-std-1.x.h5")
f = open_file(fname)
self.assertWarns(OldIndexWarning, f.get_node, "/table")
f.close()
# Sensible parameters for indexing with small blocksizes
small_blocksizes = (512, 128, 32, 8)
class CompletelySortedIndexTestCase(TempFileMixin, PyTablesTestCase):
"""Test case for testing a complete sort in a table."""
nrows = 100
nrowsinbuf = 11
class MyDescription(IsDescription):
rcol = IntCol(pos=1)
icol = IntCol(pos=2)
def setUp(self):
super(CompletelySortedIndexTestCase, self).setUp()
table = self.h5file.create_table('/', 'table', self.MyDescription)
row = table.row
nrows = self.nrows
for i in xrange(nrows):
row['rcol'] = i
row['icol'] = nrows - i
row.append()
table.flush()
self.table = table
self.icol = self.table.cols.icol
# A full index with maximum optlevel should always be completely sorted
self.icol.create_csindex(_blocksizes=small_blocksizes)
def test00_isCompletelySortedIndex(self):
"""Testing the Column.is_csi property."""
icol = self.icol
self.assertEqual(icol.index.is_csi, True)
icol.remove_index()
# Other kinds than full, should never return a CSI
icol.create_index(kind="medium", optlevel=9)
self.assertEqual(icol.index.is_csi, False)
icol.remove_index()
# As the table is small, lesser optlevels should be able to
# create a completely sorted index too.
icol.create_index(kind="full", optlevel=6)
self.assertEqual(icol.index.is_csi, True)
# Checking a CSI in a sorted copy
self.table.copy("/", 'table2', sortby='icol', checkCSI=True)
self.assertEqual(icol.index.is_csi, True)
def test01_readSorted1(self):
"""Testing the Index.read_sorted() method with no arguments."""
icol = self.icol
sortedcol = numpy.sort(icol[:])
sortedcol2 = icol.index.read_sorted()
if verbose:
print("Original sorted column:", sortedcol)
print("The values from the index:", sortedcol2)
self.assertTrue(allequal(sortedcol, sortedcol2))
def test01_readSorted2(self):
"""Testing the Index.read_sorted() method with arguments (I)."""
icol = self.icol
sortedcol = numpy.sort(icol[:])[30:55]
sortedcol2 = icol.index.read_sorted(30, 55)
if verbose:
print("Original sorted column:", sortedcol)
print("The values from the index:", sortedcol2)
self.assertTrue(allequal(sortedcol, sortedcol2))
def test01_readSorted3(self):
"""Testing the Index.read_sorted() method with arguments (II)."""
icol = self.icol
sortedcol = numpy.sort(icol[:])[33:97]
sortedcol2 = icol.index.read_sorted(33, 97)
if verbose:
print("Original sorted column:", sortedcol)
print("The values from the index:", sortedcol2)
self.assertTrue(allequal(sortedcol, sortedcol2))
def test02_readIndices1(self):
"""Testing the Index.read_indices() method with no arguments."""
icol = self.icol
indicescol = numpy.argsort(icol[:]).astype('uint64')
indicescol2 = icol.index.read_indices()
if verbose:
print("Original indices column:", indicescol)
print("The values from the index:", indicescol2)
self.assertTrue(allequal(indicescol, indicescol2))
def test02_readIndices2(self):
"""Testing the Index.read_indices() method with arguments (I)."""
icol = self.icol
indicescol = numpy.argsort(icol[:])[30:55].astype('uint64')
indicescol2 = icol.index.read_indices(30, 55)
if verbose:
print("Original indices column:", indicescol)
print("The values from the index:", indicescol2)
self.assertTrue(allequal(indicescol, indicescol2))
def test02_readIndices3(self):
"""Testing the Index.read_indices() method with arguments (II)."""
icol = self.icol
indicescol = numpy.argsort(icol[:])[33:97].astype('uint64')
indicescol2 = icol.index.read_indices(33, 97)
if verbose:
print("Original indices column:", indicescol)
print("The values from the index:", indicescol2)
self.assertTrue(allequal(indicescol, indicescol2))
def test02_readIndices4(self):
"""Testing the Index.read_indices() method with arguments (III)."""
icol = self.icol
indicescol = numpy.argsort(icol[:])[33:97:2].astype('uint64')
indicescol2 = icol.index.read_indices(33, 97, 2)
if verbose:
print("Original indices column:", indicescol)
print("The values from the index:", indicescol2)
self.assertTrue(allequal(indicescol, indicescol2))
def test02_readIndices5(self):
"""Testing the Index.read_indices() method with arguments (IV)."""
icol = self.icol
indicescol = numpy.argsort(icol[:])[33:55:5].astype('uint64')
indicescol2 = icol.index.read_indices(33, 55, 5)
if verbose:
print("Original indices column:", indicescol)
print("The values from the index:", indicescol2)
self.assertTrue(allequal(indicescol, indicescol2))
def test02_readIndices6(self):
"""Testing the Index.read_indices() method with step only."""
icol = self.icol
indicescol = numpy.argsort(icol[:])[::3].astype('uint64')
indicescol2 = icol.index.read_indices(step=3)
if verbose:
print("Original indices column:", indicescol)
print("The values from the index:", indicescol2)
self.assertTrue(allequal(indicescol, indicescol2))
def test03_getitem1(self):
"""Testing the Index.__getitem__() method with no arguments."""
icol = self.icol
indicescol = numpy.argsort(icol[:]).astype('uint64')
indicescol2 = icol.index[:]
if verbose:
print("Original indices column:", indicescol)
print("The values from the index:", indicescol2)
self.assertTrue(allequal(indicescol, indicescol2))
def test03_getitem2(self):
"""Testing the Index.__getitem__() method with start."""
icol = self.icol
indicescol = numpy.argsort(icol[:])[31].astype('uint64')
indicescol2 = icol.index[31]
if verbose:
print("Original indices column:", indicescol)
print("The values from the index:", indicescol2)
self.assertTrue(allequal(indicescol, indicescol2))
def test03_getitem3(self):
"""Testing the Index.__getitem__() method with start, stop."""
icol = self.icol
indicescol = numpy.argsort(icol[:])[2:16].astype('uint64')
indicescol2 = icol.index[2:16]
if verbose:
print("Original indices column:", indicescol)
print("The values from the index:", indicescol2)
self.assertTrue(allequal(indicescol, indicescol2))
def test04_itersorted1(self):
"""Testing the Table.itersorted() method with no arguments."""
table = self.table
sortedtable = numpy.sort(table[:], order='icol')
sortedtable2 = numpy.array(
[row.fetch_all_fields() for row in table.itersorted(
'icol')], dtype=table._v_dtype)
if verbose:
print("Original sorted table:", sortedtable)
print("The values from the iterator:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
def test04_itersorted2(self):
"""Testing the Table.itersorted() method with a start."""
table = self.table
sortedtable = numpy.sort(table[:], order='icol')[15:]
sortedtable2 = numpy.array(
[row.fetch_all_fields() for row in table.itersorted(
'icol', start=15)], dtype=table._v_dtype)
if verbose:
print("Original sorted table:", sortedtable)
print("The values from the iterator:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
def test04_itersorted3(self):
"""Testing the Table.itersorted() method with a stop."""
table = self.table
sortedtable = numpy.sort(table[:], order='icol')[:20]
sortedtable2 = numpy.array(
[row.fetch_all_fields() for row in table.itersorted(
'icol', stop=20)], dtype=table._v_dtype)
if verbose:
print("Original sorted table:", sortedtable)
print("The values from the iterator:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
def test04_itersorted4(self):
"""Testing the Table.itersorted() method with a start and stop."""
table = self.table
sortedtable = numpy.sort(table[:], order='icol')[15:20]
sortedtable2 = numpy.array(
[row.fetch_all_fields() for row in table.itersorted(
'icol', start=15, stop=20)], dtype=table._v_dtype)
if verbose:
print("Original sorted table:", sortedtable)
print("The values from the iterator:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
def test04_itersorted5(self):
"""Testing the Table.itersorted() method with a start, stop and
step."""
table = self.table
sortedtable = numpy.sort(table[:], order='icol')[15:45:4]
sortedtable2 = numpy.array(
[row.fetch_all_fields() for row in table.itersorted(
'icol', start=15, stop=45, step=4)], dtype=table._v_dtype)
if verbose:
print("Original sorted table:", sortedtable)
print("The values from the iterator:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
def test04_itersorted6(self):
"""Testing the Table.itersorted() method with a start, stop and
step."""
table = self.table
sortedtable = numpy.sort(table[:], order='icol')[33:55:5]
sortedtable2 = numpy.array(
[row.fetch_all_fields() for row in table.itersorted(
'icol', start=33, stop=55, step=5)], dtype=table._v_dtype)
if verbose:
print("Original sorted table:", sortedtable)
print("The values from the iterator:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
def test04_itersorted7(self):
"""Testing the Table.itersorted() method with checkCSI=True."""
table = self.table
sortedtable = numpy.sort(table[:], order='icol')
sortedtable2 = numpy.array(
[row.fetch_all_fields() for row in table.itersorted(
'icol', checkCSI=True)], dtype=table._v_dtype)
if verbose:
print("Original sorted table:", sortedtable)
print("The values from the iterator:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
def test04_itersorted8(self):
"""Testing the Table.itersorted() method with a start, stop and
negative step."""
# see also gh-252
table = self.table
sortedtable = numpy.sort(table[:], order='icol')[55:33:-5]
sortedtable2 = numpy.array(
[row.fetch_all_fields() for row in table.itersorted(
'icol', start=55, stop=33, step=-5)], dtype=table._v_dtype)
if verbose:
print("Original sorted table:", sortedtable)
print("The values from the iterator:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
def test04_itersorted9(self):
"""Testing the Table.itersorted() method with a negative step."""
# see also gh-252
table = self.table
sortedtable = numpy.sort(table[:], order='icol')[::-5]
sortedtable2 = numpy.array(
[row.fetch_all_fields() for row in table.itersorted(
'icol', step=-5)], dtype=table._v_dtype)
if verbose:
print("Original sorted table:", sortedtable)
print("The values from the iterator:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
def test05_readSorted1(self):
"""Testing the Table.read_sorted() method with no arguments."""
table = self.table
sortedtable = numpy.sort(table[:], order='icol')
sortedtable2 = table.read_sorted('icol')
if verbose:
print("Original sorted table:", sortedtable)
print("The values from read_sorted:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
def test05_readSorted2(self):
"""Testing the Table.read_sorted() method with a start."""
table = self.table
sortedtable = numpy.sort(table[:], order='icol')[16:17]
sortedtable2 = table.read_sorted('icol', start=16)
if verbose:
print("Original sorted table:", sortedtable)
print("The values from read_sorted:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
def test05_readSorted3(self):
"""Testing the Table.read_sorted() method with a start and stop."""
table = self.table
sortedtable = numpy.sort(table[:], order='icol')[16:33]
sortedtable2 = table.read_sorted('icol', start=16, stop=33)
if verbose:
print("Original sorted table:", sortedtable)
print("The values from read_sorted:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
def test05_readSorted4(self):
"""Testing the Table.read_sorted() method with a start, stop and
step."""
table = self.table
sortedtable = numpy.sort(table[:], order='icol')[33:55:5]
sortedtable2 = table.read_sorted('icol', start=33, stop=55, step=5)
if verbose:
print("Original sorted table:", sortedtable)
print("The values from read_sorted:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
def test05_readSorted5(self):
"""Testing the Table.read_sorted() method with only a step."""
table = self.table
sortedtable = numpy.sort(table[:], order='icol')[::3]
sortedtable2 = table.read_sorted('icol', step=3)
if verbose:
print("Original sorted table:", sortedtable)
print("The values from read_sorted:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
def test05_readSorted6(self):
"""Testing the Table.read_sorted() method with negative step."""
table = self.table
sortedtable = numpy.sort(table[:], order='icol')[::-1]
sortedtable2 = table.read_sorted('icol', step=-1)
if verbose:
print("Original sorted table:", sortedtable)
print("The values from read_sorted:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
def test05_readSorted7(self):
"""Testing the Table.read_sorted() method with negative step (II)."""
table = self.table
sortedtable = numpy.sort(table[:], order='icol')[::-2]
sortedtable2 = table.read_sorted('icol', step=-2)
if verbose:
print("Original sorted table:", sortedtable)
print("The values from read_sorted:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
def test05_readSorted8(self):
"""Testing the Table.read_sorted() method with negative step (III))."""
table = self.table
sstart = 100-24-1
sstop = 100-54-1
sortedtable = numpy.sort(table[:], order='icol')[sstart:sstop:-1]
sortedtable2 = table.read_sorted('icol', start=24, stop=54, step=-1)
if verbose:
print("Original sorted table:", sortedtable)
print("The values from read_sorted:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
def test05_readSorted9(self):
"""Testing the Table.read_sorted() method with negative step (IV))."""
table = self.table
sstart = 100-14-1
sstop = 100-54-1
sortedtable = numpy.sort(table[:], order='icol')[sstart:sstop:-3]
sortedtable2 = table.read_sorted('icol', start=14, stop=54, step=-3)
if verbose:
print("Original sorted table:", sortedtable)
print("The values from read_sorted:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
def test05_readSorted10(self):
"""Testing the Table.read_sorted() method with negative step (V))."""
table = self.table
sstart = 100-24-1
sstop = 100-25-1
sortedtable = numpy.sort(table[:], order='icol')[sstart:sstop:-2]
sortedtable2 = table.read_sorted('icol', start=24, stop=25, step=-2)
if verbose:
print("Original sorted table:", sortedtable)
print("The values from read_sorted:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
def test05_readSorted11(self):
"""Testing the Table.read_sorted() method with start > stop."""
table = self.table
sstart = 100-137-1
sstop = 100-25-1
sortedtable = numpy.sort(table[:], order='icol')[sstart:sstop:-2]
sortedtable2 = table.read_sorted('icol', start=137, stop=25, step=-2)
if verbose:
print("Original sorted table:", sortedtable)
print("The values from read_sorted:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
def test05a_readSorted12(self):
"""Testing the Table.read_sorted() method with checkCSI (I)."""
table = self.table
sortedtable = numpy.sort(table[:], order='icol')
sortedtable2 = table.read_sorted('icol', checkCSI=True)
if verbose:
print("Original sorted table:", sortedtable)
print("The values from read_sorted:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
def test05b_readSorted12(self):
"""Testing the Table.read_sorted() method with checkCSI (II)."""
table = self.table
self.assertRaises(ValueError,
table.read_sorted, "rcol", checkCSI=False)
def test06_copy_sorted1(self):
"""Testing the Table.copy(sortby) method with no arguments."""
table = self.table
# Copy to another table
table.nrowsinbuf = self.nrowsinbuf
table2 = table.copy("/", 'table2', sortby="icol")
sortedtable = numpy.sort(table[:], order='icol')
sortedtable2 = table2[:]
if verbose:
print("Original sorted table:", sortedtable)
print("The values from copy:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
def test06_copy_sorted2(self):
"""Testing the Table.copy(sortby) method with step=-1."""
table = self.table
# Copy to another table
table.nrowsinbuf = self.nrowsinbuf
table2 = table.copy("/", 'table2', sortby="icol", step=-1)
sortedtable = numpy.sort(table[:], order='icol')[::-1]
sortedtable2 = table2[:]
if verbose:
print("Original sorted table:", sortedtable)
print("The values from copy:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
def test06_copy_sorted3(self):
"""Testing the Table.copy(sortby) method with only a start."""
table = self.table
# Copy to another table
table.nrowsinbuf = self.nrowsinbuf
table2 = table.copy("/", 'table2', sortby="icol", start=3)
sortedtable = numpy.sort(table[:], order='icol')[3:4]
sortedtable2 = table2[:]
if verbose:
print("Original sorted table:", sortedtable)
print("The values from copy:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
def test06_copy_sorted4(self):
"""Testing the Table.copy(sortby) method with start, stop."""
table = self.table
# Copy to another table
table.nrowsinbuf = self.nrowsinbuf
table2 = table.copy("/", 'table2', sortby="icol", start=3, stop=40)
sortedtable = numpy.sort(table[:], order='icol')[3:40]
sortedtable2 = table2[:]
if verbose:
print("Original sorted table:", sortedtable)
print("The values from copy:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
def test06_copy_sorted5(self):
"""Testing the Table.copy(sortby) method with start, stop, step."""
table = self.table
# Copy to another table
table.nrowsinbuf = self.nrowsinbuf
table2 = table.copy("/", 'table2', sortby="icol",
start=3, stop=33, step=5)
sortedtable = numpy.sort(table[:], order='icol')[3:33:5]
sortedtable2 = table2[:]
if verbose:
print("Original sorted table:", sortedtable)
print("The values from copy:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
def test06_copy_sorted6(self):
"""Testing the Table.copy(sortby) method after table re-opening."""
self._reopen(mode='a')
table = self.h5file.root.table
# Copy to another table
table.nrowsinbuf = self.nrowsinbuf
table2 = table.copy("/", 'table2', sortby="icol")
sortedtable = numpy.sort(table[:], order='icol')
sortedtable2 = table2[:]
if verbose:
print("Original sorted table:", sortedtable)
print("The values from copy:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
def test06_copy_sorted7(self):
"""Testing the `checkCSI` parameter of Table.copy() (I)."""
table = self.table
# Copy to another table
table.nrowsinbuf = self.nrowsinbuf
table2 = table.copy("/", 'table2', sortby="icol")
self.assertRaises(ValueError,
table2.copy, "/", 'table3',
sortby="rcol", checkCSI=False)
def test06_copy_sorted8(self):
"""Testing the `checkCSI` parameter of Table.copy() (II)."""
table = self.table
# Copy to another table
table.nrowsinbuf = self.nrowsinbuf
table2 = table.copy("/", 'table2', sortby="icol")
self.assertRaises(ValueError,
table2.copy, "/", 'table3',
sortby="rcol", checkCSI=True)
def test07_isCSI_noelements(self):
"""Testing the representation of an index with no elements."""
t2 = self.h5file.create_table('/', 't2', self.MyDescription)
irows = t2.cols.rcol.create_csindex()
if verbose:
print("repr(t2)-->\n", repr(t2))
self.assertEqual(irows, 0)
self.assertEqual(t2.colindexes['rcol'].is_csi, False)
class ReadSortedIndexTestCase(TempFileMixin, PyTablesTestCase):
"""Test case for testing sorted reading in a "full" sorted column."""
nrows = 100
nrowsinbuf = 11
class MyDescription(IsDescription):
rcol = IntCol(pos=1)
icol = IntCol(pos=2)
def setUp(self):
super(ReadSortedIndexTestCase, self).setUp()
table = self.h5file.create_table('/', 'table', self.MyDescription)
row = table.row
nrows = self.nrows
for i in xrange(nrows):
row['rcol'] = i
row['icol'] = nrows - i
row.append()
table.flush()
self.table = table
self.icol = self.table.cols.icol
# A full index with maximum optlevel should always be completely sorted
self.icol.create_index(optlevel=self.optlevel, kind="full",
_blocksizes=small_blocksizes)
def test01_readSorted1(self):
"""Testing the Table.read_sorted() method with no arguments."""
table = self.table
sortedtable = numpy.sort(table[:], order='icol')
sortedtable2 = table.read_sorted('icol')
if verbose:
print("Sorted table:", sortedtable)
print("The values from read_sorted:", sortedtable2)
# Compare with the sorted read table because we have no
# guarantees that read_sorted returns a completely sorted table
self.assertTrue(allequal(sortedtable,
numpy.sort(sortedtable2, order="icol")))
def test01_readSorted2(self):
"""Testing the Table.read_sorted() method with no arguments (re-open).
"""
self._reopen()
table = self.h5file.root.table
sortedtable = numpy.sort(table[:], order='icol')
sortedtable2 = table.read_sorted('icol')
if verbose:
print("Sorted table:", sortedtable)
print("The values from read_sorted:", sortedtable2)
# Compare with the sorted read table because we have no
# guarantees that read_sorted returns a completely sorted table
self.assertTrue(allequal(sortedtable,
numpy.sort(sortedtable2, order="icol")))
def test02_copy_sorted1(self):
"""Testing the Table.copy(sortby) method."""
table = self.table
# Copy to another table
table.nrowsinbuf = self.nrowsinbuf
table2 = table.copy("/", 'table2', sortby="icol")
sortedtable = numpy.sort(table[:], order='icol')
sortedtable2 = numpy.sort(table2[:], order='icol')
if verbose:
print("Original table:", table2[:])
print("The sorted values from copy:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
def test02_copy_sorted2(self):
"""Testing the Table.copy(sortby) method after table re-opening."""
self._reopen(mode='a')
table = self.h5file.root.table
# Copy to another table
table.nrowsinbuf = self.nrowsinbuf
table2 = table.copy("/", 'table2', sortby="icol")
sortedtable = numpy.sort(table[:], order='icol')
sortedtable2 = numpy.sort(table2[:], order='icol')
if verbose:
print("Original table:", table2[:])
print("The sorted values from copy:", sortedtable2)
self.assertTrue(allequal(sortedtable, sortedtable2))
class ReadSortedIndex0(ReadSortedIndexTestCase):
optlevel = 0
class ReadSortedIndex3(ReadSortedIndexTestCase):
optlevel = 3
class ReadSortedIndex6(ReadSortedIndexTestCase):
optlevel = 6
class ReadSortedIndex9(ReadSortedIndexTestCase):
optlevel = 9
class Issue156TestBase(PyTablesTestCase):
# field name in table according to which test_copysort() sorts the table
sort_field = None
def setUp(self):
# create hdf5 file
self.filename = tempfile.mktemp(".hdf5")
self.file = open_file(self.filename, mode="w")
# create nested table
class Foo(IsDescription):
frame = UInt16Col()
class Bar(IsDescription):
code = UInt16Col()
table = self.file.create_table('/', 'foo', Foo,
filters=Filters(3, 'zlib'),
createparents=True)
self.file.flush()
# fill table with 10 random numbers
for k in xrange(10):
row = table.row
row['frame'] = numpy.random.random_integers(0, 2**16-1)
row['Bar/code'] = numpy.random.random_integers(0, 2**16-1)
row.append()
self.file.flush()
def tearDown(self):
self.file.close()
os.remove(self.filename)
def test_copysort(self):
# copy table
oldNode = self.file.get_node('/foo')
# create completely sorted index on a main column
oldNode.colinstances[self.sort_field].create_csindex()
# this fails on ade2ba123efd267fd31
# see gh-156
new_node = oldNode.copy(newname='foo2', overwrite=True,
sortby=self.sort_field, checkCSI=True,
propindexes=True)
# check column is sorted
self.assertTrue(numpy.all(
new_node.col(self.sort_field) ==
sorted(oldNode.col(self.sort_field))))
# check index is available
self.assertTrue(self.sort_field in new_node.colindexes)
# check CSI was propagated
self.assertTrue(new_node.colindexes[self.sort_field].is_csi)
class Issue156TestCase01(Issue156TestBase):
# sort by field from non nested entry
sort_field = 'frame'
class Issue156TestCase02(Issue156TestBase):
# sort by field from nested entry
sort_field = 'Bar/code'
class Issue119Time32ColTestCase(PyTablesTestCase):
"""TimeCol not properly indexing."""
col_typ = Time32Col
values = [
0.93240451618785880,
0.76322375510776170,
0.16695030056300875,
0.91259117097807850,
0.93977847053454630,
0.51450406513503090,
0.24452129962257563,
0.85475938924825230,
0.32512326762476930,
0.75127635627046820,
]
def setUp(self):
# create hdf5 file
self.filename = tempfile.mktemp(".hdf5")
self.file = open_file(self.filename, mode="w")
class Descr(IsDescription):
when = self.col_typ(pos=1)
value = Float32Col(pos=2)
self.table = self.file.create_table('/', 'test', Descr)
self.t = 1321031471.0 # 11/11/11 11:11:11
data = [(self.t + i, item) for i, item in enumerate(self.values)]
self.table.append(data)
self.file.flush()
def tearDown(self):
self.file.close()
os.remove(self.filename)
def test_timecol_issue(self):
tbl = self.table
t = self.t
wherestr = '(when >= %d) & (when < %d)' % (t, t + 5)
no_index = tbl.read_where(wherestr)
tbl.cols.when.create_index(_verbose=False)
with_index = tbl.read_where(wherestr)
self.assertTrue((no_index == with_index).all())
class Issue119Time64ColTestCase(Issue119Time32ColTestCase):
col_typ = Time64Col
class TestIndexingNans(TempFileMixin, PyTablesTestCase):
def test_issue_282(self):
trMap = {'index': Int64Col(), 'values': FloatCol()}
table = self.h5file.create_table('/', 'table', trMap)
r = table.row
for i in range(5):
r['index'] = i
r['values'] = numpy.nan if i == 0 else i
r.append()
table.flush()
table.cols.values.create_index()
# retrieve
result = table.read_where('(values >= 0)')
self.assertTrue(len(result) == 4)
def test_issue_327(self):
table = self.h5file.create_table('/', 'table', dict(
index=Int64Col(),
values=FloatCol(shape=()),
values2=FloatCol(shape=()),
))
r = table.row
for i in range(5):
r['index'] = i
r['values'] = numpy.nan if i == 2 or i == 3 else i
r['values2'] = i
r.append()
table.flush()
table.cols.values.create_index()
table.cols.values2.create_index()
results2 = table.read_where('(values2 > 0)')
self.assertTrue(len(results2) == 4)
results = table.read_where('(values > 0)')
self.assertTrue(len(results) == 2)
#----------------------------------------------------------------------
def suite():
theSuite = unittest.TestSuite()
niter = 1
# heavy = 1 # Uncomment this only for testing purposes!
for n in range(niter):
theSuite.addTest(unittest.makeSuite(BasicReadTestCase))
theSuite.addTest(unittest.makeSuite(ZlibReadTestCase))
theSuite.addTest(unittest.makeSuite(BloscReadTestCase))
theSuite.addTest(unittest.makeSuite(LZOReadTestCase))
theSuite.addTest(unittest.makeSuite(Bzip2ReadTestCase))
theSuite.addTest(unittest.makeSuite(ShuffleReadTestCase))
theSuite.addTest(unittest.makeSuite(Fletcher32ReadTestCase))
theSuite.addTest(unittest.makeSuite(ShuffleFletcher32ReadTestCase))
theSuite.addTest(unittest.makeSuite(OneHalfTestCase))
theSuite.addTest(unittest.makeSuite(UpperBoundTestCase))
theSuite.addTest(unittest.makeSuite(LowerBoundTestCase))
theSuite.addTest(unittest.makeSuite(AI1TestCase))
theSuite.addTest(unittest.makeSuite(AI2TestCase))
theSuite.addTest(unittest.makeSuite(AI9TestCase))
theSuite.addTest(unittest.makeSuite(DeepTableIndexTestCase))
theSuite.addTest(unittest.makeSuite(IndexPropsChangeTestCase))
theSuite.addTest(unittest.makeSuite(IndexFiltersTestCase))
theSuite.addTest(unittest.makeSuite(OldIndexTestCase))
theSuite.addTest(unittest.makeSuite(CompletelySortedIndexTestCase))
theSuite.addTest(unittest.makeSuite(ManyNodesTestCase))
theSuite.addTest(unittest.makeSuite(ReadSortedIndex0))
theSuite.addTest(unittest.makeSuite(ReadSortedIndex3))
theSuite.addTest(unittest.makeSuite(ReadSortedIndex6))
theSuite.addTest(unittest.makeSuite(ReadSortedIndex9))
theSuite.addTest(unittest.makeSuite(Issue156TestCase01))
theSuite.addTest(unittest.makeSuite(Issue156TestCase02))
theSuite.addTest(unittest.makeSuite(Issue119Time32ColTestCase))
theSuite.addTest(unittest.makeSuite(Issue119Time64ColTestCase))
theSuite.addTest(unittest.makeSuite(TestIndexingNans))
if heavy:
# These are too heavy for normal testing
theSuite.addTest(unittest.makeSuite(AI4bTestCase))
theSuite.addTest(unittest.makeSuite(AI5TestCase))
theSuite.addTest(unittest.makeSuite(AI6TestCase))
theSuite.addTest(unittest.makeSuite(AI7TestCase))
theSuite.addTest(unittest.makeSuite(AI8TestCase))
theSuite.addTest(unittest.makeSuite(AI10TestCase))
theSuite.addTest(unittest.makeSuite(AI11TestCase))
theSuite.addTest(unittest.makeSuite(AI12TestCase))
return theSuite
if __name__ == '__main__':
unittest.main(defaultTest='suite')
|