Skip to content

Commit 55e039e

Browse files
authored
Merge pull request #731 from AnswerDotAI/slice
add slice support for L assignment
2 parents af165a2 + 8573fd1 commit 55e039e

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

fastcore/foundation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def _get(self, i):
139139

140140
def __setitem__(self, idx, o):
141141
"Set `idx` (can be list of indices, or mask, or int) items to `o` (which is broadcast if not iterable)"
142-
if isinstance(idx, int): self.items[idx] = o
142+
if isinstance(idx, int) or isinstance(idx, slice): self.items[idx] = o
143143
else:
144144
idx = idx if isinstance(idx,L) else listify(idx)
145145
if not is_iter(o): o = [o]*len(idx)

nbs/02_foundation.ipynb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -783,11 +783,11 @@
783783
"data": {
784784
"text/plain": [
785785
"[Path('files/test.txt.bz2'),\n",
786-
" Path('images/mnist3.png'),\n",
787786
" Path('images/att_00000.png'),\n",
788787
" Path('images/att_00005.png'),\n",
789-
" Path('images/att_00007.png'),\n",
790788
" Path('images/att_00006.png'),\n",
789+
" Path('images/att_00007.png'),\n",
790+
" Path('images/mnist3.png'),\n",
791791
" Path('images/puppy.jpg')]"
792792
]
793793
},
@@ -937,7 +937,7 @@
937937
"\n",
938938
" def __setitem__(self, idx, o):\n",
939939
" \"Set `idx` (can be list of indices, or mask, or int) items to `o` (which is broadcast if not iterable)\"\n",
940-
" if isinstance(idx, int): self.items[idx] = o\n",
940+
" if isinstance(idx, int) or isinstance(idx, slice): self.items[idx] = o\n",
941941
" else:\n",
942942
" idx = idx if isinstance(idx,L) else listify(idx)\n",
943943
" if not is_iter(o): o = [o]*len(idx)\n",
@@ -1036,7 +1036,7 @@
10361036
{
10371037
"data": {
10381038
"text/plain": [
1039-
"[0, 1, 2, 'j', 4, 'k', 6, 7, 8, 9, 10, 11]"
1039+
"[1, 2, 3, 'j', 4, 'k', 6, 7, 8, 9, 10, 11]"
10401040
]
10411041
},
10421042
"execution_count": null,
@@ -1054,6 +1054,8 @@
10541054
"test_eq(t[3,5], [\"j\",\"k\"])\n",
10551055
"test_eq(t, L(t))\n",
10561056
"test_eq(L(L(1,2),[3,4]), ([1,2],[3,4]))\n",
1057+
"t[0:3] = [1, 2, 3]\n",
1058+
"test_eq(t[0:3], [1, 2, 3])\n",
10571059
"t"
10581060
]
10591061
},
@@ -1094,7 +1096,7 @@
10941096
{
10951097
"data": {
10961098
"text/plain": [
1097-
"[6, 11, 0]"
1099+
"[6, 11, 1]"
10981100
]
10991101
},
11001102
"execution_count": null,
@@ -4150,7 +4152,7 @@
41504152
"text/markdown": [
41514153
"---\n",
41524154
"\n",
4153-
"[source](https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/foundation.py#L636){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
4155+
"[source](https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/foundation.py#L650){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
41544156
"\n",
41554157
"### Config.get\n",
41564158
"\n",
@@ -4245,7 +4247,7 @@
42454247
"text/markdown": [
42464248
"---\n",
42474249
"\n",
4248-
"[source](https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/foundation.py#L650){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
4250+
"[source](https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/foundation.py#L664){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
42494251
"\n",
42504252
"### Config.find\n",
42514253
"\n",

0 commit comments

Comments
 (0)