Skip to content

Commit f5f469e

Browse files
committed
fixes #273
1 parent 937f1f0 commit f5f469e

File tree

8 files changed

+73
-16
lines changed

8 files changed

+73
-16
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ release: pypi
2727
nbdev_bump_version
2828

2929
conda_release:
30-
fastrelease_conda_package --upload_user fastai --build_args '-c pytorch -c fastai'
30+
fastrelease_conda_package --mambabuild --upload_user fastai --build_args '-c pytorch -c fastai'
3131

3232
pypi: dist
3333
twine upload --repository pypi dist/*

fastcore/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.3.16"
1+
__version__ = "1.3.17"

fastcore/_nbdev.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"Str": "01_basics.ipynb",
7070
"Float": "01_basics.ipynb",
7171
"concat": "01_basics.ipynb",
72+
"strcat": "01_basics.ipynb",
7273
"detuplify": "01_basics.ipynb",
7374
"replicate": "01_basics.ipynb",
7475
"setify": "01_basics.ipynb",
@@ -101,6 +102,7 @@
101102
"arg3": "01_basics.ipynb",
102103
"arg4": "01_basics.ipynb",
103104
"bind": "01_basics.ipynb",
105+
"mapt": "01_basics.ipynb",
104106
"map_ex": "01_basics.ipynb",
105107
"compose": "01_basics.ipynb",
106108
"maps": "01_basics.ipynb",

fastcore/basics.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
'true', 'stop', 'gen', 'chunked', 'otherwise', 'custom_dir', 'AttrDict', 'type_hints', 'annotations',
77
'anno_ret', 'argnames', 'with_cast', 'store_attr', 'attrdict', 'properties', 'camel2words', 'camel2snake',
88
'snake2camel', 'class2attr', 'getattrs', 'hasattrs', 'setattrs', 'try_attrs', 'GetAttrBase', 'GetAttr',
9-
'delegate_attr', 'ShowPrint', 'Int', 'Str', 'Float', 'concat', 'detuplify', 'replicate', 'setify', 'merge',
10-
'range_of', 'groupby', 'last_index', 'filter_dict', 'filter_keys', 'filter_values', 'cycle', 'zip_cycle',
11-
'sorted_ex', 'not_', 'argwhere', 'filter_ex', 'range_of', 'renumerate', 'first', 'nested_attr', 'nested_idx',
12-
'val2idx', 'uniqueify', 'num_methods', 'rnum_methods', 'inum_methods', 'fastuple', 'arg0', 'arg1', 'arg2',
13-
'arg3', 'arg4', 'bind', 'map_ex', 'compose', 'maps', 'partialler', 'instantiate', 'using_attr', 'Self',
14-
'Self', 'copy_func', 'patch_to', 'patch', 'patch_property', 'ImportEnum', 'StrEnum', 'str_enum', 'Stateful',
15-
'PrettyString', 'even_mults', 'num_cpus', 'add_props', 'typed']
9+
'delegate_attr', 'ShowPrint', 'Int', 'Str', 'Float', 'concat', 'strcat', 'detuplify', 'replicate', 'setify',
10+
'merge', 'range_of', 'groupby', 'last_index', 'filter_dict', 'filter_keys', 'filter_values', 'cycle',
11+
'zip_cycle', 'sorted_ex', 'not_', 'argwhere', 'filter_ex', 'range_of', 'renumerate', 'first', 'nested_attr',
12+
'nested_idx', 'val2idx', 'uniqueify', 'num_methods', 'rnum_methods', 'inum_methods', 'fastuple', 'arg0',
13+
'arg1', 'arg2', 'arg3', 'arg4', 'bind', 'mapt', 'map_ex', 'compose', 'maps', 'partialler', 'instantiate',
14+
'using_attr', 'Self', 'Self', 'copy_func', 'patch_to', 'patch', 'patch_property', 'ImportEnum', 'StrEnum',
15+
'str_enum', 'Stateful', 'PrettyString', 'even_mults', 'num_cpus', 'add_props', 'typed']
1616

1717
# Cell
1818
from .imports import *
@@ -424,6 +424,11 @@ def concat(colls)->list:
424424
"Concatenate all collections in `colls`"
425425
return list(itertools.chain.from_iterable(colls))
426426

427+
# Cell
428+
def strcat(its, sep:str='')->str:
429+
"Concatenate stringified items `its`"
430+
return sep.join(map(str,its))
431+
427432
# Cell
428433
def detuplify(x):
429434
"If `x` is a tuple with one thing, extract it"
@@ -645,6 +650,11 @@ def __call__(self, *args, **kwargs):
645650
fargs = [args[x.i] if isinstance(x, _Arg) else x for x in self.pargs] + args[self.maxi+1:]
646651
return self.func(*fargs, **kwargs)
647652

653+
# Cell
654+
def mapt(func, *iterables):
655+
"Tuplified `map`"
656+
return tuple(map(func, *iterables))
657+
648658
# Cell
649659
def map_ex(iterable, f, *args, gen=False, **kwargs):
650660
"Like `map`, but use `bind`, and supports `str` and indexing"

fastcore/xtras.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,10 @@ def run(cmd, *rest, ignore_ex=False, as_bytes=False):
168168
elif isinstance(cmd,str): cmd = shlex.split(cmd)
169169
res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
170170
stdout = res.stdout
171-
if not as_bytes: stdout = stdout.decode()
171+
if res.stderr: stdout += b' ;; ' + res.stderr
172+
if not as_bytes: stdout = stdout.decode().strip()
172173
if ignore_ex: return (res.returncode, stdout)
173-
if res.returncode: raise IOError("{} ;; {}".format(res.stdout, res.stderr))
174+
if res.returncode: raise IOError(stdout)
174175
return stdout
175176

176177
# Cell

nbs/01_basics.ipynb

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2732,6 +2732,28 @@
27322732
"concat([(o for o in range(2)),[2,3,4]])"
27332733
]
27342734
},
2735+
{
2736+
"cell_type": "code",
2737+
"execution_count": null,
2738+
"metadata": {},
2739+
"outputs": [],
2740+
"source": [
2741+
"#export\n",
2742+
"def strcat(its, sep:str='')->str:\n",
2743+
" \"Concatenate stringified items `its`\"\n",
2744+
" return sep.join(map(str,its))"
2745+
]
2746+
},
2747+
{
2748+
"cell_type": "code",
2749+
"execution_count": null,
2750+
"metadata": {},
2751+
"outputs": [],
2752+
"source": [
2753+
"test_eq(strcat(['a',2]), 'a2')\n",
2754+
"test_eq(strcat(['a',2], ';'), 'a;2')"
2755+
]
2756+
},
27352757
{
27362758
"cell_type": "code",
27372759
"execution_count": null,
@@ -3781,6 +3803,28 @@
37813803
"test_eq(bind(myfn, 17,19,14,e=arg0)(3), (17,19,14,1,3))"
37823804
]
37833805
},
3806+
{
3807+
"cell_type": "code",
3808+
"execution_count": null,
3809+
"metadata": {},
3810+
"outputs": [],
3811+
"source": [
3812+
"#export\n",
3813+
"def mapt(func, *iterables):\n",
3814+
" \"Tuplified `map`\"\n",
3815+
" return tuple(map(func, *iterables))"
3816+
]
3817+
},
3818+
{
3819+
"cell_type": "code",
3820+
"execution_count": null,
3821+
"metadata": {},
3822+
"outputs": [],
3823+
"source": [
3824+
"t = [0,1,2,3]\n",
3825+
"test_eq(mapt(operator.neg, t), (0,-1,-2,-3))"
3826+
]
3827+
},
37843828
{
37853829
"cell_type": "code",
37863830
"execution_count": null,
@@ -3804,7 +3848,6 @@
38043848
"metadata": {},
38053849
"outputs": [],
38063850
"source": [
3807-
"t = [0,1,2,3]\n",
38083851
"test_eq(map_ex(t,operator.neg), [0,-1,-2,-3])"
38093852
]
38103853
},

nbs/03_xtras.ipynb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@
618618
{
619619
"data": {
620620
"text/plain": [
621-
"['a', 'b', 'd', 'c', 'h', 'e', 'f', 'g']"
621+
"['g', 'a', 'b', 'd', 'f', 'e', 'c', 'h']"
622622
]
623623
},
624624
"execution_count": null,
@@ -1050,9 +1050,10 @@
10501050
" elif isinstance(cmd,str): cmd = shlex.split(cmd)\n",
10511051
" res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n",
10521052
" stdout = res.stdout\n",
1053-
" if not as_bytes: stdout = stdout.decode()\n",
1053+
" if res.stderr: stdout += b' ;; ' + res.stderr\n",
1054+
" if not as_bytes: stdout = stdout.decode().strip()\n",
10541055
" if ignore_ex: return (res.returncode, stdout)\n",
1055-
" if res.returncode: raise IOError(\"{} ;; {}\".format(res.stdout, res.stderr))\n",
1056+
" if res.returncode: raise IOError(stdout)\n",
10561057
" return stdout"
10571058
]
10581059
},

settings.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ author = Jeremy Howard and Sylvain Gugger
77
author_email = [email protected]
88
copyright = fast.ai
99
branch = master
10-
version = 1.3.16
10+
version = 1.3.17
1111
min_python = 3.6
1212
audience = Developers
1313
language = English

0 commit comments

Comments
 (0)