zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
U
¬ý°d+ã@sddlmZddlmZddlmZddlmZmZm    Z    m
Z
m Z m Z m Z mZmZmZmZmZddlZddlZddlmZddlmZmZmZddlmZdd    l m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+dd
l,m-Z.dd l/m0Z0m1Z1m2Z2dd l3m4Z4m5Z5m6Z6dd l7m8Z8ddl9m:Z:ddl;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFddlGmHZHddlImJZJmKZKmLZLddlMmNZNmOZOddlPmQmRZddlSmTZTddlUmVZVddlWmXZXddlYmQmZZ[ddl\mQm]m^Z_ddl\m`Z`maZambZbmcZcddldmeZeddlfmgZgddlhmiZimjZjmkZkddllmmZmerFddlnmoZompZpmqZqere_jsƒZses tdddœ¡Gdd „d ejuejvƒZwGd!d"„d"ejuejxƒZyd#d#d$œd%d&„ZzGd'd„de`ƒZ{d(d)d)d*œd+d,„Z|dCd)d.d/œd0d1„Z}d2d3œd4d5„Z~d6d6d7œd8d9„ZdDd;d<d=œd>d?„Z€d2d@œdAdB„ZdS)Eé)Ú annotations)Úwraps©Ú    getsizeof) Ú TYPE_CHECKINGÚAnyÚCallableÚ
CollectionÚ    GeneratorÚHashableÚIterableÚListÚLiteralÚSequenceÚTupleÚcastN)Ú
get_option)ÚalgosÚindexÚlib)Ú
duplicated) ÚAnyAllÚ AnyArrayLikeÚAxisÚDropKeepÚDtypeObjÚFÚ IgnoreRaiseÚ
IndexLabelÚScalarÚShapeÚnpt)Úfunction)ÚInvalidIndexErrorÚPerformanceWarningÚUnsortedIndexError)ÚAppenderÚcache_readonlyÚdoc)Úfind_stack_level)Úcoerce_indexer_dtype) Ú ensure_int64Úensure_platform_intÚis_categorical_dtypeÚis_extension_array_dtypeÚ is_hashableÚ
is_integerÚ is_iteratorÚ is_list_likeÚis_object_dtypeÚ    is_scalarÚ pandas_dtype)ÚExtensionDtype)Ú ABCDataFrameÚABCDatetimeIndexÚABCTimedeltaIndex)Úarray_equivalentÚisna)Úvalidate_putmask)Ú Categorical)Úfactorize_from_iterables)ÚIndexÚ_index_shared_docsÚ ensure_indexÚget_unanimous_names)Ú
FrozenList)Úmake_invalid_op)Úget_group_indexÚindexer_from_factorizedÚlexsort_indexer)Ú pprint_thing)ÚCategoricalIndexÚ    DataFrameÚSeriesÚ
MultiIndexzMultiIndex or list of tuples)ÚklassZ target_klassc@seZdZdZejZdd„ZdS)ÚMultiIndexUIntEngineza
    This class manages a MultiIndex by mapping label combinations to positive
    integers.
    cCs0||jK}|jdkr tj |¡Stjj|ddS)a
        Transform combination(s) of uint64 in one uint64 (each), in a strictly
        monotonic way (i.e. respecting the lexicographic order of integer
        combinations): see BaseMultiIndexCodesEngine documentation.
 
        Parameters
        ----------
        codes : 1- or 2-dimensional array of dtype uint64
            Combinations of integers (one per row)
 
        Returns
        -------
        scalar or 1-dimensional array, of dtype uint64
            Integer(s) representing one combination (each).
        é©Úaxis)ÚoffsetsÚndimÚnpÚ
bitwise_orÚreduce©ÚselfÚcodes©rZúPd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/core/indexes/multi.pyÚ_codes_to_ints}s
 
 z#MultiIndexUIntEngine._codes_to_intsN)Ú__name__Ú
__module__Ú __qualname__Ú__doc__ÚlibindexÚ UInt64EngineÚ_baser\rZrZrZr[rNusrNc@seZdZdZejZdd„ZdS)ÚMultiIndexPyIntEnginezÂ
    This class manages those (extreme) cases in which the number of possible
    label combinations overflows the 64 bits integers, and uses an ObjectEngine
    containing Python integers.
    cCs6| d¡|j>}|jdkr&tj |¡Stjj|ddS)a
        Transform combination(s) of uint64 in one Python integer (each), in a
        strictly monotonic way (i.e. respecting the lexicographic order of
        integer combinations): see BaseMultiIndexCodesEngine documentation.
 
        Parameters
        ----------
        codes : 1- or 2-dimensional array of dtype uint64
            Combinations of integers (one per row)
 
        Returns
        -------
        int, or 1-dimensional array of dtype object
            Integer(s) representing one combination (each).
        ÚobjectrOrP)ÚastyperRrSrTrUrVrWrZrZr[r\¥s
 z$MultiIndexPyIntEngine._codes_to_intsN)r]r^r_r`raÚ ObjectEnginercr\rZrZrZr[rdœsrdr)ÚmethÚreturncstˆƒ‡fdd„ƒ}tt|ƒS)z†
    A decorator to allow either `name` or `names` keyword but not both.
 
    This makes it easier to share code with base class.
    cs>d|krd|krtdƒ‚d|kr.| d¡|d<ˆ|f|ž|ŽS)NÚnameÚnamesz*Can only provide one of `names` and `name`)Ú    TypeErrorÚpop)Z self_or_clsÚargsÚkwargs©rhrZr[Únew_methÌs
znames_compat.<locals>.new_meth)rrr)rhrqrZrpr[Ú names_compatÅsrrc    s2    eZdZUdZejeƒBZdZgZde    d<e
ƒZ e
ƒZ dgZ de    d<dZd d dd œd d„Zdddœdd„Zd[dddœdd„Zedejfdddœdd„ƒZeed\dddddœdd„ƒƒZedejfd dddd!œd"d#„ƒZed]d$dd%œd&d'„ƒZed(d)œd*d+„ƒZed(d)œd,d-„ƒZed.d/„ƒZed0d)œd1d2„ƒZd3d)œd4d5„Zed3d)œd6d7„ƒZ ed8d)œd9d:„ƒZ!dd    d
d    d;œd d d d<d=œd>d?„Z"dd
d@œd ddAœdBdC„Z#ed3d)œdDdE„ƒZ$edFd)œdGdH„ƒZ%edIdJ„ƒZ&dd    d
d    d;œd d d d<d=œdKdL„Z'dd
d@œd dMœdNdO„Z(edPdQ„ƒZ)edRd)œdSdT„ƒZ*e+ej,ƒejfd(ddUœdVdW„ƒZ,dd)œdXdY„Z-d^d dZœd[d\„Z.d_d(d)œd]d^„Z/d`d_d`„Z0e+ej1ƒdad dbœdcdd„ƒZ1eded)œdfdg„ƒZ2d d)œdhdi„Z3e+ej4ƒdad d3djœdkdl„ƒZ4ed3d)œdmdn„ƒZ5dbd d3djœdodp„Z6dqdr„Z7dsdtœdudvdwœdxdy„Z8dcd{d|d}d d3d dd~œdd€„Z9d8d)œdd‚„Z:dd
dƒœd d„œd…d†„Z;ee;e:d‡dˆZ<edud)œd‰dŠ„ƒZ=d3d)œd‹dŒ„Z>ed d)œddŽ„ƒZ?ed d)œdd„ƒZ@ed‘d)œd’d“„ƒZAe+ejBƒddd•d–d—œd˜d™„ƒZBeBZCdedšd›„ZDe+ejEƒdfdddžœdŸd „ƒZEdgd3d d¡d¢œd£d¤„ZFd¥d¦„ZGe+ejHƒdhd§d¨„ƒZHd
ejd    fd d d$d©œdªd«„ZId¡d)œd¬d­„ZJd d)œd®d¯„ZKed3d)œd°d±„ƒZLdid dd²œd³d´„ZMdd)œdµd¶„ZNd·d¸„ZOd¹dº„ZPdd»dd¼œd½d¾„ZQeReSd¿eTƒdjddÁd ddœdÃdĄƒZUdÅdƄZVdÇd)œdÈdɄZWeReSdÊeTƒdkd3dd˜dÌd̈́ƒZXdldÏdÐddќdÒdӄZYdmdÐddԜdÕdքZZdndd)œdÙdڄZ[dd)œdÛd܄Z\dÝd)œdÞd߄Z]dodàdád dâdãœdädå„Z^d dæœdçdè„Z_d¡d d¡déœdêdë„Z`d<d)œdìdí„Zaed d)œdîdZbdudðdñœ‡fdòdó„ Zcdud<dñœ‡fdôdõ„ ZddÇd)œdöd÷„Zedødùd3dúœdûdü„Zfdpdýd)œ‡fdþdÿ„ Zgdqddùdœdd„Zhd¡dd3dœdd„Zid    d
„Zjdrdàd d œd d „Zkdsddœdd„Zldtd3ddœdd„Zmdd„ZnddÇdǐdœdd„Zodudd)œdd„Zpdd dœd d!„Zqdd dœd"d#„Zrdd)œ‡fd$d%„ Zsd&d d'œd(d)„Ztdd)œd*d+„Zud,d-„Zvdd)œd.d/„Zwddd0œd1d2„Zxd3d4„Zye+ejzƒdvd d5œd6d7„ƒZzd8d9„Z{ddd:œd;d<„Z|d3dd=œd>d?„Z}dd)œd@dA„Z~e+ejƒdwd–d)œdBdC„ƒZej€Ze‚dDƒZƒe‚dEƒZ„e‚dFƒZ…e‚dGƒZ†e‚dHƒZ‡e‚dIƒZˆe‚dJƒZ‰e‚dKƒZŠe‚dLƒZ‹e‚dMƒZŒe‚dNƒZe‚dOƒZŽe‚dPƒZe‚dQƒZe‚dRƒZ‘e‚dSƒZ’e‚dTƒZ“e‚dUƒZ”e‚dVƒZ•e‚dWƒZ–e‚dXƒZ—e‚dYƒZ˜‡Z™S(xrLaö
    A multi-level, or hierarchical, index object for pandas objects.
 
    Parameters
    ----------
    levels : sequence of arrays
        The unique labels for each level.
    codes : sequence of arrays
        Integers for each level designating which label at each location.
    sortorder : optional int
        Level of sortedness (must be lexicographically sorted by that
        level).
    names : optional sequence of objects
        Names for each of the index levels. (name is accepted for compat).
    copy : bool, default False
        Copy the meta-data.
    verify_integrity : bool, default True
        Check that the levels/codes are consistent and valid.
 
    Attributes
    ----------
    names
    levels
    codes
    nlevels
    levshape
    dtypes
 
    Methods
    -------
    from_arrays
    from_tuples
    from_product
    from_frame
    set_levels
    set_codes
    to_frame
    to_flat_index
    sortlevel
    droplevel
    swaplevel
    reorder_levels
    remove_unused_levels
    get_level_values
    get_indexer
    get_loc
    get_locs
    get_loc_level
    drop
 
    See Also
    --------
    MultiIndex.from_arrays  : Convert list of arrays to MultiIndex.
    MultiIndex.from_product : Create a MultiIndex from the cartesian product
                              of iterables.
    MultiIndex.from_tuples  : Convert list of tuples to a MultiIndex.
    MultiIndex.from_frame   : Make a MultiIndex from a DataFrame.
    Index : The base pandas Index type.
 
    Notes
    -----
    See the `user guide
    <https://pandas.pydata.org/pandas-docs/stable/user_guide/advanced.html>`__
    for more.
 
    Examples
    --------
    A new ``MultiIndex`` is typically constructed using one of the helper
    methods :meth:`MultiIndex.from_arrays`, :meth:`MultiIndex.from_product`
    and :meth:`MultiIndex.from_tuples`. For example (using ``.from_arrays``):
 
    >>> arrays = [[1, 1, 2, 2], ['red', 'blue', 'red', 'blue']]
    >>> pd.MultiIndex.from_arrays(arrays, names=('number', 'color'))
    MultiIndex([(1,  'red'),
                (1, 'blue'),
                (2,  'red'),
                (2, 'blue')],
               names=['number', 'color'])
 
    See further examples for how to construct a MultiIndex in the doc strings
    of the mentioned helper methods.
    Z
multiindexzlist[Hashable | None]Ú_namesrkz
int | NoneÚ    sortorderNFTÚbool)ÚcopyÚverify_integrityric     Csà|dk    r |}|dks|dkr$tdƒ‚t|ƒt|ƒkr<tdƒ‚t|ƒdkrPtdƒ‚t |¡}    i|    _|    j||dd|    j||dddgt|ƒ|    _|dk    r¢|         |¡|dk    r¶t
|ƒ|    _ n||    _ |rÎ|      ¡}
|
|    _ |     ¡d|    _|    S)NzMust pass both levels and codesz,Length of levels and codes must be the same.rz)Must pass non-zero number of levels/codesF)rvÚvalidate)rlÚlenÚ
ValueErrorreÚ__new__Ú_cacheÚ _set_levelsÚ
_set_codesrsÚ
_set_namesÚintrtÚ_verify_integrityÚ_codesÚ_reset_identityZ _references) ÚclsÚlevelsrYrtrkÚdtypervrjrwÚresultÚ    new_codesrZrZr[r{:s0  
 
 zMultiIndex.__new__Úlist)ÚlevelÚcodecCs(t|ƒ}t |¡r$t ||d|¡}|S)a”
        Reassign code values as -1 if their corresponding levels are NaN.
 
        Parameters
        ----------
        code : list
            Code to reassign.
        level : list
            Level to check for missing values (NaN, NaT, None).
 
        Returns
        -------
        new code where code value = -1 if it corresponds
        to a level with missing values (NaN, NaT, None).
        éÿÿÿÿ)r;rTÚanyÚwhere)rXrŠr‹Z    null_maskrZrZr[Ú_validate_codesis
zMultiIndex._validate_codesz list | None)rYr…c    sf|pˆj}|pˆj}t|ƒt|ƒkr,tdƒ‚t|dƒ}tt||ƒƒD]¸\}\}}t|ƒ|krvtddd„|Dƒ›ƒ‚t|ƒr²| ¡t|ƒkr²td|›d| ¡›dt|ƒ›d    ƒ‚t|ƒrà| ¡d
kràtd|›d | ¡›d ƒ‚|jsFtd t    |ƒ›d|›ƒ‚qFˆj
dk    rBˆj
t ˆjˆj ƒkrBtdˆj
›dt ˆjˆj ƒ›ƒ‚‡fdd„t||ƒDƒ}t |ƒ}|S)a7
        Parameters
        ----------
        codes : optional list
            Codes to check for validity. Defaults to current codes.
        levels : optional list
            Levels to check for validity. Defaults to current levels.
 
        Raises
        ------
        ValueError
            If length of levels and codes don't match, if the codes for any
            level would exceed level bounds, or there are any duplicate levels.
 
        Returns
        -------
        new codes where code value = -1 if it corresponds to a
        NaN level.
        zTLength of levels and codes must match. NOTE: this index is in an inconsistent state.rzUnequal code lengths: cSsg|] }t|ƒ‘qSrZ©ry)Ú.0Zcode_rZrZr[Ú
<listcomp>£sz0MultiIndex._verify_integrity.<locals>.<listcomp>z    On level z , code max (z) >= length of level (z/). NOTE: this index is in an inconsistent staterŒz, code value (z) < -1zLevel values must be unique: z
 on level NzQValue for sortorder must be inferior or equal to actual lexsort_depth: sortorder z with lexsort_depth csg|]\}}ˆ ||¡‘qSrZ)r)r‘rŠr‹©rXrZr[r’¹s)rYr…ryrzÚ    enumerateÚzipÚmaxÚminÚ    is_uniquer‰rtÚ_lexsort_depthÚnlevelsrC)rXrYr…Z codes_lengthÚirŠÚ level_codesrˆrZr“r[rs@
 
ÿ  ÿÿÿ ÿ
ÿzMultiIndex._verify_integrityz-Sequence[Hashable] | Hashable | lib.NoDefault)rkric    Cs¬d}t|ƒst|ƒ‚t|ƒr$t|ƒ}|D]}t|ƒs(t|ƒ‚q(tdt|ƒƒD](}t||ƒt||dƒkrLtdƒ‚qLt|ƒ\}}|tj    kršdd„|Dƒ}|||||ddS)až
        Convert arrays to MultiIndex.
 
        Parameters
        ----------
        arrays : list / sequence of array-likes
            Each array-like gives one level's value for each data point.
            len(arrays) is the number of levels.
        sortorder : int or None
            Level of sortedness (must be lexicographically sorted by that
            level).
        names : list / sequence of str, optional
            Names for the levels in the index.
 
        Returns
        -------
        MultiIndex
 
        See Also
        --------
        MultiIndex.from_tuples : Convert list of tuples to MultiIndex.
        MultiIndex.from_product : Make a MultiIndex from cartesian product
                                  of iterables.
        MultiIndex.from_frame : Make a MultiIndex from a DataFrame.
 
        Examples
        --------
        >>> arrays = [[1, 1, 2, 2], ['red', 'blue', 'red', 'blue']]
        >>> pd.MultiIndex.from_arrays(arrays, names=('number', 'color'))
        MultiIndex([(1,  'red'),
                    (1, 'blue'),
                    (2,  'red'),
                    (2, 'blue')],
                   names=['number', 'color'])
        z/Input must be a list / sequence of array-likes.rOzall arrays must be same lengthcSsg|]}t|ddƒ‘qS©rjN©Úgetattr)r‘ÚarrrZrZr[r’üsz*MultiIndex.from_arrays.<locals>.<listcomp>F©r…rYrtrkrw)
r2rlr1r‰Úrangeryrzr>rÚ
no_default)    r„ÚarraysrtrkÚ    error_msgÚarrayr›rYr…rZrZr[Ú from_arrays¿s**
 
 
ûzMultiIndex.from_arrayszIterable[tuple[Hashable, ...]]zSequence[Hashable] | Hashable)ÚtuplesrtrkricCs8t|ƒstdƒ‚t|ƒr t|ƒ}ttttdf|ƒ}t|ƒrŒt    dd„|DƒƒrŒt
  t|ƒ¡g}t t j|t
 d¡dƒg}|||||ddSt|ƒd    kr¸|d
kr¨td ƒ‚ggt|ƒ}npt|t
jt fƒrðt|t ƒrÞt
 |j¡}tt |¡jƒ}n8t|tƒrtt |¡jƒ}nt|Ž}tttt|ƒ}|j|||d S) a}
        Convert list of tuples to MultiIndex.
 
        Parameters
        ----------
        tuples : list / sequence of tuple-likes
            Each tuple is the index of one row/column.
        sortorder : int or None
            Level of sortedness (must be lexicographically sorted by that
            level).
        names : list / sequence of str, optional
            Names for the levels in the index.
 
        Returns
        -------
        MultiIndex
 
        See Also
        --------
        MultiIndex.from_arrays : Convert list of arrays to MultiIndex.
        MultiIndex.from_product : Make a MultiIndex from cartesian product
                                  of iterables.
        MultiIndex.from_frame : Make a MultiIndex from a DataFrame.
 
        Examples
        --------
        >>> tuples = [(1, 'red'), (1, 'blue'),
        ...           (2, 'red'), (2, 'blue')]
        >>> pd.MultiIndex.from_tuples(tuples, names=('number', 'color'))
        MultiIndex([(1,  'red'),
                    (1, 'blue'),
                    (2,  'red'),
                    (2, 'blue')],
                   names=['number', 'color'])
        z/Input must be a list / sequence of tuple-likes..css|]}t|tƒo| VqdS©N)Ú
isinstanceÚtuple)r‘ÚerZrZr[Ú    <genexpr>8sz)MultiIndex.from_tuples.<locals>.<genexpr>re©r†Fr¡rNz-Cannot infer number of levels from empty list©rtrk)r2rlr1r‰rr    rr ryÚallrTÚzerosr?ÚcomÚasarray_tuplesafer†rªÚndarrayÚasarrayÚ_valuesrZtuples_to_object_arrayÚTZto_object_array_tuplesr•r rr§)r„r¨rtrkrYr…r¤ZarrsrZrZr[Ú from_tupless8+û     
  zMultiIndex.from_tupleszSequence[Iterable[Hashable]])Ú    iterablesrtrkricCshddlm}t|ƒstdƒ‚t|ƒr,t|ƒ}t|ƒ\}}|tjkrPdd„|Dƒ}||ƒ}|||||dS)at
        Make a MultiIndex from the cartesian product of multiple iterables.
 
        Parameters
        ----------
        iterables : list / sequence of iterables
            Each iterable has unique labels for each level of the index.
        sortorder : int or None
            Level of sortedness (must be lexicographically sorted by that
            level).
        names : list / sequence of str, optional
            Names for the levels in the index.
            If not explicitly provided, names will be inferred from the
            elements of iterables if an element has a name attribute.
 
        Returns
        -------
        MultiIndex
 
        See Also
        --------
        MultiIndex.from_arrays : Convert list of arrays to MultiIndex.
        MultiIndex.from_tuples : Convert list of tuples to MultiIndex.
        MultiIndex.from_frame : Make a MultiIndex from a DataFrame.
 
        Examples
        --------
        >>> numbers = [0, 1, 2]
        >>> colors = ['green', 'purple']
        >>> pd.MultiIndex.from_product([numbers, colors],
        ...                            names=['number', 'color'])
        MultiIndex([(0,  'green'),
                    (0, 'purple'),
                    (1,  'green'),
                    (1, 'purple'),
                    (2,  'green'),
                    (2, 'purple')],
                   names=['number', 'color'])
        r)Úcartesian_productz-Input must be a list / sequence of iterables.cSsg|]}t|ddƒ‘qSrrž)r‘ÚitrZrZr[r’Žsz+MultiIndex.from_product.<locals>.<listcomp>r¯)    Zpandas.core.reshape.utilrºr2rlr1r‰r>rr£)r„r¹rtrkrºrYr…rZrZr[Ú from_productWs.  
zMultiIndex.from_productrJ)ÚdfricCsBt|tƒstdƒ‚t| ¡Ž\}}|dkr.|n|}|j|||dS)aK
        Make a MultiIndex from a DataFrame.
 
        Parameters
        ----------
        df : DataFrame
            DataFrame to be converted to MultiIndex.
        sortorder : int, optional
            Level of sortedness (must be lexicographically sorted by that
            level).
        names : list-like, optional
            If no names are provided, use the column names, or tuple of column
            names if the columns is a MultiIndex. If a sequence, overwrite
            names with the given sequence.
 
        Returns
        -------
        MultiIndex
            The MultiIndex representation of the given DataFrame.
 
        See Also
        --------
        MultiIndex.from_arrays : Convert list of arrays to MultiIndex.
        MultiIndex.from_tuples : Convert list of tuples to MultiIndex.
        MultiIndex.from_product : Make a MultiIndex from cartesian product
                                  of iterables.
 
        Examples
        --------
        >>> df = pd.DataFrame([['HI', 'Temp'], ['HI', 'Precip'],
        ...                    ['NJ', 'Temp'], ['NJ', 'Precip']],
        ...                   columns=['a', 'b'])
        >>> df
              a       b
        0    HI    Temp
        1    HI  Precip
        2    NJ    Temp
        3    NJ  Precip
 
        >>> pd.MultiIndex.from_frame(df)
        MultiIndex([('HI',   'Temp'),
                    ('HI', 'Precip'),
                    ('NJ',   'Temp'),
                    ('NJ', 'Precip')],
                   names=['a', 'b'])
 
        Using explicit names, instead of the column names
 
        >>> pd.MultiIndex.from_frame(df, names=['state', 'observation'])
        MultiIndex([('HI',   'Temp'),
                    ('HI', 'Precip'),
                    ('NJ',   'Temp'),
                    ('NJ', 'Precip')],
                   names=['state', 'observation'])
        zInput must be a DataFrameNr¯)rªr7rlr•Úitemsr§)r„r½rtrkZ column_namesÚcolumnsrZrZr[Ú
from_frame”s
9
zMultiIndex.from_frameú
np.ndarray©ricCs¦g}t|jƒD]ˆ}|j|}|j|}|}t|jƒrHtd|ƒ}|j ¡}t    |jt
ƒsbt    |t t fƒrl|  t¡}tj|dd}tj|||jd}| |¡qt |¡}|S)NrIF©rv©Ú
fill_value)r¢ršr…rYr-r†rÚ_dataZ_internal_get_valuesrªr6r8r9rfrerTr¦rÚtake_ndÚ    _na_valueÚappendrZfast_zip)rXÚvaluesr›rrYÚvalsr rZrZr[r¶Ös$
 
 
 
 
ÿ
 
zMultiIndex._valuescCs|jSr©©r¶r“rZrZr[rÊðszMultiIndex.valuescCs tdƒ‚dS)z¦
        Raises a ValueError for `MultiIndex` because there's no single
        array backing a MultiIndex.
 
        Raises
        ------
        ValueError
        zcMultiIndex has no single backing array. Use 'MultiIndex.to_numpy()' to get a NumPy array of tuples.N)rzr“rZrZr[r¦ôs
ÿzMultiIndex.arrayrKcCs>ddlm}t dd„|jDƒ¡}|dd„|jDƒt|ƒdS)zN
        Return the dtypes as a Series for the underlying MultiIndex.
        r)rKcSsg|]
}|j‘qSrZ©rj©r‘rŠrZrZr[r’
sz%MultiIndex.dtypes.<locals>.<listcomp>cSsg|]
}|j‘qSrZr®rÎrZrZr[r’ s)r)ÚpandasrKr²Zfill_missing_namesr…r?)rXrKrkrZrZr[Údtypess zMultiIndex.dtypesr€cCst|jdƒS©Nr)ryrYr“rZrZr[Ú__len__ szMultiIndex.__len__cCst|ƒS)zG
        Return the number of elements in the underlying data.
        rr“rZrZr[ÚsizeszMultiIndex.sizerCcCs0dd„t|j|jƒDƒ}|D]
}d|_qt|ƒS)NcSsg|]\}}|j|d‘qS)rÍ)Z_rename)r‘ÚxrjrZrZr[r’ sz%MultiIndex.levels.<locals>.<listcomp>T)r•Ú_levelsrsZ_no_setting_namerC)rXr‡rŠrZrZr[r…szMultiIndex.levels)rŠrvrxrwÚNone)rvrxrwric s|rVt|ƒdkrtdƒ‚|dkr6t|ƒˆjkr6tdƒ‚|dk    rVt|ƒt|ƒkrVtdƒ‚|dkrvt‡fdd„|Dƒƒ}nL‡fdd„|Dƒ}tˆjƒ}t||ƒD]\}    }
t|
ˆd     ¡||    <qœt|ƒ}|r؈j    |d
} | ˆ_
ˆj } |ˆ_t | ƒröˆ  | ¡ˆ ¡dS) Nrz#Must set non-zero number of levels.z-Length of levels must match number of levels.z,Length of levels must match length of level.c3s|]}t|ˆd ¡VqdS©rÃN)rAÚ_view©r‘ÚlevrÃrZr[r­;sz)MultiIndex._set_levels.<locals>.<genexpr>csg|]}ˆ |¡‘qSrZ©Ú_get_level_numberrÙr“rZr[r’?sz*MultiIndex._set_levels.<locals>.<listcomp>rér…)ryrzršrCr‰rÕr•rArØrr‚rkrrÚ _reset_cache) rXr…rŠrvrxrwÚ
new_levelsÚ level_numbersZnew_levels_listÚlev_numrÚrˆrkrZ©rvrXr[r}&s0   ÿ
 
 
zMultiIndex._set_levels©rŠrw)rwricCsPt|ƒrt|tƒst|ƒ}t||dƒ\}}| ¡}| ¡|j||d|d|S)aé    
        Set new levels on MultiIndex. Defaults to returning new index.
 
        Parameters
        ----------
        levels : sequence or list of sequence
            New level(s) to apply.
        level : int, level name, or sequence of int/level names (default None)
            Level(s) to set (None for all levels).
        verify_integrity : bool, default True
            If True, checks that levels and codes are compatible.
 
        Returns
        -------
        MultiIndex
 
        Examples
        --------
        >>> idx = pd.MultiIndex.from_tuples(
        ...     [
        ...         (1, "one"),
        ...         (1, "two"),
        ...         (2, "one"),
        ...         (2, "two"),
        ...         (3, "one"),
        ...         (3, "two")
        ...     ],
        ...     names=["foo", "bar"]
        ... )
        >>> idx
        MultiIndex([(1, 'one'),
            (1, 'two'),
            (2, 'one'),
            (2, 'two'),
            (3, 'one'),
            (3, 'two')],
           names=['foo', 'bar'])
 
        >>> idx.set_levels([['a', 'b', 'c'], [1, 2]])
        MultiIndex([('a', 1),
                    ('a', 2),
                    ('b', 1),
                    ('b', 2),
                    ('c', 1),
                    ('c', 2)],
                   names=['foo', 'bar'])
        >>> idx.set_levels(['a', 'b', 'c'], level=0)
        MultiIndex([('a', 'one'),
                    ('a', 'two'),
                    ('b', 'one'),
                    ('b', 'two'),
                    ('c', 'one'),
                    ('c', 'two')],
                   names=['foo', 'bar'])
        >>> idx.set_levels(['a', 'b'], level='bar')
        MultiIndex([(1, 'a'),
                    (1, 'b'),
                    (2, 'a'),
                    (2, 'b'),
                    (3, 'a'),
                    (3, 'b')],
                   names=['foo', 'bar'])
 
        If any of the levels passed to ``set_levels()`` exceeds the
        existing length, all of the values from that argument will
        be stored in the MultiIndex levels, though the values will
        be truncated in the MultiIndex output.
 
        >>> idx.set_levels([['a', 'b', 'c'], [1, 2, 3, 4]], level=[0, 1])
        MultiIndex([('a', 1),
            ('a', 2),
            ('b', 1),
            ('b', 2),
            ('c', 1),
            ('c', 2)],
           names=['foo', 'bar'])
        >>> idx.set_levels([['a', 'b', 'c'], [1, 2, 3, 4]], level=[0, 1]).levels
        FrozenList([['a', 'b', 'c'], [1, 2, 3, 4]])
        ZLevelsT)rŠrxrw)r2rªr?r‰Ú_require_listlikerØrƒr})rXr…rŠrwÚidxrZrZr[Ú
set_levelsPsSÿzMultiIndex.set_levelscCs
t|jƒS)a
        Integer number of levels in this MultiIndex.
 
        Examples
        --------
        >>> mi = pd.MultiIndex.from_arrays([['a'], ['b'], ['c']])
        >>> mi
        MultiIndex([('a', 'b', 'c')],
                   )
        >>> mi.nlevels
        3
        )ryrÕr“rZrZr[rš®szMultiIndex.nlevelsr cCstdd„|jDƒƒS)a
        A tuple with the length of each level.
 
        Examples
        --------
        >>> mi = pd.MultiIndex.from_arrays([['a'], ['b'], ['c']])
        >>> mi
        MultiIndex([('a', 'b', 'c')],
                   )
        >>> mi.levshape
        (1, 1, 1)
        css|]}t|ƒVqdSr©r©r‘rÔrZrZr[r­Ìsz&MultiIndex.levshape.<locals>.<genexpr>)r«r…r“rZrZr[Úlevshape¾szMultiIndex.levshapecCs|jSr©)r‚r“rZrZr[rYÑszMultiIndex.codesc sà|rB|dkr"t|ƒˆjkr"tdƒ‚|dk    rBt|ƒt|ƒkrBtdƒ‚|dkrjt‡fdd„tˆj|ƒDƒƒ}nT‡fdd„|Dƒ}tˆjƒ}t||ƒD]$\}    }
ˆj|    } t    |
| ˆd||    <qt|ƒ}|rΈj
|d}|ˆ_ˆ  ¡dS)    Nz+Length of codes must match number of levelsz,Length of codes must match length of levels.c3s$|]\}}t||ˆd ¡VqdSr×)Ú_coerce_indexer_frozenÚview)r‘rÚrœrÃrZr[r­åsÿz(MultiIndex._set_codes.<locals>.<genexpr>csg|]}ˆ |¡‘qSrZrÛrÙr“rZr[r’êsz)MultiIndex._set_codes.<locals>.<listcomp>rérY) ryršrzrCr•rÕr‰r‚r…rérrÞ) rXrYrŠrvrxrwrˆràZnew_codes_listrárœrÚrZrâr[r~Õs.     
þ
 
 
ÿ  zMultiIndex._set_codes)rwcCs4t||dƒ\}}| ¡}| ¡|j|||d|S)a0
        Set new codes on MultiIndex. Defaults to returning new index.
 
        Parameters
        ----------
        codes : sequence or list of sequence
            New codes to apply.
        level : int, level name, or sequence of int/level names (default None)
            Level(s) to set (None for all levels).
        verify_integrity : bool, default True
            If True, checks that levels and codes are compatible.
 
        Returns
        -------
        new index (of same type and class...etc) or None
            The same type as the caller or None if ``inplace=True``.
 
        Examples
        --------
        >>> idx = pd.MultiIndex.from_tuples(
        ...     [(1, "one"), (1, "two"), (2, "one"), (2, "two")], names=["foo", "bar"]
        ... )
        >>> idx
        MultiIndex([(1, 'one'),
            (1, 'two'),
            (2, 'one'),
            (2, 'two')],
           names=['foo', 'bar'])
 
        >>> idx.set_codes([[1, 0, 1, 0], [0, 0, 1, 1]])
        MultiIndex([(2, 'one'),
                    (1, 'one'),
                    (2, 'two'),
                    (1, 'two')],
                   names=['foo', 'bar'])
        >>> idx.set_codes([1, 0, 1, 0], level=0)
        MultiIndex([(2, 'one'),
                    (1, 'two'),
                    (2, 'one'),
                    (1, 'two')],
                   names=['foo', 'bar'])
        >>> idx.set_codes([0, 0, 1, 1], level='bar')
        MultiIndex([(1, 'one'),
                    (1, 'one'),
                    (2, 'two'),
                    (2, 'two')],
                   names=['foo', 'bar'])
        >>> idx.set_codes([[1, 0, 1, 0], [0, 0, 1, 1]], level=[0, 1])
        MultiIndex([(2, 'one'),
                    (1, 'one'),
                    (2, 'two'),
                    (1, 'two')],
                   names=['foo', 'bar'])
        ZCodesrã)rärØrƒr~)rXrYrŠrwrårZrZr[Ú    set_codesús
8zMultiIndex.set_codescCs„t t dd„|jDƒ¡¡}t |ddd…¡ddd…}t |dd…dgg¡ d¡}|ddkrtt|j|j|ƒSt    |j|j|ƒS)NcSsg|]}t|ƒtj‘qSrZ)ryraZmultiindex_nulls_shiftrÎrZrZr[r’Csþÿz&MultiIndex._engine.<locals>.<listcomp>rŒrOrÚuint64é@)
rTÚceilÚlog2r…ZcumsumÚ concatenaterfrdrYrN)rXÚsizesZlev_bitsrRrZrZr[Ú_engine;sýÿÿ  zMultiIndex._enginezCallable[..., MultiIndex]cCs
t|ƒjSr©)Útyper¸r“rZrZr[Ú _constructor]szMultiIndex._constructor)rÊricCs(|tjk    r|n|j}t|ƒj|d|dS)Nr¯)rr£rkrôr¸)rXrÊrjrkrZrZr[Ú _shallow_copyaszMultiIndex._shallow_copycCs<t|ƒ|j|j|j|jdd}|j ¡|_|j dd¡|S)NFr¡r…)rôr…rYrtrkr|rvrm)rXr‡rZrZr[rØgsû zMultiIndex._view©Údeepc    Cs¨|j|||d}| }d\}}|rBddlm}||jƒ}||jƒ}|dk    rN|n|j}|dk    r`|n|j}t|ƒ|||j|dd}|j ¡|_|j dd¡|r¤|j    |_    |S)    a
        Make a copy of this object.
 
        Names, dtype, levels and codes can be passed and will be set on new copy.
 
        Parameters
        ----------
        names : sequence, optional
        deep : bool, default False
        name : Label
            Kept for compatibility with 1-dimensional Index. Should not be used.
 
        Returns
        -------
        MultiIndex
 
        Notes
        -----
        In most cases, there should be no functional difference from using
        ``deep``, but if ``deep`` is passed it will attempt to deepcopy.
        This could be potentially expensive on large MultiIndex objects.
 
        Examples
        --------
        >>> mi = pd.MultiIndex.from_arrays([['a'], ['b'], ['c']])
        >>> mi
        MultiIndex([('a', 'b', 'c')],
                   )
        >>> mi.copy()
        MultiIndex([('a', 'b', 'c')],
                   )
        )rjrkrø)NNr)ÚdeepcopyNFr¡r…)
Z_validate_namesrvrùr…rYrôrtr|rmÚ_id)    rXrkrørjZkeep_idr…rYrùÚ    new_indexrZrZr[rvvs*& 
 
û zMultiIndex.copycCs|jS)z%the array interface, return my values)rÊ©rXr†rZrZr[Ú    __array__¶szMultiIndex.__array__cCs| ¡}|j|_|S)z0this is defined as a copy with the same identity)rvrú)rXr„r‡rZrZr[rêºszMultiIndex.viewr)Úkeyric
Cs:t|ƒz| |¡WdStttfk
r4YdSXdS)NTF)ÚhashÚget_locÚ LookupErrorrlrz©rXrþrZrZr[Ú __contains__Às 
zMultiIndex.__contains__znp.dtypecCs
t d¡S)NÚO)rTr†r“rZrZr[r†ÉszMultiIndex.dtypecs&ddœdd„‰t‡fdd„|jDƒƒS)z5return a boolean if we need a qualified .info displayrurÂcSsd|kpd|kpd|kS)NÚmixedÚstringÚunicoderZ©rŠrZrZr[ÚfÐsz0MultiIndex._is_memory_usage_qualified.<locals>.fc3s|]}ˆ|ƒVqdSr©rZrΩr    rZr[r­Ósz8MultiIndex._is_memory_usage_qualified.<locals>.<genexpr>)rÚ_inferred_type_levelsr“rZr
r[Ú_is_memory_usage_qualifiedÍsz%MultiIndex._is_memory_usage_qualified)røricCs
| |¡Sr©©Ú_nbytes)rXrørZrZr[Ú memory_usageÖszMultiIndex.memory_usagecCs
| d¡S)z1return the number of bytes in the underlying dataFr r“rZrZr[ÚnbytesÝszMultiIndex.nbytescsjd‰t‡fdd„|jDƒƒ}tdd„|jDƒƒ}t‡fdd„|jDƒƒ}|||}||jjˆd7}|S)zÇ
        return the number of bytes in the underlying data
        deeply introspect the level data if deep=True
 
        include the engine hashtable
 
        *this is in internal routine*
 
        éc3s|]}|jˆdVqdS)r÷N)r©r‘r›r÷rZr[r­ïsz%MultiIndex._nbytes.<locals>.<genexpr>css|] }|jVqdSr©)rrrZrZr[r­ðsc3s|]}t|ˆƒVqdSr©rr)ÚobjsizerZr[r­ñsr÷)Úsumr…rYrkróÚsizeof)rXrøZ level_nbytesZ label_nbytesZ names_nbytesr‡rZ)rørr[râs  zMultiIndex._nbytescCs(dd„|jDƒ}tdd„t||ƒDƒƒS)zW
        Formats each item in tup according to its level's formatter function.
        cSsg|]
}|j‘qSrZ)Ú_formatter_funcrÎrZrZr[r’ÿsz.MultiIndex._formatter_func.<locals>.<listcomp>css|]\}}||ƒVqdSr©rZ)r‘ÚfuncÚvalrZrZr[r­sz-MultiIndex._formatter_func.<locals>.<genexpr>)r…r«r•)rXÚtupZformatter_funcsrZrZr[rûszMultiIndex._formatter_funcÚnan)Úna_repÚstrznpt.NDArray[np.object_])rric KsØg}g}t|j|jƒD]z\}}|jfd|i|—Ž}|dk}| ¡r|t|ƒ}    | t¡}t     ||¡}|j
j rlt ‚|  ¡}|    ||<|     |¡|     |¡qt|ƒdkr¸t|d |d¡ƒ ¡St|||j|jdd}
|
jSdS)NrrŒrOrF©r…rYrkrtrw)r•r…rYÚ_format_native_typesrryrfrrTrÉÚflagsÚ    writeableÚAssertionErrorrvr?ÚtakerLrkrtr¶) rXrrorßrˆrŠrœZ
level_strsÚmaskZ    nan_indexÚmirZrZr[rs0
 
  ûzMultiIndex._format_native_typeséz bool | NonezCallable | Nonez
str | None)rjÚ    formatterrrkÚspaceÚadjoinrics¶|dk    r |}t|ƒdkrgSg}t|j|jƒD]’\}    }
|dk    rB|nt|    jƒ‰t|    ƒdkrš|     |
¡j|d} |
dk} |  ¡r¶t    j
| t d} ˆ| | <|   ¡} n‡fdd„t  |    j|
¡Dƒ} | | ¡q.g} t||jƒD]N\}    }g}|r| |dk    rüt|ddnd    ¡| t    j
|    t d¡|  |¡qÒ|dkr4td
ƒ}|r€d    }t|tƒsZ|tjksZt‚|d tjfkrn|}t| t|ƒ|d } |r®dd lm}|ƒ}|j|f| žŽ d¡S| SdS)Nr)r&rŒr®cs$g|]}tt|ƒrˆn|dd‘qS)©ú    ú Ú
©Z escape_chars)rHr;rç©ÚnarZr[r’Fsÿz%MultiIndex.format.<locals>.<listcomp>r)r-Úzdisplay.multi_sparseF©ÚstartÚsentinel)Úget_adjustmentr,) ryr•r…rYÚ _get_na_repr†r"ÚformatrrTr¦reÚtolistrrÇr¶rÉrkrHÚextendrrªrurr£r!Úsparsify_labelsr€Zpandas.io.formats.formatr4r(Úsplit)rXrjr&rrkr'Zsparsifyr(Zstringified_levelsrÚrœÚ    formattedr#Z result_levelsZlev_namerŠr3r4ZadjrZr.r[r6&s\
 
 
 þ ÿý 
ÿ zMultiIndex.formatcCs
t|jƒSr©)rCrsr“rZrZr[Ú
_get_namessszMultiIndex._get_names)rŠrx©rxcsÖ|dk    rt|ƒstdƒ‚t|ƒ}|rb|dk    rDt|ƒt|ƒkrDtdƒ‚|dkrbt|ƒˆjkrbtdƒ‚|dkrvtˆjƒ}n‡fdd„|Dƒ}t||ƒD]6\}}|dk    r¾t|ƒs¾tt    ˆƒj
›dƒ‚|ˆj |<q’ˆ  ¡dS)aö
        Set new names on index. Each name has to be a hashable type.
 
        Parameters
        ----------
        values : str or sequence
            name(s) to set
        level : int, level name, or sequence of int/level names (default None)
            If the index is a MultiIndex (hierarchical), level(s) to set (None
            for all levels).  Otherwise level must be None
        validate : bool, default True
            validate that the names match level lengths
 
        Raises
        ------
        TypeError if each name is not hashable.
 
        Notes
        -----
        sets names on levels. WARNING: mutates!
 
        Note that you generally want to set this *after* changing levels, so
        that it only acts on copies
        Nz*Names should be list-like for a MultiIndexz+Length of names must match length of level.z:Length of names must match number of levels in MultiIndex.csg|]}ˆ |¡‘qSrZrÛrÙr“rZr[r’ sz)MultiIndex._set_names.<locals>.<listcomp>z.name must be a hashable type) r2rzr‰ryršr¢r•r/rlrôr]rsrÞ)rXrkrŠrxrÚrjrZr“r[rvs*ÿ ÿ zMultiIndex._set_namesam
        Names of levels in MultiIndex.
 
        Examples
        --------
        >>> mi = pd.MultiIndex.from_arrays(
        ... [[1, 2], [3, 4], [5, 6]], names=['x', 'y', 'z'])
        >>> mi
        MultiIndex([(1, 3, 5),
                    (2, 4, 6)],
                   names=['x', 'y', 'z'])
        >>> mi.names
        FrozenList(['x', 'y', 'z'])
        )ÚfsetÚfgetr(cCsdS)NrrZr“rZrZr[Ú inferred_typeÅszMultiIndex.inferred_typec
Csä|j |¡}|dkr,t|ƒs,td|›dƒ‚z|j |¡}Wn¢tk
rÞ}z„t|ƒshtd|›dƒ|‚|dkr¨||j7}|dkrÎ||j}td|j›d|›d    ƒ|‚n&||jkrÎtd|j›d
|d›ƒ|‚W5d}~XYnX|S) NrOz    The name z* occurs multiple times, use a level numberzLevel z
 not foundrz Too many levels: Index has only z     levels, z is not a valid level numberz  levels, not )rkÚcountr0rzrÚKeyErrorršÚ
IndexError)rXrŠrAÚerrZ
orig_levelrZrZr[rÜÉs4 
ÿ
 
ÿý
ÿýzMultiIndex._get_level_numbercsžtdd„ˆjDƒƒrdStdd„ˆjDƒƒrBt dd„ˆjDƒ¡S‡fdd„tttˆjƒƒƒDƒ}zt     
|¡}t |ƒj WSt k
r˜t ˆjƒj YSXdS)    zI
        Return a boolean if the values are equal or increasing.
        css|]}d|kVqdS)rŒNrZ)r‘r‹rZrZr[r­ész5MultiIndex.is_monotonic_increasing.<locals>.<genexpr>Fcss|] }|jVqdSr©©Úis_monotonic_increasingrÎrZrZr[r­ìscSsg|]}|jddd‘qS)Úint64FrÃ)rfrçrZrZr[r’ïsz6MultiIndex.is_monotonic_increasing.<locals>.<listcomp>csg|]}ˆ |¡j‘qSrZ)Ú_get_level_valuesr¶rr“rZr[r’ósN)rrYr°r…ÚlibalgosÚ is_lexsortedÚreversedr¢ryrTÚlexsortr?rFrlr¶)rXrÊZ
sort_orderrZr“r[rFäsÿ
ÿ
 z"MultiIndex.is_monotonic_increasingcCs|ddd…jS)zI
        Return a boolean if the values are equal or decreasing.
        NrŒrEr“rZrZr[Úis_monotonic_decreasingsz"MultiIndex.is_monotonic_decreasingz    list[str]cCsdd„|jDƒS)z7return a list of the inferred types, one for each levelcSsg|]
}|j‘qSrZ)r@rrZrZr[r’sz4MultiIndex._inferred_type_levels.<locals>.<listcomp>rÝr“rZrZr[r  sz MultiIndex._inferred_type_levelsÚfirstrúnpt.NDArray[np.bool_])ÚkeepricCs0tdd„|jDƒƒ}t|j|ddd}t||ƒS)Ncss|]}t|ƒVqdSr©rrÙrZrZr[r­sz(MultiIndex.duplicated.<locals>.<genexpr>F)ÚsortZxnull)r«r…rErYr)rXrPÚshapeÚidsrZrZr[rszMultiIndex.duplicatedcCs tdƒ‚dS)z:
        fillna is not implemented for MultiIndex
        z"isna is not defined for MultiIndexN)ÚNotImplementedError)rXÚvalueZdowncastrZrZr[ÚfillnaszMultiIndex.fillnarr)Úhowricsndd„|jDƒ}|dkr(tj|dd‰n&|dkr@tj|dd‰ntd|›ƒ‚‡fdd„|jDƒ}|j|d    S)
NcSsg|] }|dk‘qS)rŒrZ©r‘rœrZrZr[r’#sz%MultiIndex.dropna.<locals>.<listcomp>rrrPr°zinvalid how option: csg|]}|ˆ‘qSrZrZrX©ÚindexerrZr[r’+srë)rYrTrr°rzrì)rXrWZnansrˆrZrYr[Údropna!szMultiIndex.dropnar?)rŠÚuniquericCsN|j|}|j|}|j|}|r,t |¡}tj|j||jd}|j||dS)aP
        Return vector of label values for requested level,
        equal to the length of the index
 
        **this is an internal method**
 
        Parameters
        ----------
        level : int
        unique : bool, default False
            if True, drop duplicated values
 
        Returns
        -------
        Index
        rÄrÍ)    r…rYrsrr\rÇr¶rÈrö)rXrŠr\rÚrœrjZfilledrZrZr[rH.s
 
 
 
zMultiIndex._get_level_valuescCs| |¡}| |¡}|S)a(
        Return vector of label values for requested level.
 
        Length of returned vector is equal to the length of the index.
 
        Parameters
        ----------
        level : int or str
            ``level`` is either the integer position of the level in the
            MultiIndex, or the name of the level.
 
        Returns
        -------
        Index
            Values is a level of this MultiIndex converted to
            a single :class:`Index` (or subclass thereof).
 
        Notes
        -----
        If the level contains missing values, the result may be casted to
        ``float`` with missing values specified as ``NaN``. This is because
        the level is converted to a regular ``Index``.
 
        Examples
        --------
        Create a MultiIndex:
 
        >>> mi = pd.MultiIndex.from_arrays((list('abc'), list('def')))
        >>> mi.names = ['level_1', 'level_2']
 
        Get level values by supplying level as either integer or name:
 
        >>> mi.get_level_values(0)
        Index(['a', 'b', 'c'], dtype='object', name='level_1')
        >>> mi.get_level_values('level_2')
        Index(['d', 'e', 'f'], dtype='object', name='level_2')
 
        If a level contains missing values, the return type of the level
        may be cast to ``float``.
 
        >>> pd.MultiIndex.from_arrays([[1, None, 2], [3, 4, 5]]).dtypes
        level_0    int64
        level_1    int64
        dtype: object
        >>> pd.MultiIndex.from_arrays([[1, None, 2], [3, 4, 5]]).get_level_values(0)
        Index([1.0, nan, 2.0], dtype='float64')
        )rÜrH)rXrŠrÊrZrZr[Úget_level_valuesGs0
 
zMultiIndex.get_level_valuescCs,|dkr| ¡S| |¡}|j|ddSdS)NT)rŠr\)Zdrop_duplicatesrÜrH)rXrŠrZrZr[r\{s
zMultiIndex.unique)rÚallow_duplicatesrics¦ddlm}|tjk    rFt|ƒs&tdƒ‚t|ƒtˆjƒkr@tdƒ‚|}nˆ     ¡}|sntt
|ƒƒt|ƒkrntdƒ‚|‡fdd„t tˆjƒƒDƒdd    }||_ |r¢ˆ|_ |S)
a$
        Create a DataFrame with the levels of the MultiIndex as columns.
 
        Column ordering is determined by the DataFrame constructor with data as
        a dict.
 
        Parameters
        ----------
        index : bool, default True
            Set the index of the returned DataFrame as the original MultiIndex.
 
        name : list / sequence of str, optional
            The passed names should substitute index level names.
 
        allow_duplicates : bool, optional default False
            Allow duplicate column labels to be created.
 
            .. versionadded:: 1.5.0
 
        Returns
        -------
        DataFrame
 
        See Also
        --------
        DataFrame : Two-dimensional, size-mutable, potentially heterogeneous
            tabular data.
 
        Examples
        --------
        >>> mi = pd.MultiIndex.from_arrays([['a', 'b'], ['c', 'd']])
        >>> mi
        MultiIndex([('a', 'c'),
                    ('b', 'd')],
                   )
 
        >>> df = mi.to_frame()
        >>> df
             0  1
        a c  a  c
        b d  b  d
 
        >>> df = mi.to_frame(index=False)
        >>> df
           0  1
        0  a  c
        1  b  d
 
        >>> df = mi.to_frame(name=['x', 'y'])
        >>> df
             x  y
        a c  a  c
        b d  b  d
        r)rJz1'name' must be a list / sequence of column names.z<'name' should have same length as number of levels on index.zBCannot create duplicate column labels if allow_duplicates is Falsecsi|]}|ˆ |¡“qSrZ©rHrÎr“rZr[Ú
<dictcomp>Ôsz'MultiIndex.to_frame.<locals>.<dictcomp>FrÃ)rÏrJrr£r2rlryr…rzZ_get_level_namesÚsetr¢r¿r)rXrrjr^rJZ    idx_namesr‡rZr“r[Úto_frameƒs,< 
ÿÿþzMultiIndex.to_framecCst|jddS)a
        Convert a MultiIndex to an Index of Tuples containing the level values.
 
        Returns
        -------
        pd.Index
            Index with the MultiIndex data represented in Tuples.
 
        See Also
        --------
        MultiIndex.from_tuples : Convert flat index back to MultiIndex.
 
        Notes
        -----
        This method will simply return the caller if called by anything other
        than a MultiIndex.
 
        Examples
        --------
        >>> index = pd.MultiIndex.from_product(
        ...     [['foo', 'bar'], ['baz', 'qux']],
        ...     names=['a', 'b'])
        >>> index.to_flat_index()
        Index([('foo', 'baz'), ('foo', 'qux'),
               ('bar', 'baz'), ('bar', 'qux')],
              dtype='object')
        F)Z tupleize_cols)r?r¶r“rZrZr[Ú to_flat_indexßszMultiIndex.to_flat_indexcCs |j|jkS)a´
        Return True if the codes are lexicographically sorted.
 
        Returns
        -------
        bool
 
        Examples
        --------
        In the below examples, the first level of the MultiIndex is sorted because
        a<b<c, so there is no need to look at the next level.
 
        >>> pd.MultiIndex.from_arrays([['a', 'b', 'c'],
        ...                            ['d', 'e', 'f']])._is_lexsorted()
        True
        >>> pd.MultiIndex.from_arrays([['a', 'b', 'c'],
        ...                            ['d', 'f', 'e']])._is_lexsorted()
        True
 
        In case there is a tie, the lexicographical sorting looks
        at the next level of the MultiIndex.
 
        >>> pd.MultiIndex.from_arrays([[0, 1, 1], ['a', 'b', 'c']])._is_lexsorted()
        True
        >>> pd.MultiIndex.from_arrays([[0, 1, 1], ['a', 'c', 'b']])._is_lexsorted()
        False
        >>> pd.MultiIndex.from_arrays([['a', 'a', 'b', 'b'],
        ...                            ['aa', 'bb', 'aa', 'bb']])._is_lexsorted()
        True
        >>> pd.MultiIndex.from_arrays([['a', 'a', 'b', 'b'],
        ...                            ['bb', 'aa', 'aa', 'bb']])._is_lexsorted()
        False
        )r™ršr“rZrZr[Ú _is_lexsortedýs"zMultiIndex._is_lexsortedcCs|jdk    r|jSt|j|jƒS)z­
        Compute and return the lexsort_depth, the number of levels of the
        MultiIndex that are sorted lexically
 
        Returns
        -------
        int
        N)rtr™rYršr“rZrZr[r™!s
 
zMultiIndex._lexsort_depth)Úraise_if_incomparableric    Cs¸| ¡r|jr|Sg}g}t|j|jƒD]x\}}|jsŒz | ¡}Wntk
r\|rX‚Yn0X| |¡}t|ƒ}t     
|t |ƒ¡}t   ||¡}| |¡| |¡q(t|||j|jddS)aÖ
        This is an *internal* function.
 
        Create a new MultiIndex from the current to monotonically sorted
        items IN the levels. This does not actually make the entire MultiIndex
        monotonic, JUST the levels.
 
        The resulting MultiIndex will have the same outward
        appearance, meaning the same .values and ordering. It will also
        be .equals() to the original.
 
        Returns
        -------
        MultiIndex
 
        Examples
        --------
        >>> mi = pd.MultiIndex(levels=[['a', 'b'], ['bb', 'aa']],
        ...                    codes=[[0, 0, 1, 1], [0, 1, 0, 1]])
        >>> mi
        MultiIndex([('a', 'bb'),
                    ('a', 'aa'),
                    ('b', 'bb'),
                    ('b', 'aa')],
                   )
 
        >>> mi.sort_values()
        MultiIndex([('a', 'aa'),
                    ('a', 'bb'),
                    ('b', 'aa'),
                    ('b', 'bb')],
                   )
        F)rkrtrw)rdrFr•r…rYÚargsortrlr"r,rZget_reverse_indexerryrrÇrÉrLrkrt)rXrerßrˆrÚrœrZÚrirZrZr[Ú_sort_levels_monotonic/s0" 
 
 ûz!MultiIndex._sort_levels_monotonicc Csbg}g}d}t|j|jƒD]\}}t t |d¡dk¡dd}tt|ƒoX|ddkƒ}t|ƒt|ƒ|kr| ¡     ¡r”t|ƒt|ƒkr”q,d}t
  |¡}|rÔt |dk¡d}||ddg|d|dg<t  t|ƒ|¡}    t  t|ƒ¡||    |<|    |}| ||d…¡}| |¡| |¡q| ¡}
|r^|
 ¡|
j|dd|
j|dd|
S)a¤
        Create new MultiIndex from current that removes unused levels.
 
        Unused level(s) means levels that are not expressed in the
        labels. The resulting MultiIndex will have the same outward
        appearance, meaning the same .values and ordering. It will
        also be .equals() to the original.
 
        Returns
        -------
        MultiIndex
 
        Examples
        --------
        >>> mi = pd.MultiIndex.from_product([range(2), list('ab')])
        >>> mi
        MultiIndex([(0, 'a'),
                    (0, 'b'),
                    (1, 'a'),
                    (1, 'b')],
                   )
 
        >>> mi[2:]
        MultiIndex([(1, 'a'),
                    (1, 'b')],
                   )
 
        The 0 from the first level is not represented
        and can be removed
 
        >>> mi2 = mi[2:].remove_unused_levels()
        >>> mi2.levels
        FrozenList([[1], ['a', 'b']])
        FrOrrŒTNr=)r•r…rYrTrŽZbincountr€ryr;rrr\r±Úaranger"rÉrêrƒr}r~) rXrßrˆÚchangedrÚrœZuniquesZhas_naZna_idxZ code_mappingr‡rZrZr[Úremove_unused_levelsrs4# 
 
 zMultiIndex.remove_unused_levelscCs6t|jƒt|jƒ|jt|jƒdœ}tjt|ƒ|fdfS)z*Necessary for making this object picklable)r…rYrtrkN)r‰r…rYrtrkÚibaseZ
_new_Indexrô)rXÚdrZrZr[Ú
__reduce__Ês üzMultiIndex.__reduce__csîtˆƒrbt ˆ¡‰g}t|j|jƒD]4\}}|ˆdkrF| tj¡q$| ||ˆ¡q$t    |ƒSd}t 
ˆ¡r†tj ˆt d‰|j }n:tˆtƒr¬ˆjdks¤ˆjdkrÀ|j }ntˆtƒrÀt  ˆ¡‰‡fdd„|jDƒ}t|j||j|ddSdS)NrŒr®rcsg|] }|ˆ‘qSrZrZrX©rþrZr[r’îsz*MultiIndex.__getitem__.<locals>.<listcomp>Fr)r4r²Zcast_scalar_indexerr•r…rYrÉrTrr«Úis_bool_indexerrµrurtrªÚsliceÚstepr?rLrk)rXrþÚretvalrÚrœrtrˆrZror[Ú __getitem__Ös2
 
 
 
 
ûzMultiIndex.__getitem__rq)rXÚslobjricsLd}ˆjdksˆjdkr|j}‡fdd„|jDƒ}t|ƒ|j||j|ddS)zH
        Fastpath for __getitem__ when we know we have a slice.
        Nrcsg|] }|ˆ‘qSrZrZrX©rurZr[r’sz-MultiIndex._getitem_slice.<locals>.<listcomp>Fr)rrrtrYrôr…rs)rXrurtrˆrZrvr[Ú_getitem_sliceøsûzMultiIndex._getitem_slicer"rr)rXrQÚ
allow_fillric  st d|¡tˆƒ‰| ||ˆ¡}d}‡fdd„|jDƒ}|r|ˆdk}| ¡r|g}    |D] }
|
} || |<|     t | ¡¡qV|    }t    |j
||j ddS)NrZrŒcsg|]}| ˆ¡‘qSrZ©r")r‘Úlab©ÚindicesrZr[r’sz#MultiIndex.take.<locals>.<listcomp>F©r…rYrkrw) ÚnvZ validate_taker,Z_maybe_disallow_fillrYrrÉrTrµrLr…rk) rXr|rQrxrÅroÚna_valueZtakenr#ZmaskedZ    new_labelZ label_valuesrZr{r[r"
s(     ÿzMultiIndex.takec    st|ttfƒs|g}t‡fdd„|Dƒƒr¨gg}}tˆjƒD]Z‰ˆ ˆ¡‰‡fdd„|Dƒ}| ˆ |¡¡t‡fdd„|Dƒƒ}| |r’ˆjnd¡q>t    j
||dSˆj ftdd„|Dƒƒ}t   |¡}z t     |¡WSttfk
rút|ƒYSXdS)    aä
        Append a collection of Index options together.
 
        Parameters
        ----------
        other : Index or list/tuple of indices
 
        Returns
        -------
        Index
            The combined index.
 
        Examples
        --------
        >>> mi = pd.MultiIndex.from_arrays([['a'], ['b']])
        >>> mi
        MultiIndex([('a', 'b')],
                   )
        >>> mi.append(mi)
        MultiIndex([('a', 'b'), ('a', 'b')],
                   )
        c3s$|]}t|tƒo|jˆjkVqdSr©)rªrLrš©r‘Úor“rZr[r­Dsz$MultiIndex.append.<locals>.<genexpr>csg|]}| ˆ¡‘qSrZr_r€)r›rZr[r’Jsz%MultiIndex.append.<locals>.<listcomp>c3s|]}ˆj|jkVqdSr©rÍrç)ÚlabelrZr[r­LsN©rkcss|] }|jVqdSr©rÌ©r‘ÚkrZrZr[r­Ps)rªr‰r«r°r¢ršrHrÉrjrLr§r¶rTrñr¸rlrCr?)rXÚotherr¤rkZappendedZsingle_label_nameZ    to_concatZ
new_tuplesrZ)r›r‚rXr[rÉ*s& ÿ
 
 
 zMultiIndex.appendznpt.NDArray[np.intp]cOs>t|ƒdkr0t|ƒdkr0|jdd}t| ¡ƒS|jj||ŽS)NrT)re)ryrhrGÚ_get_codes_for_sortingr¶rf)rXrnroÚtargetrZrZr[rf[s  zMultiIndex.argsortÚrepeat)Úrepeatsrics@t dd|i¡tˆƒ‰t|j‡fdd„|jDƒ|j|jddS)NrZrQcs*g|]"}| tj¡jtjdd ˆ¡‘qS)FrÃ)rêrTr´rfÚintpr‰rX©rŠrZr[r’jsÿz%MultiIndex.repeat.<locals>.<listcomp>Fr)r~Zvalidate_repeatr,rLr…rYrkrt)rXrŠrQrZrŒr[r‰bs
þøzMultiIndex.repeatÚraisez.Index | np.ndarray | Iterable[Hashable] | Noner)rŠÚerrorsric        Cs>|dk    r| |||¡St|tjtfƒsTztj|t d¡d}Wntk
rRYnXg}|D]Ö}z®|     |¡}t|t
ƒr‚|  |¡nŠt|t ƒr¸|j dk    rœ|j nd}| t|j|j|ƒ¡nTt |¡rö|jdkrÞtjdttƒd| ¡d}| |¡ndt|ƒ›}t|ƒ‚Wq\tk
r0|d    kr,‚Yq\Xq\| |¡S)
aV
        Make new MultiIndex with passed list of codes deleted.
 
        Parameters
        ----------
        codes : array-like
            Must be a list of tuples when level is not specified.
        level : int or level name, default None
        errors : str, default 'raise'
 
        Returns
        -------
        MultiIndex
        Nrer®rOrzYdropping on a non-lexsorted multi-index without a level parameter may impact performance.©Ú
stacklevelzunsupported indexer of type Úignore)Ú_drop_from_levelrªrTr´r?r²Úindex_labels_to_arrayr†rzrr€rÉrqrrr8r¢r2Ústoprpr™ÚwarningsÚwarnr$r)Únonzerorôr!rBÚdelete)    rXrYrŠrŽZindsrœÚlocrrÚmsgrZrZr[Údropts>
 
 
 
 
ü   
 
zMultiIndex.drop)rŽric
Cs¸t |¡}| |¡}|j|}| |¡}t|ƒ}d|t |d¡|dk@<|jd|jdkrld|t |d¡<||dk}t    |ƒdkrœ|dkrœt
d|›dƒ‚t   |j ||¡}    ||    S)    NéþÿÿÿFrŒrTr‘zlabels z not found in level)r²r“rÜr…Ú get_indexerr;rTÚequalrRryrBrÚisinrY)
rXrYrŠrŽr›rrÊZ    nan_codesÚ    not_foundr#rZrZr[r’¯s
 
 
 
 zMultiIndex._drop_from_levelrœrŒcCst|jƒ}t|jƒ}t|jƒ}| |¡}| |¡}||||||<||<||||||<||<||||||<||<t|||ddS)aú
        Swap level i with level j.
 
        Calling this method does not change the ordering of the values.
 
        Parameters
        ----------
        i : int, str, default -2
            First level of index to be swapped. Can pass level name as string.
            Type of parameters can be mixed.
        j : int, str, default -1
            Second level of index to be swapped. Can pass level name as string.
            Type of parameters can be mixed.
 
        Returns
        -------
        MultiIndex
            A new MultiIndex.
 
        See Also
        --------
        Series.swaplevel : Swap levels i and j in a MultiIndex.
        DataFrame.swaplevel : Swap levels i and j in a MultiIndex on a
            particular axis.
 
        Examples
        --------
        >>> mi = pd.MultiIndex(levels=[['a', 'b'], ['bb', 'aa']],
        ...                    codes=[[0, 0, 1, 1], [0, 1, 0, 1]])
        >>> mi
        MultiIndex([('a', 'bb'),
                    ('a', 'aa'),
                    ('b', 'bb'),
                    ('b', 'aa')],
                   )
        >>> mi.swaplevel(0, 1)
        MultiIndex([('bb', 'a'),
                    ('aa', 'a'),
                    ('bb', 'b'),
                    ('aa', 'b')],
                   )
        Fr})r‰r…rYrkrÜrL)rXr›ÚjrßrˆÚ    new_namesrZrZr[Ú    swaplevelÄs+
 
 
 
 
ÿzMultiIndex.swaplevelcs€‡fdd„|Dƒ}t|ƒˆjkr:tdˆj›dt|ƒ›ƒ‚‡fdd„|Dƒ}‡fdd„|Dƒ}‡fdd„|Dƒ}t|||dd    S)
aI
        Rearrange levels using input order. May not drop or duplicate levels.
 
        Parameters
        ----------
        order : list of int or list of str
            List representing new level order. Reference level by number
            (position) or by key (label).
 
        Returns
        -------
        MultiIndex
 
        Examples
        --------
        >>> mi = pd.MultiIndex.from_arrays([[1, 2], [3, 4]], names=['x', 'y'])
        >>> mi
        MultiIndex([(1, 3),
                    (2, 4)],
                   names=['x', 'y'])
 
        >>> mi.reorder_levels(order=[1, 0])
        MultiIndex([(3, 1),
                    (4, 2)],
                   names=['y', 'x'])
 
        >>> mi.reorder_levels(order=['y', 'x'])
        MultiIndex([(3, 1),
                    (4, 2)],
                   names=['y', 'x'])
        csg|]}ˆ |¡‘qSrZrÛrr“rZr[r’    sz-MultiIndex.reorder_levels.<locals>.<listcomp>z2Length of order must be same as number of levels (z), got csg|]}ˆj|‘qSrZrÝrr“rZr[r’$    scsg|]}ˆj|‘qSrZrërr“rZr[r’%    scsg|]}ˆj|‘qSrZrƒrr“rZr[r’&    sFr})ryršr!rL)rXÚorderrßrˆr¢rZr“r[Úreorder_levelsþs ÿÿzMultiIndex.reorder_levelszlist[Categorical]csdd„‰‡fdd„|jDƒS)a
 
        we are categorizing our codes by using the
        available categories (all, not just observed)
        excluding any missing ones (-1); this is in preparation
        for sorting, where we need to disambiguate that -1 is not
        a valid valid
        cSs*tjt|ƒrt |¡ ¡dnd|jdS)NrOrr®)rTriryr¦r–r†)rœrZrZr[Úcats5    sþz/MultiIndex._get_codes_for_sorting.<locals>.catscs g|]}tj|ˆ|ƒdd‘qS)T)Zordered)r=Ú
from_codesrX©r¦rZr[r’;    sÿz5MultiIndex._get_codes_for_sorting.<locals>.<listcomp>rër“rZr¨r[r‡,    s    
þz!MultiIndex._get_codes_for_sortingrzbool | list[bool]z'tuple[MultiIndex, npt.NDArray[np.intp]])rŠÚ    ascendingÚsort_remainingric
sRt|ƒs|g}‡fdd„|Dƒ}d}t|tƒrbt|ƒt|ƒksFtdƒ‚t‡fdd„|Dƒ|d‰n¶tˆjƒ‰tˆjƒ‰t‡fdd„|Dƒƒ}t‡fd    d„|Dƒƒ}t    |d
d D]}ˆ 
|¡ˆ 
|¡q®|rî||tˆƒ7}||tˆƒ7}n|d }t ||d d‰|sˆddd…‰t ˆƒ‰‡fdd„ˆjDƒ}t |ˆjˆj|d d}    |    ˆfS)aÙ
        Sort MultiIndex at the requested level.
 
        The result will respect the original ordering of the associated
        factor at that level.
 
        Parameters
        ----------
        level : list-like, int or str, default 0
            If a string is given, must be a name of the level.
            If list-like must be names or ints of levels.
        ascending : bool, default True
            False to sort in descending order.
            Can also be a list to specify a directed ordering.
        sort_remaining : sort by the remaining levels after level
 
        Returns
        -------
        sorted_index : pd.MultiIndex
            Resulting index.
        indexer : np.ndarray[np.intp]
            Indices of output values in original index.
 
        Examples
        --------
        >>> mi = pd.MultiIndex.from_arrays([[0, 0], [2, 1]])
        >>> mi
        MultiIndex([(0, 2),
                    (0, 1)],
                   )
 
        >>> mi.sortlevel()
        (MultiIndex([(0, 1),
                    (0, 2)],
                   ), array([1, 0]))
 
        >>> mi.sortlevel(sort_remaining=False)
        (MultiIndex([(0, 2),
                    (0, 1)],
                   ), array([0, 1]))
 
        >>> mi.sortlevel(1)
        (MultiIndex([(0, 1),
                    (0, 2)],
                   ), array([1, 0]))
 
        >>> mi.sortlevel(1, ascending=False)
        (MultiIndex([(0, 2),
                    (0, 1)],
                   ), array([0, 1]))
        csg|]}ˆ |¡‘qSrZrÛrÙr“rZr[r’}    sz(MultiIndex.sortlevel.<locals>.<listcomp>Nz(level must have same length as ascendingcsg|]}ˆj|‘qSrZrërÙr“rZr[r’ˆ    s)Zordersc3s|]}ˆ|VqdSr©rZrÙrërZr[r­‘    sz'MultiIndex.sortlevel.<locals>.<genexpr>c3s|]}ˆ|VqdSr©rZrÙ)rRrZr[r­’    sT©ÚreverserF)ÚcompressrŒcsg|]}| ˆ¡‘qSrZryrXrYrZr[r’¦    s)rYr…rkrtrw)r2rªr‰ryrzrGrYrèr«ÚsortedrmrFr,rLr…rk)
rXrŠr©rªrtZprimaryZprimshprÚrˆrûrZ)rYrZrXrRr[Ú    sortlevel@    sJ9
ÿ
ÿ
 
 
 ûzMultiIndex.sortlevel)Úpreserve_namescCsht|tƒsX|dkr|}n@|dk ¡r0| |¡}n(zt |¡}Wntk
rV|YSX| ||¡}|SrÑ)rªrLr°r"r¸rlÚ_maybe_preserve_names)rXrˆrZr°rZrZr[Ú_wrap_reindex_result²    s
 
 zMultiIndex._wrap_reindex_result)rˆr°ricCs4|r0|j|jkr0|j|jkr0|jdd}|j|_|S)NFr÷)ršrkrv)rXrˆr°rZrZr[r±    sÿ
þ
ý z MultiIndex._maybe_preserve_namescCst|ƒrt|ƒrt|ƒ‚dSr©)r/r1r#rrZrZr[Ú_check_indexing_errorÏ    sz MultiIndex._check_indexing_errorcCs |jdjS)zA
        Should integer key(s) be treated as positional?
        r)r…Ú_should_fallback_to_positionalr“rZrZr[r´Ö    sz)MultiIndex._should_fallback_to_positionalz"tuple[Index, npt.NDArray[np.intp]])Ú    axis_namerics`|}t|tƒst |¡}t|ƒrRt|dtƒsR| |¡}| |||¡|||fStƒ     ||¡SrÑ)
rªr?r²r³ryr«Ú_get_indexer_level_0Ú_raise_if_missingÚsuperÚ_get_indexer_strict)rXrþrµÚkeyarrrZ©Ú    __class__rZr[r¹Þ    s
 
 
 zMultiIndex._get_indexer_strictcs”|}t|tƒst |¡}t|ƒr€t|dtƒs€|dk}| ¡r|jd |¡}|dk}| ¡rpt    ||›dƒ‚t    |›dƒ‚nt
ƒ  |||¡SdS)NrrŒz  not in index) rªr?r²r³ryr«rr…rrBr¸r·)rXrþrZrµrºr#ÚcheckZcmaskr»rZr[r·í    s
 
zMultiIndex._raise_if_missingcCs4|jd}|jd}tj||d}t|ƒ}| |¡S)z]
        Optimized equivalent to `self.get_level_values(0).get_indexer_for(target)`.
        r)rYÚ
categories)r…r‚r=r§r?Úget_indexer_for)rXrˆrÚrYÚcatÚcirZrZr[r¶
s
 
 
zMultiIndex._get_indexer_level_0zHashable | Sequence[Hashable]zLiteral[('left', 'right')])r‚ÚsidericCst|tƒs|f}|j||dS)a¼
        For an ordered MultiIndex, compute slice bound
        that corresponds to given label.
 
        Returns leftmost (one-past-the-rightmost if `side=='right') position
        of given label.
 
        Parameters
        ----------
        label : object or tuple of objects
        side : {'left', 'right'}
 
        Returns
        -------
        int
            Index of label.
 
        Notes
        -----
        This method only works if level 0 index of the MultiIndex is lexsorted.
 
        Examples
        --------
        >>> mi = pd.MultiIndex.from_arrays([list('abbc'), list('gefd')])
 
        Get the locations from the leftmost 'b' in the first level
        until the end of the multiindex:
 
        >>> mi.get_slice_bound('b', side="left")
        1
 
        Like above, but if you get the locations from the rightmost
        'b' in the first level and 'f' in the second level:
 
        >>> mi.get_slice_bound(('b','f'), side="right")
        3
 
        See Also
        --------
        MultiIndex.get_loc : Get location for a label or a tuple of labels.
        MultiIndex.get_locs : Get location for a label/slice/list/mask or a
                              sequence of such.
        ©rÂ)rªr«Ú_partial_tup_index)rXr‚rÂrZrZr[Úget_slice_bound
s0
zMultiIndex.get_slice_boundztuple[int, int]cstƒ |||¡S)aL
        For an ordered MultiIndex, compute the slice locations for input
        labels.
 
        The input labels can be tuples representing partial levels, e.g. for a
        MultiIndex with 3 levels, you can pass a single value (corresponding to
        the first level), or a 1-, 2-, or 3-tuple.
 
        Parameters
        ----------
        start : label or tuple, default None
            If None, defaults to the beginning
        end : label or tuple
            If None, defaults to the end
        step : int or None
            Slice step
 
        Returns
        -------
        (start, end) : (int, int)
 
        Notes
        -----
        This method only works if the MultiIndex is properly lexsorted. So,
        if only the first 2 levels of a 3-level MultiIndex are lexsorted,
        you can only pass two levels to ``.slice_locs``.
 
        Examples
        --------
        >>> mi = pd.MultiIndex.from_arrays([list('abbd'), list('deff')],
        ...                                names=['A', 'B'])
 
        Get the slice locations from the beginning of 'b' in the first level
        until the end of the multiindex:
 
        >>> mi.slice_locs(start='b')
        (1, 4)
 
        Like above, but stop at the end of 'b' in the first level and 'f' in
        the second level:
 
        >>> mi.slice_locs(start='b', end=('b', 'f'))
        (1, 3)
 
        See Also
        --------
        MultiIndex.get_loc : Get location for a label or a tuple of labels.
        MultiIndex.get_locs : Get location for a label/slice/list/mask or a
                              sequence of such.
        )r¸Ú
slice_locs)rXr2Úendrrr»rZr[rÆ@
s5zMultiIndex.slice_locsÚleftr«)rrÂc CsÎt|ƒ|jkr*tdt|ƒ›d|j›dƒ‚t|ƒ}dt|ƒ}}t||j|jƒ}t|ƒD]n\}\}}    }
|
||…} ||    krt|ƒsztj    |    ||d} Wn2t
k
rÎ} zt
d|›ƒ| ‚W5d} ~ XYnXt | ƒsæt
d|›ƒ‚|dkr| dkr| d8} |tj    | | |dS|  |    |¡}t |tƒrN||dkrN|j}|j}qX||dkr†|tj    | |dd}|tj    | |d    d}qXt |tƒr°|j}|tj    | ||dS|tj    | ||dSqXdS)
Nú Key length (z-) was greater than MultiIndex lexsort depth (ú)rrÃzLevel type mismatch: ÚrightrOrÈ)ryr™r%r•r…rYr”r;rÚ searchsortedrlr0Ú_get_loc_single_level_indexrªrqr2r”)rXrrÂÚnr2rÇZzippedr…rzrÚrœÚsectionr™rDrårZrZr[rÄw
sLÿ " ÿÿ
 zMultiIndex._partial_tup_indexr )Ú level_indexrþricCs"t|ƒrt|ƒrdS| |¡SdS)a‹
        If key is NA value, location of index unify as -1.
 
        Parameters
        ----------
        level_index: Index
        key : label
 
        Returns
        -------
        loc : int
            If key is NA value, loc is -1
            Else, location of key in index.
 
        See Also
        --------
        Index.get_loc : The get_loc method for (single-level) index.
        rŒN)r4r;r)rXrÐrþrZrZr[rÍ©
sz&MultiIndex._get_loc_single_level_indexc
sðˆ |¡‡fdd„}t|tƒs6ˆj|dd}||ƒSt|ƒ}ˆj|kr`td|›dˆj›dƒ‚|ˆjkr²ˆjr²zˆj     |¡WSt
k
r°ˆ  |t t ˆjƒƒ¡\}}|YSXˆj}|d|…||d…}}|säd}    tˆƒ}
nDzˆ ||¡\}    }
Wn.t
k
r&} zt|ƒ| ‚W5d} ~ XYnX|    |
kr:t|ƒ‚|sJt|    |
ƒStjd    ttƒd
tj|    |
tjd }t|t|ƒƒD]N\}} ˆj||ˆ ˆj|| ¡k} |  ¡s¶|| }t|ƒs|t|ƒ‚q|t|ƒ|
|    kræ||ƒSt|    |
ƒS) aÌ
        Get location for a label or a tuple of labels.
 
        The location is returned as an integer/slice or boolean
        mask.
 
        Parameters
        ----------
        key : label or tuple of labels (one for each level)
 
        Returns
        -------
        int, slice object or boolean mask
            If the key is past the lexsort depth, the return may be a
            boolean mask array, otherwise it is always a slice or int.
 
        See Also
        --------
        Index.get_loc : The get_loc method for (single-level) index.
        MultiIndex.slice_locs : Get slice location given start label(s) and
                                end label(s).
        MultiIndex.get_locs : Get location for a label/slice/list/mask or a
                              sequence of such.
 
        Notes
        -----
        The key cannot be a slice, list of same-level labels, a boolean mask,
        or a sequence of such. If you want to use those, use
        :meth:`MultiIndex.get_locs` instead.
 
        Examples
        --------
        >>> mi = pd.MultiIndex.from_arrays([list('abb'), list('def')])
 
        >>> mi.get_loc('b')
        slice(1, 3, None)
 
        >>> mi.get_loc(('b', 'e'))
        1
        csbt|tjƒr|jtjkr|St |tˆƒ¡}t|tƒr:|Stj    tˆƒdd}| 
d¡d||<|S)z<convert integer indexer to boolean mask or slice if possiblerur®FT) rªrTr´r†r‹rZmaybe_indices_to_sliceryrqÚemptyÚfill)r™r#r“rZr[Ú_maybe_to_sliceí
s
 
z+MultiIndex.get_loc.<locals>._maybe_to_slicerrrÉz) exceeds index depth (rÊNz3indexing past lexsort depth may impact performance.rr®)r³rªr«Ú_get_level_indexerryršrBr˜rórrlÚ get_loc_levelr‰r¢r™rÆrqr•r–r$r)rTrir‹r”rYrÍr…r°)rXrþrÓr™ZkeylenÚ_r›Zlead_keyZ
follow_keyr2r”rDr…r#rZr“r[rÂ
sZ)
 
 
ÿ
 
 
 
ýÿ
 
 zMultiIndex.get_loc)rŠÚ
drop_levelcsnt|ttfƒsˆ |¡}n‡fdd„|Dƒ}ˆj||d\}}|sft |¡r^ˆ||d…}nˆ|}||fS)a
        Get location and sliced index for requested label(s)/level(s).
 
        Parameters
        ----------
        key : label or sequence of labels
        level : int/level name or list thereof, optional
        drop_level : bool, default True
            If ``False``, the resulting index will not drop any level.
 
        Returns
        -------
        tuple
            A 2-tuple where the elements :
 
            Element 0: int, slice object or boolean array.
 
            Element 1: The resulting sliced multiindex/index. If the key
            contains all levels, this will be ``None``.
 
        See Also
        --------
        MultiIndex.get_loc  : Get location for a label or a tuple of labels.
        MultiIndex.get_locs : Get location for a label/slice/list/mask or a
                              sequence of such.
 
        Examples
        --------
        >>> mi = pd.MultiIndex.from_arrays([list('abb'), list('def')],
        ...                                names=['A', 'B'])
 
        >>> mi.get_loc_level('b')
        (slice(1, 3, None), Index(['e', 'f'], dtype='object', name='B'))
 
        >>> mi.get_loc_level('e', level='B')
        (array([False,  True, False]), Index(['b'], dtype='object', name='A'))
 
        >>> mi.get_loc_level(['b', 'e'])
        (1, None)
        csg|]}ˆ |¡‘qSrZrÛrÙr“rZr[r’f sz,MultiIndex.get_loc_level.<locals>.<listcomp>rrO)rªr‰r«rÜÚ_get_loc_levelrr0)rXrþrŠr×r™r$rZr“r[rÕ: s) 
zMultiIndex.get_loc_levelzint | list[int]rc
sЇfdd„}t|ttfƒrÌtˆƒt|ƒkr2tdƒ‚d}t|ˆƒD]V\}}ˆj||d\}}t|tƒr‚tj    tˆƒt
d}    d|    |<|    }|dkrŽ|n||@}q@z|||ƒ}
Wnt k
rˆ|}
YnX||
fStˆtƒrÞtˆƒ‰tˆtƒrF|dkrFz8ˆˆj dkr*ˆj ˆ|d} || dgƒ}| |fWSWnttfk
rFYnXtd    d
„ˆDƒƒsNtˆƒˆjkrʈjrÊzˆj ˆ¡dfWStk
r´} ztˆƒ| ‚W5d} ~ XYntk
rÈYnXˆ ˆ¡} ‡fd d „ttˆƒƒDƒ} t| ƒˆjkr@t| ƒr| dfS‡‡fd d „ttˆƒƒDƒ} t| ƒˆjkr@g} | || | ƒfSd} tˆƒD]¬\}}t|tƒs̈j ||d}t|tƒrÆt |¡sZt |tˆƒ¡rªqZtj    tˆƒt
d}d||<n|}n t |¡rސqZntdˆ›ƒ‚| dkrü|} n| |M} qZ| dkrtddƒ} ‡fdd „ttˆƒƒDƒ} | || | ƒfSn†ˆj ˆ|d} tˆtƒr”ˆj |jr”ˆj | ˆ¡}t|ƒs”| ˆ| fSz|| |gƒ}Wnt k
rˆ| }YnX| |fSdS)zX
        get_loc_level but with `level` known to be positional, not name-based.
        cs*ˆ|}t|ddD]}| |g¡}q|S)z‚
            If level does not exist or all levels were dropped, the exception
            has to be handled outside.
            Tr«)r®Ú_drop_level_numbers)rZr…rûr›r“rZr[Úmaybe_mi_droplevelsv sz6MultiIndex._get_loc_level.<locals>.maybe_mi_droplevelsz:Key for location must have same length as number of levelsNrr®Trcss|]}t|tƒVqdSr©)rªrqr„rZrZr[r­© sz,MultiIndex._get_loc_level.<locals>.<genexpr>cs"g|]}ˆ|tddƒkr|‘qSr©©rqrrorZr[r’· sz-MultiIndex._get_loc_level.<locals>.<listcomp>cs<g|]4}tˆ|tƒr"ˆj|jsˆ|tddƒkr|‘qSr©)rªrr…Ú!_supports_partial_string_indexingrqr©rþrXrZr[r’À s
 úz'Expected label or tuple of labels, got cs"g|]}ˆ|tddƒkr|‘qSr©rÛrrorZr[r’ð s)rªr«r‰ryr!r•rØrqrTr±rurzr…rÔrlr#rršr˜rórrBr¢r0r”r²Ú is_null_sliceZ is_full_slicerrÜ)rXrþrŠrÚr‡rÚr…r™rûr#r$rZrDZilevelsr›Z    loc_levelZk_indexr½Z result_indexrZrÝr[rØp s¨ ÿ
 
 
 
 
þ      ÿ
 
 
 
ÿ
þ
 zMultiIndex._get_loc_levelznpt.NDArray[np.bool_] | None©rŠrZcCsz|j|}|j|}||fdd„}t|tƒr˜|j}|dk    oB|dk}zt|jdk    r^| |j¡}    n|rpt|ƒd}    nd}    |jdk    rŒ| |j¡}
n*|r–d}
n t|    tƒrªt|ƒ}
n t|ƒd}
Wn2t    k
rê| 
|j|j|j¡}    }
|    j}YnXt|    tƒst|
tƒr(t |    d|    ƒ}    t |
d|
ƒ}
||    |
|ƒS|dksH|j dksH|dk    rj|rV|
dn|
d}
||    |
|ƒSt j||    dd} t j||
d    d} t| | |ƒSnÞ| ||¡} |dksº|j dkrt| tƒrÞ|| jk|| jk@}|Stj|| ktd
d }| ¡st    |ƒ‚|St| tƒr:t j|| jdd}    t j|| jdd}n t j|| dd}    t j|| d    d}|    |krlt    |ƒ‚t|    |ƒSdS) NcSsr|dk    r||}|dks |dkr2||k||k@}n tj||||jd}t ||¡}|dkr^|S| ¡}|||<|S)NrOr®)rTrir†rrŸrv)r2r”rrrZrYÚ new_indexerÚrrZrZr[Úconvert_indexer s z6MultiIndex._get_level_indexer.<locals>.convert_indexerrrOr2r”rÈrÃrËF)r†rv)r…rYrªrqrrr2rryr”rBZ slice_indexerrŸr™rrÌrÍrTr¦rur)rXrþrŠrZrÐrœrârrZis_negative_stepr2r”r›r¡råZlocsrÇrZrZr[rÔ sb
 
 
 
 
 
        
 
zMultiIndex._get_level_indexerc s:dd„tt |¡ƒDƒ}|r@|d|jkr@td|›d|j›ƒ‚tdd„|DƒƒrZtdƒ‚t|ƒ‰d    d
œ‡fd d „ }d }t|ƒD]„\}}d }t |¡rºt|ƒˆkr¬t    dƒ‚t
  |¡}nt |ƒr~z|j |||d}Wn„tttfk
r\}z^|D]T}    t|    ƒs|‚|j |    ||d}
|d kr,||
ƒ}qöt|
tƒrBd||
<qö||
O}qöW5d }~XYnX|d krÊt
jgt
jdSnLt |¡rº|d kr€|t|ƒdkr€t
jˆt
jdSq€n|j |||d}||ƒ}|d krâ|}q€||M}t
 |¡s€t
 |¡r€t|ƒ‚q€|d kr"t
jgt
jdS| ¡d} | || ¡S)a
        Get location for a sequence of labels.
 
        Parameters
        ----------
        seq : label, slice, list, mask or a sequence of such
           You should use one of the above for each level.
           If a level should not be used, set it to ``slice(None)``.
 
        Returns
        -------
        numpy.ndarray
            NumPy array of integers suitable for passing to iloc.
 
        See Also
        --------
        MultiIndex.get_loc : Get location for a label or a tuple of labels.
        MultiIndex.slice_locs : Get slice location given start label(s) and
                                end label(s).
 
        Examples
        --------
        >>> mi = pd.MultiIndex.from_arrays([list('abb'), list('def')])
 
        >>> mi.get_locs('b')  # doctest: +SKIP
        array([1, 2], dtype=int64)
 
        >>> mi.get_locs([slice(None), ['e', 'f']])  # doctest: +SKIP
        array([1, 2], dtype=int64)
 
        >>> mi.get_locs([[True, False, True], slice('e', 'f')])  # doctest: +SKIP
        array([2], dtype=int64)
        cSsg|]\}}|r|‘qSrZrZ)r‘r›ÚsrZrZr[r’š sz'MultiIndex.get_locs.<locals>.<listcomp>rŒzIMultiIndex slicing requires the index to be lexsorted: slicing on levels z, lexsort depth css|]}|tkVqdSr©)ÚEllipsisrçrZrZr[r­¡ sz&MultiIndex.get_locs.<locals>.<genexpr>z2MultiIndex does not support indexing with EllipsisrOrÂcs*t|tƒr&tjˆtjd}d||<|S|S)Nr®T)rªrqrTr±Úbool_)rZrà©rÎrZr[Ú_to_bool_indexer¨ s
 
z-MultiIndex.get_locs.<locals>._to_bool_indexerNzLcannot index with a boolean indexer that is not the same length as the indexrßTr®rOr)r”r²Zis_true_slicesr™r%rrTryrprzrTrµr2rÔr#rlrBr/rªrqr¦r‹rÞrir—Ú_reorder_indexer) rXÚseqZ true_slicesrçrZr›r…Z lvl_indexerrDrÔZ item_indexerZ pos_indexerrZrær[Úget_locsv sl$ÿÿ
 ÿ
 
ÿ
 
 
 
 
 
 
 zMultiIndex.get_locsz,tuple[Scalar | Iterable | AnyArrayLike, ...])rérZric CsDd}t|ƒD]¾\}}t |¡sÂt |¡sÂt|ƒr2nt|ƒrt|ƒdkrHqÂ| ¡rŠ|j|     |¡}||dk}|dd…|dd…k 
¡}qÂd}n2t |t ƒr¾| ¡r¸|j dk    o´|j dk}qÂd}nd}|r qÌq |sÔ|St|ƒ}d}t|ƒD]F\}}t|ƒr|g}t |¡r t |¡|}    nt|ƒržt |¡}tjt|j|ƒtjdt|j|ƒ}
|j|     |¡} | | dk} t t| ƒ¡|
| <|
|j||}    nˆt |t ƒrÜ|j dk    rÜ|j dkrÜt |¡ddd…|}    nJt |t ƒr|jdkr|jdkrtj|ftjd|}    nt |¡|}    |    f|}qèt |¡} || S)    am
        Reorder an indexer of a MultiIndex (self) so that the labels are in the
        same order as given in seq
 
        Parameters
        ----------
        seq : label/slice/list/mask or a sequence of such
        indexer: a position indexer of self
 
        Returns
        -------
        indexer : a sorted position indexer of self ordered as seq
        FrOrNrŒTrZr®)r”r²rÞrpr4r2ryrdr…rrrªrqrrrTrirr\ZonesrírYr2r”r‹rL) rXrérZZ    need_sortr›r…Zk_codesrÎÚkeysZ    new_orderZ key_order_mapZ level_indexerÚindrZrZr[rèû sZ  
 
 
 
ÿ $$ 
zMultiIndex._reorder_indexercs”|r|r||krtdƒ‚|jd ||¡\}}| ||¡\‰‰t|jƒ}|d||…|d<‡‡fdd„|jDƒ}|d||d<t|||jddS)aÓ
        Slice index between two labels / tuples, return new MultiIndex.
 
        Parameters
        ----------
        before : label or tuple, can be partial. Default None
            None defaults to start.
        after : label or tuple, can be partial. Default None
            None defaults to end.
 
        Returns
        -------
        MultiIndex
            The truncated MultiIndex.
 
        Examples
        --------
        >>> mi = pd.MultiIndex.from_arrays([['a', 'b', 'c'], ['x', 'y', 'z']])
        >>> mi
        MultiIndex([('a', 'x'), ('b', 'y'), ('c', 'z')],
                   )
        >>> mi.truncate(before='a', after='b')
        MultiIndex([('a', 'x'), ('b', 'y')],
                   )
        zafter < beforercsg|]}|ˆˆ…‘qSrZrZrX©rÈrËrZr[r’t sz'MultiIndex.truncate.<locals>.<listcomp>Fr})rzr…rÆr‰rYrLrs)rXZbeforeÚafterr›r¡rßrˆrZrír[ÚtruncateQ s
üzMultiIndex.truncatere)r†ric    CsV| |¡rdSt|tƒsdSt|ƒt|ƒkr0dSt|tƒsV| |¡sHdSt|j|jƒS|j|jkrfdSt    |jƒD]à}|j
|}|j
|}|dk}|dk}t   ||¡sªdS||}|j |j |¡}||}|j |j |¡}t|ƒdkrüt|ƒdkrüqpt|t jƒs| |¡sPdSqpt|t jƒs@| |¡sPdSqpt||ƒspdSqpdS)zØ
        Determines if two MultiIndex objects have the same labeling information
        (the levels themselves do not necessarily have to be the same)
 
        See Also
        --------
        equal_levels
        TFrŒr)Úis_rªr?ryrLZ_should_comparer:r¶ršr¢rYrTZ array_equalr…r"r´Úequals)    rXr†r›Z
self_codesZ other_codesZ    self_maskZ
other_maskZ self_valuesZ other_valuesrZrZr[rñ~ sD    
 
 
 
 
 
 
 
 
zMultiIndex.equalscCs@|j|jkrdSt|jƒD] }|j| |j|¡sdSqdS)zT
        Return True if the levels of both MultiIndex objects are the same
 
        FT)ršr¢r…rñ)rXr†r›rZrZr[Ú equal_levels¼ s  zMultiIndex.equal_levelscs¾| |¡\}}|jrDtƒ ||¡}t|tƒr0|Stjt|Žd|dS|j|dd}t    |ƒrf| 
|¡}n
|  |¡}|dk    r¶z |  ¡}Wn0t k
r´|dkrž‚tjdttƒdYnX|SdS)Nr¯F©rQTzTThe values in the array are unorderable. Pass `sort=False` to suppress this warning.r)Ú_convert_can_do_setopZhas_duplicatesr¸Ú_unionrªrLr§r•Ú
differenceryrÉÚ_get_reconciled_name_objectZ sort_valuesrlr•r–ÚRuntimeWarningr))rXr†rQÚ result_namesr‡Z right_missingr»rZr[rõÌ s4
ÿ 
 ü zMultiIndex._unionr)r†ricCst|ƒSr©)r3rürZrZr[Ú_is_comparable_dtypeî szMultiIndex._is_comparable_dtypecCs"| |¡}|j|kr| |¡S|S)z¡
        If the result of a set operation will be self,
        return self, unless the names change, in which
        case make a shallow copy of self.
        )Ú_maybe_match_namesrkÚrename)rXr†rkrZrZr[r÷ñ s
 
 
z&MultiIndex._get_reconciled_name_objectcCsbt|jƒt|jƒkr$dgt|jƒSg}t|j|jƒD]&\}}||krR| |¡q6| d¡q6|S)zë
        Try to find common names to attach to the result of an operation between
        a and b. Return a consensus list of names if they match at least partly
        or list of None if they have completely different names.
        N)ryrkr•rÉ)rXr†rkZa_nameZb_namerZrZr[rûý s  zMultiIndex._maybe_match_namescCs| |¡\}}| |¡Sr©)rôÚ    set_names©rXr†r‡rÖrùrZrZr[Ú_wrap_intersection_resultsz$MultiIndex._wrap_intersection_result)r‡ricCs6| |¡\}}t|ƒdkr(| ¡ |¡S| |¡SdSrÑ)rôryrkrýrþrZrZr[Ú_wrap_difference_results z"MultiIndex._wrap_difference_resultc
CsŒ|j}t|tƒszt|ƒdkr.|dd…|jfSd}ztj||jd}Wq„ttfk
rv}zt|ƒ|‚W5d}~XYq„Xn
t||ƒ}||fS)Nrz.other must be a MultiIndex or a list of tuplesrƒ)    rkrªr?ryrLr¸rzrlrB)rXr†rùršrDrZrZr[rôs
 
z MultiIndex._convert_can_do_setoprÃcCs@t|ƒ}t|ƒrd}t|ƒ‚t|ƒs,tdƒ‚|dkr<| ¡S|S)Nz3> 1 ndim Categorical are not supported at this timezISetting a MultiIndex dtype to anything other than object is not supportedT)r5r-rTr3rlrØ)rXr†rvršrZrZr[rf/sÿzMultiIndex.astypecCs^t|tƒr$|j|jkrtdƒ‚|jSt|tƒsD|fd|jd}nt|ƒ|jkrZtdƒ‚|S)Nz0Item must have length equal to number of levels.)r0rO)rªrLršrzr¶r«ry)rXÚitemrZrZr[Ú_validate_fill_value>s
 
zMultiIndex._validate_fill_value)rUricCsÂt||ƒ\}}|r| ¡St|ƒt|ƒkr8|| ¡}n| ¡}g}g}tt|j|j|jƒƒD]P\}\}}    }
|    j|dd} |      | 
|¡¡} t |
ƒ} | | |<|  | ¡|  | ¡q^t |||jddS)a
        Return a new MultiIndex of the values set with the mask.
 
        Parameters
        ----------
        mask : array like
        value : MultiIndex
            Must either be the same length as self or length one
 
        Returns
        -------
        MultiIndex
        Frór})r<rvryrkr”r•r…rYÚunionr¿r]r+rÉrLrk)rXr#rUZnoopZsubsetrßrˆr›Z value_levelrŠrœZ    new_levelZ value_codesZnew_coderZrZr[ÚputmaskLs.ÿ
 ÿzMultiIndex.putmask)r™ric    CsŠ| |¡}g}g}t||j|jƒD]T\}}}||krJt|ƒ}| ||¡}n
| |¡}| |¡| t t    |ƒ||¡¡q"t
|||j ddS)a
        Make new MultiIndex inserting new item at location
 
        Parameters
        ----------
        loc : int
        item : tuple
            Must be same length as number of levels in the MultiIndex
 
        Returns
        -------
        new_index : Index
        Fr}) rr•r…rYryÚinsertrrÉrTr+rLrk)    rXr™rrßrˆr…rŠrœZlev_locrZrZr[rts 
 
 
ÿzMultiIndex.insertcs(‡fdd„|jDƒ}t|j||jddS)z}
        Make new index with passed location deleted
 
        Returns
        -------
        new_index : MultiIndex
        csg|]}t |ˆ¡‘qSrZ)rTr˜rX©r™rZr[r’Ÿsz%MultiIndex.delete.<locals>.<listcomp>Fr})rYrLr…rk)rXr™rˆrZrr[r˜—süzMultiIndex.deletecCs¢t|tƒrt|ƒ}|dkrbt|ƒdkr<tjt|ƒftjdSt|tƒsPt |¡}|     ¡ 
|¡dkS|  |¡}|  |¡}|j dkr”tjt|ƒtjdS| |¡SdS)Nrr®rŒ)rªr
r‰ryrTr±rårLr¸r\r¿rÜr]rÓrŸ)rXrÊrŠÚnumZlevsrZrZr[rŸ§s
 
 
 
 
 
zMultiIndex.isinÚ__add__Ú__radd__Ú__iadd__Ú__sub__Ú__rsub__Ú__isub__Ú__pow__Ú__rpow__Ú__mul__Ú__rmul__Ú __floordiv__Ú __rfloordiv__Ú __truediv__Ú __rtruediv__Ú__mod__Ú__rmod__Ú
__divmod__Ú __rdivmod__Ú__neg__Ú__pos__Ú__abs__Ú
__invert__)NNNNNFNT)NN)NN)NN)NFN)N)N)F)F)NNNFr%NT)rN)NN)r)F)N)F)rTN)N)Nr)r)rœrŒ)rTT)NNN)rÈ)rT)r)rN)NN)T)N)šr]r^r_r`r?Z _hidden_attrsÚ    frozensetZ_typrsÚ__annotations__rCrÕr‚Z _comparablesr{rrÚ classmethodrr£r§rrr¸r¼rÀr'r¶ÚpropertyrÊr¦rÐrÒrÓr…r}ræršrèrYr~rìrórõr(rörØrvrýrêrr†r rrrrrr6r<rrkr@rÜrFrMr rZ _duplicatedrVr[rHr]r\rbrcrdr™rhrkrnrtrwr&r@Ú_index_doc_kwargsr"rÉrfr‰r›r’r£r¥r‡r¯r²r±r³r´r¹r·r¶rÅrÆrÄrÍrrÕrØrÔrêrèrïrñròrõrúr÷rûrÿrrôrfrrrr˜rŸrýrürDrr    r
r r r rrrrrrrrrrrrrrrrÚ __classcell__rZrZr»r[rLØsÀ
S  ÷/>üFüOü<A
    
ù+ÿ^
ù%A
!ü@     ÿ&øM:ý  4    ü\$ CX "û1ü<ÿ:.ür 
572 x6ÿq V->"   (#
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
zlist[np.ndarray]r€)rYršricCs>dd„|Dƒ}t|ddƒD]}t |d|…¡r|SqdS)zJCount depth (up to a maximum of `nlevels`) with which codes are lexsorted.cSsg|] }t|ƒ‘qSrZ)r+rXrZrZr[r’Üsz"_lexsort_depth.<locals>.<listcomp>rrŒN)r¢rIrJ)rYršZ int64_codesr…rZrZr[r™Ús
 
r™r0rer1c CsÊtt|Žƒ}t|ƒ}|d|d…}||}||dd…D]€}g}tt||ƒƒD]d\}    \}
} |    |dkr‚| | ¡| |¡q¸|
| kr–| |¡qR| ||    d…¡| |¡q¸qR|}q<tt|ŽƒS)NrO)r‰r•ryr”rÉr8) Z
label_listr2r3Zpivotedr…r‡ÚprevÚcurZ
sparse_curr›ÚpÚtrZrZr[r9ãs$  
 
 
r9rrÂcCs.t|ƒr|j›S|j}tjdtjdi |d¡S)NZNaTÚNaN)r.rrôrTZ
datetime64Z timedelta64Úgetr®rZrZr[r5ÿsr5r?)rric    Csr|}t|tƒrH|D]2}z| dg¡}Wqtk
rB|YSXqn&z| dg¡}Wntk
rlYnX|S)z¬
    Attempt to drop level or levels from the given index.
 
    Parameters
    ----------
    index: Index
    key : scalar or tuple
 
    Returns
    -------
    Index
    r)rªr«rÙrz)rrþZoriginal_indexrÖrZrZr[Úmaybe_droplevelss
r*FrurÁ)rvricCs"t||ƒ}|r| ¡}d|j_|S)a
    Coerce the array-like indexer to the smallest integer dtype that can encode all
    of the given categories.
 
    Parameters
    ----------
    array_like : array-like
    categories : array-like
    copy : bool
 
    Returns
    -------
    np.ndarray
        Non-writeable.
    F)r*rvrr )Z
array_liker¾rvrZrZr[ré)s
 
ré)ÚarrnamecCs”|dk    rZt|ƒsZt|ƒs&t|›dƒ‚t|ƒdkrLt|dƒrLt|›dƒ‚|g}|g}n2|dksjt|ƒrŒt|ƒr~t|dƒsŒt|›dƒ‚||fS)zT
    Ensure that level is either None or listlike, and arr is list-of-listlike.
    Nz must be list-likerz must be list of lists-like)r2rlry)rŠr r+rZrZr[rä@srä)rr0)F)‚Ú
__future__rÚ    functoolsrÚsysrÚtypingrrrr    r
r r r rrrrr•ÚnumpyrTZpandas._configrZ pandas._libsrrIrrarZpandas._libs.hashtablerZpandas._typingrrrrrrrrrr r!Zpandas.compat.numpyr"r~Z pandas.errorsr#r$r%Zpandas.util._decoratorsr&r'r(Zpandas.util._exceptionsr)Zpandas.core.dtypes.castr*Zpandas.core.dtypes.commonr+r,r-r.r/r0r1r2r3r4r5Zpandas.core.dtypes.dtypesr6Zpandas.core.dtypes.genericr7r8r9Zpandas.core.dtypes.missingr:r;Zpandas.core.algorithmsÚcoreZ
algorithmsZpandas.core.array_algos.putmaskr<Zpandas.core.arraysr=Zpandas.core.arrays.categoricalr>Zpandas.core.commonÚcommonr²Zpandas.core.indexes.baseZindexesÚbaserlr?r@rArBZpandas.core.indexes.frozenrCZpandas.core.ops.invalidrDZpandas.core.sortingrErFrGZpandas.io.formats.printingrHrÏrIrJrKÚdictr"ÚupdateZBaseMultiIndexCodesEnginerbrNrgrdrrrLr™r9r5r*rérärZrZrZr[Ú<module>s’   8  4   4       
ÿ')        !