|
1188 | 1188 | { |
1189 | 1189 | "data": { |
1190 | 1190 | "text/plain": [ |
1191 | | - "Path('/home/lgvaz/git/fastcore/fastcore')" |
| 1191 | + "Path('/Users/jhoward/Documents/GitHub/fastcore/fastcore')" |
1192 | 1192 | ] |
1193 | 1193 | }, |
1194 | 1194 | "execution_count": null, |
|
1255 | 1255 | { |
1256 | 1256 | "data": { |
1257 | 1257 | "text/plain": [ |
1258 | | - "Path('05_transform.ipynb')" |
| 1258 | + "Path('000_tour.ipynb')" |
1259 | 1259 | ] |
1260 | 1260 | }, |
1261 | 1261 | "execution_count": null, |
|
1289 | 1289 | { |
1290 | 1290 | "data": { |
1291 | 1291 | "text/plain": [ |
1292 | | - "(Path('../fastcore/all.py'), Path('05_transform.ipynb'))" |
| 1292 | + "(Path('../fastcore/shutil.py'), Path('000_tour.ipynb'))" |
1293 | 1293 | ] |
1294 | 1294 | }, |
1295 | 1295 | "execution_count": null, |
|
1434 | 1434 | "text/markdown": [ |
1435 | 1435 | "---\n", |
1436 | 1436 | "\n", |
1437 | | - "### ReindexCollection\n", |
| 1437 | + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/xtras.py#L380){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
1438 | 1438 | "\n", |
1439 | | - "> ReindexCollection (coll, idxs=None, cache=None, tfm=<functionnoop>)\n", |
| 1439 | + "#### ReindexCollection\n", |
1440 | 1440 | "\n", |
1441 | | - "Reindexes collection `coll` with indices `idxs` and optional LRU cache of size `cache`" |
| 1441 | + "> ReindexCollection (coll, idxs=None, cache=None, tfm=<function noop>)\n", |
| 1442 | + "\n", |
| 1443 | + "*Reindexes collection `coll` with indices `idxs` and optional LRU cache of size `cache`*" |
1442 | 1444 | ], |
1443 | 1445 | "text/plain": [ |
1444 | | - "<nbdev.showdoc.BasicMarkdownRenderer>" |
| 1446 | + "---\n", |
| 1447 | + "\n", |
| 1448 | + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/xtras.py#L380){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 1449 | + "\n", |
| 1450 | + "#### ReindexCollection\n", |
| 1451 | + "\n", |
| 1452 | + "> ReindexCollection (coll, idxs=None, cache=None, tfm=<function noop>)\n", |
| 1453 | + "\n", |
| 1454 | + "*Reindexes collection `coll` with indices `idxs` and optional LRU cache of size `cache`*" |
1445 | 1455 | ] |
1446 | 1456 | }, |
1447 | 1457 | "execution_count": null, |
|
1507 | 1517 | "text/markdown": [ |
1508 | 1518 | "---\n", |
1509 | 1519 | "\n", |
1510 | | - "#### ReindexCollection.reindex\n", |
| 1520 | + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/xtras.py#L391){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 1521 | + "\n", |
| 1522 | + "###### ReindexCollection.reindex\n", |
1511 | 1523 | "\n", |
1512 | 1524 | "> ReindexCollection.reindex (idxs)\n", |
1513 | 1525 | "\n", |
1514 | | - "Replace `self.idxs` with idxs" |
| 1526 | + "*Replace `self.idxs` with idxs*" |
1515 | 1527 | ], |
1516 | 1528 | "text/plain": [ |
1517 | | - "<nbdev.showdoc.BasicMarkdownRenderer>" |
| 1529 | + "---\n", |
| 1530 | + "\n", |
| 1531 | + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/xtras.py#L391){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 1532 | + "\n", |
| 1533 | + "###### ReindexCollection.reindex\n", |
| 1534 | + "\n", |
| 1535 | + "> ReindexCollection.reindex (idxs)\n", |
| 1536 | + "\n", |
| 1537 | + "*Replace `self.idxs` with idxs*" |
1518 | 1538 | ] |
1519 | 1539 | }, |
1520 | 1540 | "execution_count": null, |
|
1597 | 1617 | "text/markdown": [ |
1598 | 1618 | "---\n", |
1599 | 1619 | "\n", |
1600 | | - "#### ReindexCollection.cache_clear\n", |
| 1620 | + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/xtras.py#L395){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 1621 | + "\n", |
| 1622 | + "##### ReindexCollection.cache_clear\n", |
1601 | 1623 | "\n", |
1602 | 1624 | "> ReindexCollection.cache_clear ()\n", |
1603 | 1625 | "\n", |
1604 | | - "Clear LRU cache" |
| 1626 | + "*Clear LRU cache*" |
1605 | 1627 | ], |
1606 | 1628 | "text/plain": [ |
1607 | | - "<nbdev.showdoc.BasicMarkdownRenderer>" |
| 1629 | + "---\n", |
| 1630 | + "\n", |
| 1631 | + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/xtras.py#L395){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 1632 | + "\n", |
| 1633 | + "##### ReindexCollection.cache_clear\n", |
| 1634 | + "\n", |
| 1635 | + "> ReindexCollection.cache_clear ()\n", |
| 1636 | + "\n", |
| 1637 | + "*Clear LRU cache*" |
1608 | 1638 | ] |
1609 | 1639 | }, |
1610 | 1640 | "execution_count": null, |
|
1652 | 1682 | "text/markdown": [ |
1653 | 1683 | "---\n", |
1654 | 1684 | "\n", |
1655 | | - "#### ReindexCollection.shuffle\n", |
| 1685 | + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/xtras.py#L392){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 1686 | + "\n", |
| 1687 | + "##### ReindexCollection.shuffle\n", |
1656 | 1688 | "\n", |
1657 | 1689 | "> ReindexCollection.shuffle ()\n", |
1658 | 1690 | "\n", |
1659 | | - "Randomly shuffle indices" |
| 1691 | + "*Randomly shuffle indices*" |
1660 | 1692 | ], |
1661 | 1693 | "text/plain": [ |
1662 | | - "<nbdev.showdoc.BasicMarkdownRenderer>" |
| 1694 | + "---\n", |
| 1695 | + "\n", |
| 1696 | + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/xtras.py#L392){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 1697 | + "\n", |
| 1698 | + "##### ReindexCollection.shuffle\n", |
| 1699 | + "\n", |
| 1700 | + "> ReindexCollection.shuffle ()\n", |
| 1701 | + "\n", |
| 1702 | + "*Randomly shuffle indices*" |
1663 | 1703 | ] |
1664 | 1704 | }, |
1665 | 1705 | "execution_count": null, |
|
1686 | 1726 | { |
1687 | 1727 | "data": { |
1688 | 1728 | "text/plain": [ |
1689 | | - "['d', 'f', 'g', 'a', 'h', 'e', 'b', 'c']" |
| 1729 | + "['h', 'g', 'a', 'd', 'b', 'e', 'f', 'c']" |
1690 | 1730 | ] |
1691 | 1731 | }, |
1692 | 1732 | "execution_count": null, |
|
2102 | 2142 | "text/markdown": [ |
2103 | 2143 | "---\n", |
2104 | 2144 | "\n", |
2105 | | - "### EventTimer\n", |
| 2145 | + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/xtras.py#L502){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 2146 | + "\n", |
| 2147 | + "#### EventTimer\n", |
2106 | 2148 | "\n", |
2107 | 2149 | "> EventTimer (store=5, span=60)\n", |
2108 | 2150 | "\n", |
2109 | | - "An event timer with history of `store` items of time `span`" |
| 2151 | + "*An event timer with history of `store` items of time `span`*" |
2110 | 2152 | ], |
2111 | 2153 | "text/plain": [ |
2112 | | - "<nbdev.showdoc.BasicMarkdownRenderer>" |
| 2154 | + "---\n", |
| 2155 | + "\n", |
| 2156 | + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/xtras.py#L502){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 2157 | + "\n", |
| 2158 | + "#### EventTimer\n", |
| 2159 | + "\n", |
| 2160 | + "> EventTimer (store=5, span=60)\n", |
| 2161 | + "\n", |
| 2162 | + "*An event timer with history of `store` items of time `span`*" |
2113 | 2163 | ] |
2114 | 2164 | }, |
2115 | 2165 | "execution_count": null, |
|
2137 | 2187 | "name": "stdout", |
2138 | 2188 | "output_type": "stream", |
2139 | 2189 | "text": [ |
2140 | | - "Num Events: 3, Freq/sec: 242.1\n", |
2141 | | - "Most recent: ▇▁▂▃▁ 358.8 267.5 296.5 315.5 266.4\n" |
| 2190 | + "Num Events: 3, Freq/sec: 256.2\n", |
| 2191 | + "Most recent: ▁▃▇▅▂ 223.9 260.6 307.1 279.5 252.0\n" |
2142 | 2192 | ] |
2143 | 2193 | } |
2144 | 2194 | ], |
|
2217 | 2267 | "text/markdown": [ |
2218 | 2268 | "---\n", |
2219 | 2269 | "\n", |
2220 | | - "### PartialFormatter\n", |
| 2270 | + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/xtras.py#L534){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 2271 | + "\n", |
| 2272 | + "#### PartialFormatter\n", |
2221 | 2273 | "\n", |
2222 | 2274 | "> PartialFormatter ()\n", |
2223 | 2275 | "\n", |
2224 | | - "A `string.Formatter` that doesn't error on missing fields, and tracks missing fields and unused args" |
| 2276 | + "*A `string.Formatter` that doesn't error on missing fields, and tracks missing fields and unused args*" |
2225 | 2277 | ], |
2226 | 2278 | "text/plain": [ |
2227 | | - "<nbdev.showdoc.BasicMarkdownRenderer>" |
| 2279 | + "---\n", |
| 2280 | + "\n", |
| 2281 | + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/xtras.py#L534){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 2282 | + "\n", |
| 2283 | + "#### PartialFormatter\n", |
| 2284 | + "\n", |
| 2285 | + "> PartialFormatter ()\n", |
| 2286 | + "\n", |
| 2287 | + "*A `string.Formatter` that doesn't error on missing fields, and tracks missing fields and unused args*" |
2228 | 2288 | ] |
2229 | 2289 | }, |
2230 | 2290 | "execution_count": null, |
|
2290 | 2350 | "name": "stdout", |
2291 | 2351 | "output_type": "stream", |
2292 | 2352 | "text": [ |
2293 | | - "2000-01-01 12:00:00 UTC is 2000-01-01 17:30:00+05:30 local time\n" |
| 2353 | + "2000-01-01 12:00:00 UTC is 2000-01-01 22:00:00+10:00 local time\n" |
2294 | 2354 | ] |
2295 | 2355 | } |
2296 | 2356 | ], |
|
2320 | 2380 | "name": "stdout", |
2321 | 2381 | "output_type": "stream", |
2322 | 2382 | "text": [ |
2323 | | - "2000-01-01 12:00:00 local is 2000-01-01 06:30:00+00:00 UTC time\n" |
| 2383 | + "2000-01-01 12:00:00 local is 2000-01-01 02:00:00+00:00 UTC time\n" |
2324 | 2384 | ] |
2325 | 2385 | } |
2326 | 2386 | ], |
|
2423 | 2483 | "text/markdown": [ |
2424 | 2484 | "---\n", |
2425 | 2485 | "\n", |
2426 | | - "### ContextManagers\n", |
| 2486 | + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/xtras.py#L591){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 2487 | + "\n", |
| 2488 | + "#### ContextManagers\n", |
2427 | 2489 | "\n", |
2428 | 2490 | "> ContextManagers (mgrs)\n", |
2429 | 2491 | "\n", |
2430 | | - "Wrapper for `contextlib.ExitStack` which enters a collection of context managers" |
| 2492 | + "*Wrapper for `contextlib.ExitStack` which enters a collection of context managers*" |
2431 | 2493 | ], |
2432 | 2494 | "text/plain": [ |
2433 | | - "<nbdev.showdoc.BasicMarkdownRenderer>" |
| 2495 | + "---\n", |
| 2496 | + "\n", |
| 2497 | + "[source](https://github.com/fastai/fastcore/blob/master/fastcore/xtras.py#L591){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 2498 | + "\n", |
| 2499 | + "#### ContextManagers\n", |
| 2500 | + "\n", |
| 2501 | + "> ContextManagers (mgrs)\n", |
| 2502 | + "\n", |
| 2503 | + "*Wrapper for `contextlib.ExitStack` which enters a collection of context managers*" |
2434 | 2504 | ] |
2435 | 2505 | }, |
2436 | 2506 | "execution_count": null, |
|
2643 | 2713 | "outputs": [], |
2644 | 2714 | "source": [ |
2645 | 2715 | "#| export\n", |
2646 | | - "def make_nullable(cls):\n", |
| 2716 | + "def make_nullable(clas):\n", |
2647 | 2717 | " from dataclasses import dataclass, fields, MISSING\n", |
2648 | | - " if hasattr(cls, '_nullable'): return\n", |
2649 | | - " cls._nullable = True\n", |
| 2718 | + " if hasattr(clas, '_nullable'): return\n", |
| 2719 | + " clas._nullable = True\n", |
2650 | 2720 | "\n", |
2651 | | - " @patch\n", |
2652 | | - " def __init__(self:cls, *args, **kwargs):\n", |
2653 | | - " flds = fields(cls)\n", |
| 2721 | + " original_init = clas.__init__\n", |
| 2722 | + " def __init__(self, *args, **kwargs):\n", |
| 2723 | + " flds = fields(clas)\n", |
2654 | 2724 | " dargs = {k.name:v for k,v in zip(flds, args)}\n", |
2655 | 2725 | " for f in flds:\n", |
2656 | 2726 | " nm = f.name\n", |
2657 | 2727 | " if nm not in dargs and nm not in kwargs and f.default is None and f.default_factory is MISSING:\n", |
2658 | 2728 | " kwargs[nm] = None\n", |
2659 | | - " self._orig___init__(*args, **kwargs)\n", |
| 2729 | + " original_init(self, *args, **kwargs)\n", |
| 2730 | + " \n", |
| 2731 | + " clas.__init__ = __init__\n", |
| 2732 | + "\n", |
| 2733 | + " for f in fields(clas):\n", |
| 2734 | + " if f.default is MISSING and f.default_factory is MISSING: f.default = None\n", |
2660 | 2735 | " \n", |
2661 | | - " for f in fields(cls):\n", |
2662 | | - " if f.default is MISSING and f.default_factory is MISSING: f.default = None" |
| 2736 | + " return clas" |
2663 | 2737 | ] |
2664 | 2738 | }, |
2665 | 2739 | { |
|
0 commit comments