|
1 | 1 | # AUTOGENERATED! DO NOT EDIT! File to edit: nbs/01_basics.ipynb (unless otherwise specified). |
2 | 2 |
|
3 | | -__all__ = ['defaults', 'ifnone', 'maybe_attr', 'basic_repr', 'is_array', 'listify', 'get_class', 'mk_class', |
4 | | - 'wrap_class', 'ignore_exceptions', 'exec_local', 'risinstance', 'Inf', 'in_', 'lt', 'gt', 'le', 'ge', 'eq', |
5 | | - 'ne', 'add', 'sub', 'mul', 'truediv', 'is_', 'is_not', 'in_', 'true', 'stop', 'gen', 'chunked', 'otherwise', |
6 | | - 'custom_dir', 'AttrDict', 'with_cast', 'store_attr', 'attrdict', 'properties', 'camel2snake', 'snake2camel', |
7 | | - 'class2attr', 'hasattrs', 'setattrs', 'try_attrs', 'ShowPrint', 'Int', 'Str', 'Float', 'detuplify', |
8 | | - 'replicate', 'setify', 'merge', 'range_of', 'groupby', 'last_index', 'filter_dict', 'filter_keys', |
9 | | - 'filter_values', 'cycle', 'zip_cycle', 'sorted_ex', 'negate_func', 'argwhere', 'filter_ex', 'range_of', |
10 | | - 'renumerate', 'first', 'nested_attr', 'nested_idx', 'num_methods', 'rnum_methods', 'inum_methods', |
11 | | - 'fastuple', 'arg0', 'arg1', 'arg2', 'arg3', 'arg4', 'bind', 'map_ex', 'compose', 'maps', 'partialler', |
12 | | - 'instantiate', 'using_attr', 'Self', 'Self', 'PrettyString', 'even_mults', 'num_cpus', 'add_props', 'typed'] |
| 3 | +__all__ = ['defaults', 'ifnone', 'maybe_attr', 'basic_repr', 'is_array', 'listify', 'true', 'NullType', 'null', |
| 4 | + 'tonull', 'get_class', 'mk_class', 'wrap_class', 'ignore_exceptions', 'exec_local', 'risinstance', 'Inf', |
| 5 | + 'in_', 'lt', 'gt', 'le', 'ge', 'eq', 'ne', 'add', 'sub', 'mul', 'truediv', 'is_', 'is_not', 'in_', 'true', |
| 6 | + 'stop', 'gen', 'chunked', 'otherwise', 'custom_dir', 'AttrDict', 'with_cast', 'store_attr', 'attrdict', |
| 7 | + 'properties', 'camel2snake', 'snake2camel', 'class2attr', 'hasattrs', 'setattrs', 'try_attrs', 'ShowPrint', |
| 8 | + 'Int', 'Str', 'Float', 'detuplify', 'replicate', 'setify', 'merge', 'range_of', 'groupby', 'last_index', |
| 9 | + 'filter_dict', 'filter_keys', 'filter_values', 'cycle', 'zip_cycle', 'sorted_ex', 'negate_func', 'argwhere', |
| 10 | + 'filter_ex', 'range_of', 'renumerate', 'first', 'nested_attr', 'nested_idx', 'num_methods', 'rnum_methods', |
| 11 | + 'inum_methods', 'fastuple', 'arg0', 'arg1', 'arg2', 'arg3', 'arg4', 'bind', 'map_ex', 'compose', 'maps', |
| 12 | + 'partialler', 'instantiate', 'using_attr', 'Self', 'Self', 'PrettyString', 'even_mults', 'num_cpus', |
| 13 | + 'add_props', 'typed'] |
13 | 14 |
|
14 | 15 | # Cell |
15 | 16 | from .imports import * |
@@ -37,15 +38,40 @@ def _f(self): |
37 | 38 | return _f |
38 | 39 |
|
39 | 40 | # Cell |
40 | | -def is_array(x): return hasattr(x,'__array__') or hasattr(x,'iloc') |
| 41 | +def is_array(x): |
| 42 | + "`True` if `x` supports `__array__` or `iloc`" |
| 43 | + return hasattr(x,'__array__') or hasattr(x,'iloc') |
41 | 44 |
|
| 45 | +# Cell |
42 | 46 | def listify(o): |
| 47 | + "Convert `o` to a `list`" |
43 | 48 | if o is None: return [] |
44 | 49 | if isinstance(o, list): return o |
45 | 50 | if isinstance(o, str) or is_array(o): return [o] |
46 | 51 | if is_iter(o): return list(o) |
47 | 52 | return [o] |
48 | 53 |
|
| 54 | +# Cell |
| 55 | +def true(x): |
| 56 | + "Test whether `x` is truthy; collections with >0 elements are considered `True`" |
| 57 | + try: return bool(len(x)) |
| 58 | + except: return bool(x) |
| 59 | + |
| 60 | +# Cell |
| 61 | +class NullType: |
| 62 | + "An object that is `False` and can be called, chained, and indexed" |
| 63 | + def __getattr__(self,*args):return null |
| 64 | + def __call__(self,*args, **kwargs):return null |
| 65 | + def __getitem__(self, *args):return null |
| 66 | + def __bool__(self): return False |
| 67 | + |
| 68 | +null = NullType() |
| 69 | + |
| 70 | +# Cell |
| 71 | +def tonull(x): |
| 72 | + "Convert `None` to `null`" |
| 73 | + return null if x is None else x |
| 74 | + |
49 | 75 | # Cell |
50 | 76 | def get_class(nm, *fld_names, sup=None, doc=None, funcs=None, **flds): |
51 | 77 | "Dynamically create a class, optionally inheriting from `sup`, containing `fld_names`" |
|
0 commit comments