Skip to content

Commit 00288d0

Browse files
committed
Update slicing/updating example in the docs
Closes #80
1 parent 9dcb156 commit 00288d0

File tree

1 file changed

+105
-39
lines changed

1 file changed

+105
-39
lines changed

docs/source/notebooks/nuances.ipynb

Lines changed: 105 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,15 @@
3434
"cell_type": "code",
3535
"execution_count": 1,
3636
"metadata": {},
37-
"outputs": [],
37+
"outputs": [
38+
{
39+
"name": "stdout",
40+
"output_type": "stream",
41+
"text": [
42+
"\n"
43+
]
44+
}
45+
],
3846
"source": [
3947
"%pip install mudata"
4048
]
@@ -53,6 +61,26 @@
5361
"cell_type": "code",
5462
"execution_count": 3,
5563
"metadata": {},
64+
"outputs": [
65+
{
66+
"data": {
67+
"text/plain": [
68+
"<mudata._core.config.set_options at 0x148b0fa90>"
69+
]
70+
},
71+
"execution_count": 3,
72+
"metadata": {},
73+
"output_type": "execute_result"
74+
}
75+
],
76+
"source": [
77+
"mudata.set_options(pull_on_update=False)"
78+
]
79+
},
80+
{
81+
"cell_type": "code",
82+
"execution_count": 4,
83+
"metadata": {},
5684
"outputs": [],
5785
"source": [
5886
"import numpy as np\n",
@@ -68,7 +96,7 @@
6896
},
6997
{
7098
"cell_type": "code",
71-
"execution_count": 4,
99+
"execution_count": 5,
72100
"metadata": {},
73101
"outputs": [],
74102
"source": [
@@ -122,7 +150,7 @@
122150
},
123151
{
124152
"cell_type": "code",
125-
"execution_count": 5,
153+
"execution_count": 6,
126154
"metadata": {},
127155
"outputs": [
128156
{
@@ -145,9 +173,7 @@
145173
"name": "stderr",
146174
"output_type": "stream",
147175
"text": [
148-
"/usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/mudata/src/mudata/_core/mudata.py:869: UserWarning: Cannot join columns with the same name because var_names are intersecting.\n",
149-
" warnings.warn(\n",
150-
"/usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/mudata/src/mudata/_core/mudata.py:1478: UserWarning: Modality names will be prepended to var_names since there are identical var_names in different modalities.\n",
176+
"/usr/local/opt/python@3.11/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/mudata/_core/mudata.py:1558: UserWarning: Modality names will be prepended to var_names since there are identical var_names in different modalities.\n",
151177
" warnings.warn(\n"
152178
]
153179
}
@@ -179,7 +205,7 @@
179205
},
180206
{
181207
"cell_type": "code",
182-
"execution_count": 6,
208+
"execution_count": 7,
183209
"metadata": {},
184210
"outputs": [
185211
{
@@ -190,7 +216,7 @@
190216
" dtype='object')"
191217
]
192218
},
193-
"execution_count": 6,
219+
"execution_count": 7,
194220
"metadata": {},
195221
"output_type": "execute_result"
196222
}
@@ -237,49 +263,53 @@
237263
"source": [
238264
"### Filtering data\n",
239265
"\n",
240-
"In rare cases some observations (or variables) can be dropped from all the contained modalities:"
266+
"In some cases some observations (or variables) can be dropped from all the contained modalities:"
241267
]
242268
},
243269
{
244270
"cell_type": "code",
245-
"execution_count": 7,
271+
"execution_count": 8,
246272
"metadata": {},
247273
"outputs": [],
248274
"source": [
249-
"smaller_mdata = MuData({\n",
250-
" \"mod1\": mod1[:900].copy(),\n",
251-
" \"mod2\": mod2[:900].copy(),\n",
252-
"})"
275+
"mdata.obs[\"dummy_index\"] = range(len(mdata))\n",
276+
"\n",
277+
"smaller_mdata = mdata.copy()\n",
278+
"\n",
279+
"smaller_mdata.mod['mod1'] = mod1[:900]\n",
280+
"smaller_mdata.mod['mod2'] = mod2[:900]"
253281
]
254282
},
255283
{
256284
"cell_type": "markdown",
257285
"metadata": {},
258286
"source": [
259-
"While `smaller_mdata` includes `mod1` and `mod2` as its modalities, it currently does not know about this change:"
287+
"While `smaller_mdata` now includes modalities with fewer observations, it currently does not know about this change:"
260288
]
261289
},
262290
{
263291
"cell_type": "code",
264-
"execution_count": 8,
292+
"execution_count": 9,
265293
"metadata": {},
266294
"outputs": [
267295
{
268296
"data": {
269297
"text/html": [
270-
"<pre>MuData object with n_obs × n_vars = 900 × 300\n",
298+
"<pre>MuData object with n_obs × n_vars = 1000 × 300\n",
299+
" obs:\t&#x27;dummy_index&#x27;\n",
271300
" 2 modalities\n",
272301
" mod1:\t900 x 100\n",
273302
" mod2:\t900 x 200</pre>"
274303
],
275304
"text/plain": [
276-
"MuData object with n_obs × n_vars = 900 × 300\n",
305+
"MuData object with n_obs × n_vars = 1000 × 300\n",
306+
" obs:\t'dummy_index'\n",
277307
" 2 modalities\n",
278308
" mod1:\t900 x 100\n",
279309
" mod2:\t900 x 200"
280310
]
281311
},
282-
"execution_count": 8,
312+
"execution_count": 9,
283313
"metadata": {},
284314
"output_type": "execute_result"
285315
}
@@ -288,6 +318,23 @@
288318
"smaller_mdata"
289319
]
290320
},
321+
{
322+
"cell_type": "code",
323+
"execution_count": 10,
324+
"metadata": {},
325+
"outputs": [
326+
{
327+
"name": "stdout",
328+
"output_type": "stream",
329+
"text": [
330+
"999\n"
331+
]
332+
}
333+
],
334+
"source": [
335+
"print(max(smaller_mdata.obs['dummy_index']))"
336+
]
337+
},
291338
{
292339
"cell_type": "markdown",
293340
"metadata": {},
@@ -297,25 +344,27 @@
297344
},
298345
{
299346
"cell_type": "code",
300-
"execution_count": 9,
347+
"execution_count": 11,
301348
"metadata": {},
302349
"outputs": [
303350
{
304351
"data": {
305352
"text/html": [
306353
"<pre>MuData object with n_obs × n_vars = 900 × 300\n",
354+
" obs:\t&#x27;dummy_index&#x27;\n",
307355
" 2 modalities\n",
308356
" mod1:\t900 x 100\n",
309357
" mod2:\t900 x 200</pre>"
310358
],
311359
"text/plain": [
312360
"MuData object with n_obs × n_vars = 900 × 300\n",
361+
" obs:\t'dummy_index'\n",
313362
" 2 modalities\n",
314363
" mod1:\t900 x 100\n",
315364
" mod2:\t900 x 200"
316365
]
317366
},
318-
"execution_count": 9,
367+
"execution_count": 11,
319368
"metadata": {},
320369
"output_type": "execute_result"
321370
}
@@ -325,6 +374,23 @@
325374
"smaller_mdata"
326375
]
327376
},
377+
{
378+
"cell_type": "code",
379+
"execution_count": 12,
380+
"metadata": {},
381+
"outputs": [
382+
{
383+
"name": "stdout",
384+
"output_type": "stream",
385+
"text": [
386+
"899\n"
387+
]
388+
}
389+
],
390+
"source": [
391+
"print(max(smaller_mdata.obs['dummy_index']))"
392+
]
393+
},
328394
{
329395
"cell_type": "markdown",
330396
"metadata": {},
@@ -350,7 +416,7 @@
350416
},
351417
{
352418
"cell_type": "code",
353-
"execution_count": 10,
419+
"execution_count": 13,
354420
"metadata": {},
355421
"outputs": [],
356422
"source": [
@@ -366,16 +432,16 @@
366432
},
367433
{
368434
"cell_type": "code",
369-
"execution_count": 11,
435+
"execution_count": 14,
370436
"metadata": {},
371437
"outputs": [
372438
{
373439
"data": {
374440
"text/plain": [
375-
"Index([], dtype='object')"
441+
"Index(['dummy_index'], dtype='object')"
376442
]
377443
},
378-
"execution_count": 11,
444+
"execution_count": 14,
379445
"metadata": {},
380446
"output_type": "execute_result"
381447
}
@@ -393,16 +459,16 @@
393459
},
394460
{
395461
"cell_type": "code",
396-
"execution_count": 12,
462+
"execution_count": 15,
397463
"metadata": {},
398464
"outputs": [
399465
{
400466
"data": {
401467
"text/plain": [
402-
"<mudata._core.config.set_options at 0x3597fec00>"
468+
"<mudata._core.config.set_options at 0x1491e95d0>"
403469
]
404470
},
405-
"execution_count": 12,
471+
"execution_count": 15,
406472
"metadata": {},
407473
"output_type": "execute_result"
408474
}
@@ -414,14 +480,14 @@
414480
},
415481
{
416482
"cell_type": "code",
417-
"execution_count": 13,
483+
"execution_count": 16,
418484
"metadata": {},
419485
"outputs": [
420486
{
421487
"name": "stdout",
422488
"output_type": "stream",
423489
"text": [
424-
"Index([], dtype='object')\n"
490+
"Index(['dummy_index'], dtype='object')\n"
425491
]
426492
}
427493
],
@@ -439,14 +505,14 @@
439505
},
440506
{
441507
"cell_type": "code",
442-
"execution_count": 14,
508+
"execution_count": 17,
443509
"metadata": {},
444510
"outputs": [
445511
{
446512
"name": "stdout",
447513
"output_type": "stream",
448514
"text": [
449-
"Index(['mod1:mod1_profiled'], dtype='object')\n"
515+
"Index(['dummy_index', 'mod1:mod1_profiled'], dtype='object')\n"
450516
]
451517
}
452518
],
@@ -457,7 +523,7 @@
457523
},
458524
{
459525
"cell_type": "code",
460-
"execution_count": 15,
526+
"execution_count": 18,
461527
"metadata": {},
462528
"outputs": [],
463529
"source": [
@@ -475,14 +541,14 @@
475541
},
476542
{
477543
"cell_type": "code",
478-
"execution_count": 16,
544+
"execution_count": 19,
479545
"metadata": {},
480546
"outputs": [
481547
{
482548
"name": "stdout",
483549
"output_type": "stream",
484550
"text": [
485-
"Index(['mod1_profiled'], dtype='object')\n"
551+
"Index(['dummy_index', 'mod1_profiled'], dtype='object')\n"
486552
]
487553
}
488554
],
@@ -514,7 +580,7 @@
514580
},
515581
{
516582
"cell_type": "code",
517-
"execution_count": 17,
583+
"execution_count": 20,
518584
"metadata": {},
519585
"outputs": [],
520586
"source": [
@@ -527,7 +593,7 @@
527593
},
528594
{
529595
"cell_type": "code",
530-
"execution_count": 18,
596+
"execution_count": 21,
531597
"metadata": {},
532598
"outputs": [
533599
{
@@ -588,7 +654,7 @@
588654
"mod2:88 B"
589655
]
590656
},
591-
"execution_count": 18,
657+
"execution_count": 21,
592658
"metadata": {},
593659
"output_type": "execute_result"
594660
}
@@ -629,7 +695,7 @@
629695
"name": "python",
630696
"nbconvert_exporter": "python",
631697
"pygments_lexer": "ipython3",
632-
"version": "3.12.3"
698+
"version": "3.11.9"
633699
},
634700
"toc": {
635701
"base_numbering": 1,

0 commit comments

Comments
 (0)