Skip to content

Commit

Permalink
fixes #658
Browse files Browse the repository at this point in the history
  • Loading branch information
jph00 committed Dec 14, 2024
1 parent 17b02dc commit 566516c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

<!-- do not remove -->

## 1.7.27




## 1.7.26


Expand Down
4 changes: 2 additions & 2 deletions fastcore/foundation.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def renumerate(self): return L(renumerate(self))
def unique(self, sort=False, bidir=False, start=None): return L(uniqueify(self, sort=sort, bidir=bidir, start=start))
def val2idx(self): return val2idx(self)
def cycle(self): return cycle(self)
def groupby(self, key, val=noop): return L(groupby(self, key, val=val))
def groupby(self, key, val=noop): return groupby(self, key, val=val)
def map_dict(self, f=noop, *args, **kwargs): return {k:f(k, *args,**kwargs) for k in self}
def map_first(self, f=noop, g=noop, *args, **kwargs):
return first(self.map(f, *args, **kwargs), g)
Expand Down Expand Up @@ -223,7 +223,7 @@ def setattrs(self, attr, val): [setattr(o,attr,val) for o in self]
cycle="Same as `itertools.cycle`",
enumerate="Same as `enumerate`",
renumerate="Same as `renumerate`",
groupby="Same as `groupby`",
groupby="Same as `fastcore.basics.groupby`",
zip="Create new `L` with `zip(*items)`",
zipwith="Create new `L` with `self` zip with each of `*rest`",
map_zip="Combine `zip` and `starmap`",
Expand Down
61 changes: 51 additions & 10 deletions nbs/02_foundation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,6 @@
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/jhoward/miniforge3/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
" from .autonotebook import tqdm as notebook_tqdm\n"
]
},
{
"data": {
"text/markdown": [
Expand Down Expand Up @@ -620,7 +612,7 @@
" def unique(self, sort=False, bidir=False, start=None): return L(uniqueify(self, sort=sort, bidir=bidir, start=start))\n",
" def val2idx(self): return val2idx(self)\n",
" def cycle(self): return cycle(self)\n",
" def groupby(self, key, val=noop): return L(groupby(self, key, val=val))\n",
" def groupby(self, key, val=noop): return groupby(self, key, val=val)\n",
" def map_dict(self, f=noop, *args, **kwargs): return {k:f(k, *args,**kwargs) for k in self}\n",
" def map_first(self, f=noop, g=noop, *args, **kwargs):\n",
" return first(self.map(f, *args, **kwargs), g)\n",
Expand Down Expand Up @@ -677,7 +669,7 @@
" cycle=\"Same as `itertools.cycle`\",\n",
" enumerate=\"Same as `enumerate`\",\n",
" renumerate=\"Same as `renumerate`\",\n",
" groupby=\"Same as `groupby`\",\n",
" groupby=\"Same as `fastcore.basics.groupby`\",\n",
" zip=\"Create new `L` with `zip(*items)`\",\n",
" zipwith=\"Create new `L` with `self` zip with each of `*rest`\",\n",
" map_zip=\"Combine `zip` and `starmap`\",\n",
Expand Down Expand Up @@ -1219,6 +1211,55 @@
"test_eq(L(1,2,3).val2idx(), {3:2,1:0,2:1})"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"---\n",
"\n",
"[source](https://github.com/AnswerDotAI/fastcore/blob/master/fastcore/foundation.py#L176){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"\n",
"### L.groupby\n",
"\n",
"> L.groupby (key, val=<function noop>)\n",
"\n",
"*Same as `groupby`*"
],
"text/plain": [
"---\n",
"\n",
"[source](https://github.com/AnswerDotAI/fastcore/blob/master/fastcore/foundation.py#L176){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"\n",
"### L.groupby\n",
"\n",
"> L.groupby (key, val=<function noop>)\n",
"\n",
"*Same as `groupby`*"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"show_doc(L.groupby)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"words = L.split('aaa abc bba')\n",
"test_eq(words.groupby(0, (1,2)), {'a':[('a','a'),('b','c')], 'b':[('b','a')]})"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down

0 comments on commit 566516c

Please sign in to comment.