|
25 | 25 | ], |
26 | 26 | "source": [ |
27 | 27 | "import sys\n", |
28 | | - "sys.path.insert(0, '..')\n", |
29 | | - "import zarr\n", |
| 28 | + "\n", |
| 29 | + "sys.path.insert(0, \"..\")\n", |
30 | 30 | "import numpy as np\n", |
| 31 | + "\n", |
| 32 | + "import zarr\n", |
| 33 | + "\n", |
31 | 34 | "np.random.seed(42)\n", |
32 | 35 | "import cProfile\n", |
| 36 | + "\n", |
33 | 37 | "zarr.__version__" |
34 | 38 | ] |
35 | 39 | }, |
|
57 | 61 | "source": [ |
58 | 62 | "a = np.arange(10)\n", |
59 | 63 | "za = zarr.array(a, chunks=2)\n", |
60 | | - "ix = [False, True, False, True, False, True, False, True, False, True]" |
| 64 | + "ix = [False, True, False, True, False, True, False, True, False, True]" |
61 | 65 | ] |
62 | 66 | }, |
63 | 67 | { |
|
547 | 551 | ], |
548 | 552 | "source": [ |
549 | 553 | "# combine with slice\n", |
550 | | - "za.oindex[[1, 3], :]" |
| 554 | + "za.oindex[[1, 3], :]" |
551 | 555 | ] |
552 | 556 | }, |
553 | 557 | { |
|
973 | 977 | } |
974 | 978 | ], |
975 | 979 | "source": [ |
976 | | - "a = np.array([(b'aaa', 1, 4.2),\n", |
977 | | - " (b'bbb', 2, 8.4),\n", |
978 | | - " (b'ccc', 3, 12.6)], \n", |
979 | | - " dtype=[('foo', 'S3'), ('bar', 'i4'), ('baz', 'f8')])\n", |
| 980 | + "a = np.array(\n", |
| 981 | + " [(b\"aaa\", 1, 4.2), (b\"bbb\", 2, 8.4), (b\"ccc\", 3, 12.6)],\n", |
| 982 | + " dtype=[(\"foo\", \"S3\"), (\"bar\", \"i4\"), (\"baz\", \"f8\")],\n", |
| 983 | + ")\n", |
980 | 984 | "za = zarr.array(a, chunks=2, fill_value=None)\n", |
981 | 985 | "za[:]" |
982 | 986 | ] |
|
999 | 1003 | } |
1000 | 1004 | ], |
1001 | 1005 | "source": [ |
1002 | | - "za['foo']" |
| 1006 | + "za[\"foo\"]" |
1003 | 1007 | ] |
1004 | 1008 | }, |
1005 | 1009 | { |
|
1020 | 1024 | } |
1021 | 1025 | ], |
1022 | 1026 | "source": [ |
1023 | | - "za['foo', 'baz']" |
| 1027 | + "za[\"foo\", \"baz\"]" |
1024 | 1028 | ] |
1025 | 1029 | }, |
1026 | 1030 | { |
|
1041 | 1045 | } |
1042 | 1046 | ], |
1043 | 1047 | "source": [ |
1044 | | - "za[:2, 'foo']" |
| 1048 | + "za[:2, \"foo\"]" |
1045 | 1049 | ] |
1046 | 1050 | }, |
1047 | 1051 | { |
|
1062 | 1066 | } |
1063 | 1067 | ], |
1064 | 1068 | "source": [ |
1065 | | - "za[:2, 'foo', 'baz']" |
| 1069 | + "za[:2, \"foo\", \"baz\"]" |
1066 | 1070 | ] |
1067 | 1071 | }, |
1068 | 1072 | { |
|
1083 | 1087 | } |
1084 | 1088 | ], |
1085 | 1089 | "source": [ |
1086 | | - "za.oindex[[0, 2], 'foo']" |
| 1090 | + "za.oindex[[0, 2], \"foo\"]" |
1087 | 1091 | ] |
1088 | 1092 | }, |
1089 | 1093 | { |
|
1104 | 1108 | } |
1105 | 1109 | ], |
1106 | 1110 | "source": [ |
1107 | | - "za.vindex[[0, 2], 'foo']" |
| 1111 | + "za.vindex[[0, 2], \"foo\"]" |
1108 | 1112 | ] |
1109 | 1113 | }, |
1110 | 1114 | { |
|
1125 | 1129 | } |
1126 | 1130 | ], |
1127 | 1131 | "source": [ |
1128 | | - "za['bar'] = 42\n", |
| 1132 | + "za[\"bar\"] = 42\n", |
1129 | 1133 | "za[:]" |
1130 | 1134 | ] |
1131 | 1135 | }, |
|
1147 | 1151 | } |
1148 | 1152 | ], |
1149 | 1153 | "source": [ |
1150 | | - "za[:2, 'bar'] = 84\n", |
| 1154 | + "za[:2, \"bar\"] = 84\n", |
1151 | 1155 | "za[:]" |
1152 | 1156 | ] |
1153 | 1157 | }, |
|
1176 | 1180 | } |
1177 | 1181 | ], |
1178 | 1182 | "source": [ |
1179 | | - "a['foo', 'baz']" |
| 1183 | + "a[\"foo\", \"baz\"]" |
1180 | 1184 | ] |
1181 | 1185 | }, |
1182 | 1186 | { |
|
1197 | 1201 | } |
1198 | 1202 | ], |
1199 | 1203 | "source": [ |
1200 | | - "a[['foo', 'baz']]" |
| 1204 | + "a[[\"foo\", \"baz\"]]" |
1201 | 1205 | ] |
1202 | 1206 | }, |
1203 | 1207 | { |
|
1218 | 1222 | } |
1219 | 1223 | ], |
1220 | 1224 | "source": [ |
1221 | | - "za['foo', 'baz']" |
| 1225 | + "za[\"foo\", \"baz\"]" |
1222 | 1226 | ] |
1223 | 1227 | }, |
1224 | 1228 | { |
|
1243 | 1247 | } |
1244 | 1248 | ], |
1245 | 1249 | "source": [ |
1246 | | - "za[['foo', 'baz']]" |
| 1250 | + "za[[\"foo\", \"baz\"]]" |
1247 | 1251 | ] |
1248 | 1252 | }, |
1249 | 1253 | { |
|
1437 | 1441 | "metadata": {}, |
1438 | 1442 | "outputs": [], |
1439 | 1443 | "source": [ |
1440 | | - "import tempfile\n", |
1441 | | - "import cProfile\n", |
1442 | 1444 | "import pstats\n", |
| 1445 | + "import tempfile\n", |
| 1446 | + "\n", |
1443 | 1447 | "\n", |
1444 | | - "def profile(statement, sort='time', restrictions=(7,)):\n", |
| 1448 | + "def profile(statement, sort=\"time\", restrictions=(7,)):\n", |
1445 | 1449 | " with tempfile.NamedTemporaryFile() as f:\n", |
1446 | 1450 | " cProfile.run(statement, filename=f.name)\n", |
1447 | | - " pstats.Stats(f.name).sort_stats(sort).print_stats(*restrictions)\n" |
| 1451 | + " pstats.Stats(f.name).sort_stats(sort).print_stats(*restrictions)" |
1448 | 1452 | ] |
1449 | 1453 | }, |
1450 | 1454 | { |
|
1477 | 1481 | } |
1478 | 1482 | ], |
1479 | 1483 | "source": [ |
1480 | | - "profile('zc.oindex[ix_dense_bool]')" |
| 1484 | + "profile(\"zc.oindex[ix_dense_bool]\")" |
1481 | 1485 | ] |
1482 | 1486 | }, |
1483 | 1487 | { |
|
1517 | 1521 | } |
1518 | 1522 | ], |
1519 | 1523 | "source": [ |
1520 | | - "profile('zc.vindex[ix_dense_bool]')" |
| 1524 | + "profile(\"zc.vindex[ix_dense_bool]\")" |
1521 | 1525 | ] |
1522 | 1526 | }, |
1523 | 1527 | { |
|
1551 | 1555 | } |
1552 | 1556 | ], |
1553 | 1557 | "source": [ |
1554 | | - "ix_dense_int = np.random.choice(c.shape[0], size=c.shape[0]//10, replace=True)\n", |
| 1558 | + "ix_dense_int = np.random.choice(c.shape[0], size=c.shape[0] // 10, replace=True)\n", |
1555 | 1559 | "ix_dense_int_sorted = ix_dense_int.copy()\n", |
1556 | 1560 | "ix_dense_int_sorted.sort()\n", |
1557 | 1561 | "len(ix_dense_int)" |
|
1689 | 1693 | } |
1690 | 1694 | ], |
1691 | 1695 | "source": [ |
1692 | | - "profile('zc.oindex[ix_dense_int_sorted]')" |
| 1696 | + "profile(\"zc.oindex[ix_dense_int_sorted]\")" |
1693 | 1697 | ] |
1694 | 1698 | }, |
1695 | 1699 | { |
|
1722 | 1726 | } |
1723 | 1727 | ], |
1724 | 1728 | "source": [ |
1725 | | - "profile('zc.vindex[ix_dense_int_sorted]')" |
| 1729 | + "profile(\"zc.vindex[ix_dense_int_sorted]\")" |
1726 | 1730 | ] |
1727 | 1731 | }, |
1728 | 1732 | { |
|
1755 | 1759 | } |
1756 | 1760 | ], |
1757 | 1761 | "source": [ |
1758 | | - "profile('zc.oindex[ix_dense_int]')" |
| 1762 | + "profile(\"zc.oindex[ix_dense_int]\")" |
1759 | 1763 | ] |
1760 | 1764 | }, |
1761 | 1765 | { |
|
1788 | 1792 | } |
1789 | 1793 | ], |
1790 | 1794 | "source": [ |
1791 | | - "profile('zc.vindex[ix_dense_int]')" |
| 1795 | + "profile(\"zc.vindex[ix_dense_int]\")" |
1792 | 1796 | ] |
1793 | 1797 | }, |
1794 | 1798 | { |
|
1908 | 1912 | } |
1909 | 1913 | ], |
1910 | 1914 | "source": [ |
1911 | | - "profile('zc.oindex[ix_sparse_bool]')" |
| 1915 | + "profile(\"zc.oindex[ix_sparse_bool]\")" |
1912 | 1916 | ] |
1913 | 1917 | }, |
1914 | 1918 | { |
|
1941 | 1945 | } |
1942 | 1946 | ], |
1943 | 1947 | "source": [ |
1944 | | - "profile('zc.vindex[ix_sparse_bool]')" |
| 1948 | + "profile(\"zc.vindex[ix_sparse_bool]\")" |
1945 | 1949 | ] |
1946 | 1950 | }, |
1947 | 1951 | { |
|
1968 | 1972 | } |
1969 | 1973 | ], |
1970 | 1974 | "source": [ |
1971 | | - "ix_sparse_int = np.random.choice(c.shape[0], size=c.shape[0]//10000, replace=True)\n", |
| 1975 | + "ix_sparse_int = np.random.choice(c.shape[0], size=c.shape[0] // 10000, replace=True)\n", |
1972 | 1976 | "ix_sparse_int_sorted = ix_sparse_int.copy()\n", |
1973 | 1977 | "ix_sparse_int_sorted.sort()\n", |
1974 | 1978 | "len(ix_sparse_int)" |
|
2106 | 2110 | } |
2107 | 2111 | ], |
2108 | 2112 | "source": [ |
2109 | | - "profile('zc.oindex[ix_sparse_int]')" |
| 2113 | + "profile(\"zc.oindex[ix_sparse_int]\")" |
2110 | 2114 | ] |
2111 | 2115 | }, |
2112 | 2116 | { |
|
2139 | 2143 | } |
2140 | 2144 | ], |
2141 | 2145 | "source": [ |
2142 | | - "profile('zc.vindex[ix_sparse_int]')" |
| 2146 | + "profile(\"zc.vindex[ix_sparse_int]\")" |
2143 | 2147 | ] |
2144 | 2148 | }, |
2145 | 2149 | { |
|
2330 | 2334 | } |
2331 | 2335 | ], |
2332 | 2336 | "source": [ |
2333 | | - "profile('zc[::2]')" |
| 2337 | + "profile(\"zc[::2]\")" |
2334 | 2338 | ] |
2335 | 2339 | }, |
2336 | 2340 | { |
|
2480 | 2484 | "metadata": {}, |
2481 | 2485 | "outputs": [], |
2482 | 2486 | "source": [ |
2483 | | - "ix0 = np.random.choice(d.shape[0], size=int(d.shape[0] * .5), replace=True)\n", |
2484 | | - "ix1 = np.random.choice(d.shape[1], size=int(d.shape[1] * .5), replace=True)" |
| 2487 | + "ix0 = np.random.choice(d.shape[0], size=int(d.shape[0] * 0.5), replace=True)\n", |
| 2488 | + "ix1 = np.random.choice(d.shape[1], size=int(d.shape[1] * 0.5), replace=True)" |
2485 | 2489 | ] |
2486 | 2490 | }, |
2487 | 2491 | { |
|
2542 | 2546 | } |
2543 | 2547 | ], |
2544 | 2548 | "source": [ |
2545 | | - "n = int(d.size * .1)\n", |
| 2549 | + "n = int(d.size * 0.1)\n", |
2546 | 2550 | "ix0 = np.random.choice(d.shape[0], size=n, replace=True)\n", |
2547 | 2551 | "ix1 = np.random.choice(d.shape[1], size=n, replace=True)\n", |
2548 | 2552 | "n" |
|
2612 | 2616 | } |
2613 | 2617 | ], |
2614 | 2618 | "source": [ |
2615 | | - "profile('zd.vindex[ix0, ix1]')" |
| 2619 | + "profile(\"zd.vindex[ix0, ix1]\")" |
2616 | 2620 | ] |
2617 | 2621 | }, |
2618 | 2622 | { |
|
2637 | 2641 | "metadata": {}, |
2638 | 2642 | "outputs": [], |
2639 | 2643 | "source": [ |
2640 | | - "import h5py\n", |
2641 | | - "import tempfile" |
| 2644 | + "import h5py" |
2642 | 2645 | ] |
2643 | 2646 | }, |
2644 | 2647 | { |
|
2647 | 2650 | "metadata": {}, |
2648 | 2651 | "outputs": [], |
2649 | 2652 | "source": [ |
2650 | | - "h5f = h5py.File(tempfile.mktemp(), driver='core', backing_store=False)" |
| 2653 | + "h5f = h5py.File(tempfile.mktemp(), driver=\"core\", backing_store=False)" |
2651 | 2654 | ] |
2652 | 2655 | }, |
2653 | 2656 | { |
|
2667 | 2670 | } |
2668 | 2671 | ], |
2669 | 2672 | "source": [ |
2670 | | - "hc = h5f.create_dataset('c', data=c, compression='gzip', compression_opts=1, chunks=zc.chunks, shuffle=True)\n", |
| 2673 | + "hc = h5f.create_dataset(\n", |
| 2674 | + " \"c\", data=c, compression=\"gzip\", compression_opts=1, chunks=zc.chunks, shuffle=True\n", |
| 2675 | + ")\n", |
2671 | 2676 | "hc" |
2672 | 2677 | ] |
2673 | 2678 | }, |
|
2733 | 2738 | "metadata": {}, |
2734 | 2739 | "outputs": [], |
2735 | 2740 | "source": [ |
2736 | | - "# # this is pathological, takes minutes \n", |
| 2741 | + "# # this is pathological, takes minutes\n", |
2737 | 2742 | "# %time hc[ix_dense_bool]" |
2738 | 2743 | ] |
2739 | 2744 | }, |
|
0 commit comments