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
U
¬ý°dPkã@sîddlmZddlmZddlZddlmZmZmZm    Z    m
Z
m Z ddl Z ddl ZddlmZddlmZddlmZddlmZmZdd    lmZdd
lmZmZmZmZmZm Z dd l!m"Z"dd l#m$Z$m%Z%dd l&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1ddl2m3Z3ddl4m5Z5m6Z6ddl7m8Z8m9Z9m:Z:m;Z;ddl<m=Z>ddl?m@mAZBddlCmDZEmFZFddlGmHZHmIZImJZJmKZKddlLmMZMmNZNer ddlOmPZPmQZQe    dddZReSddƒZTdZUGdd„dƒZVeVƒZWGdd„dƒZXGdd„deƒZYe"eXjZƒGdd „d eYƒƒZ[e"eXj\ƒGd!d"„d"eYƒƒZ]Gd#d$„d$eƒZ^e"eXj_ƒGd%d&„d&e^ƒƒZ`e"eXjaƒGd'd(„d(e^ƒƒZbd)d*d+d,œd-d.„Zcd)d/d0d1œd2d3„Zdd4d5d6œd7d8„Zed9d:„Zfd;d<„Zgd=d>„Zhd?d@œdAdB„Zid?d@œdCdD„ZjdEd?dFœdGdH„ZkdId@œdJdK„ZldS)Lé)Ú annotations)ÚsuppressN)Ú TYPE_CHECKINGÚHashableÚSequenceÚTypeVarÚcastÚfinal)Úusing_copy_on_write)ÚNDFrameIndexerBase)Úitem_from_zerodim)ÚAxisÚAxisInt)ÚPYPY)ÚAbstractMethodErrorÚChainedAssignmentErrorÚ IndexingErrorÚInvalidIndexErrorÚLossySetitemErrorÚ_chained_assignment_msg)Údoc)Úcan_hold_elementÚ maybe_promote) Ú is_array_likeÚ is_bool_dtypeÚis_extension_array_dtypeÚ is_hashableÚ
is_integerÚ is_iteratorÚ is_list_likeÚis_numeric_dtypeÚis_object_dtypeÚ    is_scalarÚ is_sequence)Ú concat_compat)Ú ABCDataFrameÚ    ABCSeries)Úinfer_fill_valueÚis_valid_na_for_dtypeÚisnaÚna_value_for_dtype)Ú
algorithms)ÚarrayÚ extract_array)Úcheck_array_indexerÚis_list_like_indexerÚis_scalar_indexerÚlength_of_indexer)ÚIndexÚ
MultiIndex)Ú    DataFrameÚSeriesÚ_LocationIndexerTÚ_LocationIndexer)Úboundz(indexer may only contain one '...' entryc@seZdZdZdd„ZdS)Ú _IndexSlicea
    Create an object to more easily perform multi-index slicing.
 
    See Also
    --------
    MultiIndex.remove_unused_levels : New MultiIndex with no unused levels.
 
    Notes
    -----
    See :ref:`Defined Levels <advanced.shown_levels>`
    for further info on slicing a MultiIndex.
 
    Examples
    --------
    >>> midx = pd.MultiIndex.from_product([['A0','A1'], ['B0','B1','B2','B3']])
    >>> columns = ['foo', 'bar']
    >>> dfmi = pd.DataFrame(np.arange(16).reshape((len(midx), len(columns))),
    ...                     index=midx, columns=columns)
 
    Using the default slice command:
 
    >>> dfmi.loc[(slice(None), slice('B0', 'B1')), :]
               foo  bar
        A0 B0    0    1
           B1    2    3
        A1 B0    8    9
           B1   10   11
 
    Using the IndexSlice class for a more intuitive command:
 
    >>> idx = pd.IndexSlice
    >>> dfmi.loc[idx[:, 'B0':'B1'], :]
               foo  bar
        A0 B0    0    1
           B1    2    3
        A1 B0    8    9
           B1   10   11
    cCs|S©N©)ÚselfÚargr;r;úKd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/core/indexing.pyÚ __getitem__ˆsz_IndexSlice.__getitem__N)Ú__name__Ú
__module__Ú __qualname__Ú__doc__r?r;r;r;r>r9`s'r9c@sXeZdZdZeddœdd„ƒZeddœdd„ƒZed    dœd
d „ƒZed dœd d„ƒZdS)Ú IndexingMixinzH
    Mixin for adding .loc/.iloc/.at/.iat to Dataframes and Series.
    Ú _iLocIndexer©ÚreturncCs
td|ƒS)aÙ
        Purely integer-location based indexing for selection by position.
 
        ``.iloc[]`` is primarily integer position based (from ``0`` to
        ``length-1`` of the axis), but may also be used with a boolean
        array.
 
        Allowed inputs are:
 
        - An integer, e.g. ``5``.
        - A list or array of integers, e.g. ``[4, 3, 0]``.
        - A slice object with ints, e.g. ``1:7``.
        - A boolean array.
        - A ``callable`` function with one argument (the calling Series or
          DataFrame) and that returns valid output for indexing (one of the above).
          This is useful in method chains, when you don't have a reference to the
          calling object, but would like to base your selection on some value.
        - A tuple of row and column indexes. The tuple elements consist of one of the
          above inputs, e.g. ``(0, 1)``.
 
        ``.iloc`` will raise ``IndexError`` if a requested indexer is
        out-of-bounds, except *slice* indexers which allow out-of-bounds
        indexing (this conforms with python/numpy *slice* semantics).
 
        See more at :ref:`Selection by Position <indexing.integer>`.
 
        See Also
        --------
        DataFrame.iat : Fast integer location scalar accessor.
        DataFrame.loc : Purely label-location based indexer for selection by label.
        Series.iloc : Purely integer-location based indexing for
                       selection by position.
 
        Examples
        --------
        >>> mydict = [{'a': 1, 'b': 2, 'c': 3, 'd': 4},
        ...           {'a': 100, 'b': 200, 'c': 300, 'd': 400},
        ...           {'a': 1000, 'b': 2000, 'c': 3000, 'd': 4000 }]
        >>> df = pd.DataFrame(mydict)
        >>> df
              a     b     c     d
        0     1     2     3     4
        1   100   200   300   400
        2  1000  2000  3000  4000
 
        **Indexing just the rows**
 
        With a scalar integer.
 
        >>> type(df.iloc[0])
        <class 'pandas.core.series.Series'>
        >>> df.iloc[0]
        a    1
        b    2
        c    3
        d    4
        Name: 0, dtype: int64
 
        With a list of integers.
 
        >>> df.iloc[[0]]
           a  b  c  d
        0  1  2  3  4
        >>> type(df.iloc[[0]])
        <class 'pandas.core.frame.DataFrame'>
 
        >>> df.iloc[[0, 1]]
             a    b    c    d
        0    1    2    3    4
        1  100  200  300  400
 
        With a `slice` object.
 
        >>> df.iloc[:3]
              a     b     c     d
        0     1     2     3     4
        1   100   200   300   400
        2  1000  2000  3000  4000
 
        With a boolean mask the same length as the index.
 
        >>> df.iloc[[True, False, True]]
              a     b     c     d
        0     1     2     3     4
        2  1000  2000  3000  4000
 
        With a callable, useful in method chains. The `x` passed
        to the ``lambda`` is the DataFrame being sliced. This selects
        the rows whose index label even.
 
        >>> df.iloc[lambda x: x.index % 2 == 0]
              a     b     c     d
        0     1     2     3     4
        2  1000  2000  3000  4000
 
        **Indexing both axes**
 
        You can mix the indexer types for the index and columns. Use ``:`` to
        select the entire axis.
 
        With scalar integers.
 
        >>> df.iloc[0, 1]
        2
 
        With lists of integers.
 
        >>> df.iloc[[0, 2], [1, 3]]
              b     d
        0     2     4
        2  2000  4000
 
        With `slice` objects.
 
        >>> df.iloc[1:3, 0:3]
              a     b     c
        1   100   200   300
        2  1000  2000  3000
 
        With a boolean array whose length matches the columns.
 
        >>> df.iloc[:, [True, False, True, False]]
              a     c
        0     1     3
        1   100   300
        2  1000  3000
 
        With a callable function that expects the Series or DataFrame.
 
        >>> df.iloc[:, lambda df: [0, 2]]
              a     c
        0     1     3
        1   100   300
        2  1000  3000
        Úiloc)rE©r<r;r;r>rH”s
zIndexingMixin.ilocÚ _LocIndexercCs
td|ƒS)a„!
        Access a group of rows and columns by label(s) or a boolean array.
 
        ``.loc[]`` is primarily label based, but may also be used with a
        boolean array.
 
        Allowed inputs are:
 
        - A single label, e.g. ``5`` or ``'a'``, (note that ``5`` is
          interpreted as a *label* of the index, and **never** as an
          integer position along the index).
        - A list or array of labels, e.g. ``['a', 'b', 'c']``.
        - A slice object with labels, e.g. ``'a':'f'``.
 
          .. warning:: Note that contrary to usual python slices, **both** the
              start and the stop are included
 
        - A boolean array of the same length as the axis being sliced,
          e.g. ``[True, False, True]``.
        - An alignable boolean Series. The index of the key will be aligned before
          masking.
        - An alignable Index. The Index of the returned selection will be the input.
        - A ``callable`` function with one argument (the calling Series or
          DataFrame) and that returns valid output for indexing (one of the above)
 
        See more at :ref:`Selection by Label <indexing.label>`.
 
        Raises
        ------
        KeyError
            If any items are not found.
        IndexingError
            If an indexed key is passed and its index is unalignable to the frame index.
 
        See Also
        --------
        DataFrame.at : Access a single value for a row/column label pair.
        DataFrame.iloc : Access group of rows and columns by integer position(s).
        DataFrame.xs : Returns a cross-section (row(s) or column(s)) from the
            Series/DataFrame.
        Series.loc : Access group of values using labels.
 
        Examples
        --------
        **Getting values**
 
        >>> df = pd.DataFrame([[1, 2], [4, 5], [7, 8]],
        ...      index=['cobra', 'viper', 'sidewinder'],
        ...      columns=['max_speed', 'shield'])
        >>> df
                    max_speed  shield
        cobra               1       2
        viper               4       5
        sidewinder          7       8
 
        Single label. Note this returns the row as a Series.
 
        >>> df.loc['viper']
        max_speed    4
        shield       5
        Name: viper, dtype: int64
 
        List of labels. Note using ``[[]]`` returns a DataFrame.
 
        >>> df.loc[['viper', 'sidewinder']]
                    max_speed  shield
        viper               4       5
        sidewinder          7       8
 
        Single label for row and column
 
        >>> df.loc['cobra', 'shield']
        2
 
        Slice with labels for row and single label for column. As mentioned
        above, note that both the start and stop of the slice are included.
 
        >>> df.loc['cobra':'viper', 'max_speed']
        cobra    1
        viper    4
        Name: max_speed, dtype: int64
 
        Boolean list with the same length as the row axis
 
        >>> df.loc[[False, False, True]]
                    max_speed  shield
        sidewinder          7       8
 
        Alignable boolean Series:
 
        >>> df.loc[pd.Series([False, True, False],
        ...        index=['viper', 'sidewinder', 'cobra'])]
                    max_speed  shield
        sidewinder          7       8
 
        Index (same behavior as ``df.reindex``)
 
        >>> df.loc[pd.Index(["cobra", "viper"], name="foo")]
               max_speed  shield
        foo
        cobra          1       2
        viper          4       5
 
        Conditional that returns a boolean Series
 
        >>> df.loc[df['shield'] > 6]
                    max_speed  shield
        sidewinder          7       8
 
        Conditional that returns a boolean Series with column labels specified
 
        >>> df.loc[df['shield'] > 6, ['max_speed']]
                    max_speed
        sidewinder          7
 
        Callable that returns a boolean Series
 
        >>> df.loc[lambda df: df['shield'] == 8]
                    max_speed  shield
        sidewinder          7       8
 
        **Setting values**
 
        Set value for all items matching the list of labels
 
        >>> df.loc[['viper', 'sidewinder'], ['shield']] = 50
        >>> df
                    max_speed  shield
        cobra               1       2
        viper               4      50
        sidewinder          7      50
 
        Set value for an entire row
 
        >>> df.loc['cobra'] = 10
        >>> df
                    max_speed  shield
        cobra              10      10
        viper               4      50
        sidewinder          7      50
 
        Set value for an entire column
 
        >>> df.loc[:, 'max_speed'] = 30
        >>> df
                    max_speed  shield
        cobra              30      10
        viper              30      50
        sidewinder         30      50
 
        Set value for rows matching callable condition
 
        >>> df.loc[df['shield'] > 35] = 0
        >>> df
                    max_speed  shield
        cobra              30      10
        viper               0       0
        sidewinder          0       0
 
        **Getting values on a DataFrame with an index that has integer labels**
 
        Another example using integers for the index
 
        >>> df = pd.DataFrame([[1, 2], [4, 5], [7, 8]],
        ...      index=[7, 8, 9], columns=['max_speed', 'shield'])
        >>> df
           max_speed  shield
        7          1       2
        8          4       5
        9          7       8
 
        Slice with integer labels for rows. As mentioned above, note that both
        the start and stop of the slice are included.
 
        >>> df.loc[7:9]
           max_speed  shield
        7          1       2
        8          4       5
        9          7       8
 
        **Getting values with a MultiIndex**
 
        A number of examples using a DataFrame with a MultiIndex
 
        >>> tuples = [
        ...    ('cobra', 'mark i'), ('cobra', 'mark ii'),
        ...    ('sidewinder', 'mark i'), ('sidewinder', 'mark ii'),
        ...    ('viper', 'mark ii'), ('viper', 'mark iii')
        ... ]
        >>> index = pd.MultiIndex.from_tuples(tuples)
        >>> values = [[12, 2], [0, 4], [10, 20],
        ...         [1, 4], [7, 1], [16, 36]]
        >>> df = pd.DataFrame(values, columns=['max_speed', 'shield'], index=index)
        >>> df
                             max_speed  shield
        cobra      mark i           12       2
                   mark ii           0       4
        sidewinder mark i           10      20
                   mark ii           1       4
        viper      mark ii           7       1
                   mark iii         16      36
 
        Single label. Note this returns a DataFrame with a single index.
 
        >>> df.loc['cobra']
                 max_speed  shield
        mark i          12       2
        mark ii          0       4
 
        Single index tuple. Note this returns a Series.
 
        >>> df.loc[('cobra', 'mark ii')]
        max_speed    0
        shield       4
        Name: (cobra, mark ii), dtype: int64
 
        Single label for row and column. Similar to passing in a tuple, this
        returns a Series.
 
        >>> df.loc['cobra', 'mark i']
        max_speed    12
        shield        2
        Name: (cobra, mark i), dtype: int64
 
        Single tuple. Note using ``[[]]`` returns a DataFrame.
 
        >>> df.loc[[('cobra', 'mark ii')]]
                       max_speed  shield
        cobra mark ii          0       4
 
        Single tuple for the index with a single label for the column
 
        >>> df.loc[('cobra', 'mark i'), 'shield']
        2
 
        Slice from index tuple to single label
 
        >>> df.loc[('cobra', 'mark i'):'viper']
                             max_speed  shield
        cobra      mark i           12       2
                   mark ii           0       4
        sidewinder mark i           10      20
                   mark ii           1       4
        viper      mark ii           7       1
                   mark iii         16      36
 
        Slice from index tuple to index tuple
 
        >>> df.loc[('cobra', 'mark i'):('viper', 'mark ii')]
                            max_speed  shield
        cobra      mark i          12       2
                   mark ii          0       4
        sidewinder mark i          10      20
                   mark ii          1       4
        viper      mark ii          7       1
 
        Please see the :ref:`user guide<advanced.advanced_hierarchical>`
        for more details and explanations of advanced indexing.
        Úloc)rJrIr;r;r>rKszIndexingMixin.locÚ
_AtIndexercCs
td|ƒS)aŠ
        Access a single value for a row/column label pair.
 
        Similar to ``loc``, in that both provide label-based lookups. Use
        ``at`` if you only need to get or set a single value in a DataFrame
        or Series.
 
        Raises
        ------
        KeyError
            * If getting a value and 'label' does not exist in a DataFrame or
                Series.
        ValueError
            * If row/column label pair is not a tuple or if any label from
                the pair is not a scalar for DataFrame.
            * If label is list-like (*excluding* NamedTuple) for Series.
 
        See Also
        --------
        DataFrame.at : Access a single value for a row/column pair by label.
        DataFrame.iat : Access a single value for a row/column pair by integer
            position.
        DataFrame.loc : Access a group of rows and columns by label(s).
        DataFrame.iloc : Access a group of rows and columns by integer
            position(s).
        Series.at : Access a single value by label.
        Series.iat : Access a single value by integer position.
        Series.loc : Access a group of rows by label(s).
        Series.iloc : Access a group of rows by integer position(s).
 
        Notes
        -----
        See :ref:`Fast scalar value getting and setting <indexing.basics.get_value>`
        for more details.
 
        Examples
        --------
        >>> df = pd.DataFrame([[0, 2, 3], [0, 4, 1], [10, 20, 30]],
        ...                   index=[4, 5, 6], columns=['A', 'B', 'C'])
        >>> df
            A   B   C
        4   0   2   3
        5   0   4   1
        6  10  20  30
 
        Get value at specified row/column pair
 
        >>> df.at[4, 'B']
        2
 
        Set value at specified row/column pair
 
        >>> df.at[4, 'B'] = 10
        >>> df.at[4, 'B']
        10
 
        Get value within a Series
 
        >>> df.loc[5].at['B']
        4
        Úat)rLrIr;r;r>rM&s?zIndexingMixin.atÚ _iAtIndexercCs
td|ƒS)a†
        Access a single value for a row/column pair by integer position.
 
        Similar to ``iloc``, in that both provide integer-based lookups. Use
        ``iat`` if you only need to get or set a single value in a DataFrame
        or Series.
 
        Raises
        ------
        IndexError
            When integer position is out of bounds.
 
        See Also
        --------
        DataFrame.at : Access a single value for a row/column label pair.
        DataFrame.loc : Access a group of rows and columns by label(s).
        DataFrame.iloc : Access a group of rows and columns by integer position(s).
 
        Examples
        --------
        >>> df = pd.DataFrame([[0, 2, 3], [0, 4, 1], [10, 20, 30]],
        ...                   columns=['A', 'B', 'C'])
        >>> df
            A   B   C
        0   0   2   3
        1   0   4   1
        2  10  20  30
 
        Get value at specified row/column pair
 
        >>> df.iat[1, 2]
        1
 
        Set value at specified row/column pair
 
        >>> df.iat[1, 2] = 10
        >>> df.iat[1, 2]
        10
 
        Get value within a series
 
        >>> df.loc[0].iat[1]
        2
        Úiat)rNrIr;r;r>rOgs.zIndexingMixin.iatN)    r@rArBrCÚpropertyrHrKrMrOr;r;r;r>rDs @rDc@sˆeZdZUded<dZded<ded<ed>dd    dd
œd d „ƒZd d„Zedd„ƒZed?ddœdd„ƒZ    eddœdd„ƒZ
ddœdd„Z edddœdd„ƒZ edddœd d!„ƒZ edddœd"d#„ƒZedddœd$d%„ƒZedddœd&d'„ƒZedd(œd)d*„ƒZedd(œd+d,„ƒZedd(œd-d.„ƒZddœd/d0„Zed1d2„ƒZdd3œd4d5„Zdd(œd6d7„Zddœd8d9„Zddœd:d;„Zeddœd<d=„ƒZdS)@r7ÚstrÚ _valid_typesNzAxisInt | NoneÚaxisÚboolÚ    _takeabler6z Axis | None)r<rSrGcCs6t|ƒ|j|jƒ}|dk    r(|j |¡}n|}||_|Sr:)ÚtypeÚnameÚobjÚ_get_axis_numberrS)r<rSZnew_selfZ axis_int_noner;r;r>Ú__call__Ÿs z_LocationIndexer.__call__c
Csê|jdkr| |¡t|tƒr0|D] }t|ƒq"|jdk    rJt|j|j|ƒ}|j     d¡}t|t
ƒrš|jdkršt |ƒršt t tƒ| |¡W5QR£SQRXt|tƒrÊt tƒ| |¡W5QR£SQRXt|tƒrÜt|ƒ}|j|ddS)zR
        Convert a potentially-label-based key into a positional indexer.
        rKNrrH©rS)rWÚ_ensure_listlike_indexerÚ
isinstanceÚtupleÚcheck_dict_or_set_indexersrSÚ_tupleize_axis_indexerÚndimrXÚ    _get_axisr3rrÚKeyErrorrÚget_locrÚ_convert_tupleÚrangeÚlistÚ_convert_to_indexer)r<ÚkeyÚxÚaxr;r;r>Ú_get_setitem_indexer­s"
 
 
 
 
 
 
 
z%_LocationIndexer._get_setitem_indexercCsnt|tƒrNt|ƒdkrNt|ttfƒrN|\}}|j}t |¡rft|ƒt|ƒkrf| ¡d}t    ||jdƒr°|dkr°t|ƒdkr–|j
dd…}n|j j
  ||¡}||f}nœt|t jƒrf|jjdkrft|ƒdkrf|dkrü|j j
  ||¡}||f}nP|dkrf|jddkrft|ƒdkr4|j
dd…}n|j j
 ||¡}||f}nt |¡rf| ¡d}||fS)a
        If we have obj.iloc[mask] = series_or_frame and series_or_frame has the
        same length as obj, we treat this as obj.iloc[mask] = series_or_frame[mask],
        similar to Series.__setitem__.
 
        Note this is only for loc, not iloc.
        éréNÚi)r]r^Úlenr&r%raÚcomÚis_bool_indexerÚnonzeror0rHrXÚ _align_seriesÚnpÚndarrayÚdtypeÚkindÚshapeÚ _align_frame)r<ÚindexerÚvalueÚpiZicolsraZnewkeyr;r;r>Ú_maybe_mask_setitem_valueÎs@ ÿ
þ ý  
 
ÿ
þ
ý
 
  z*_LocationIndexer._maybe_mask_setitem_valueÚNonerFc
Cs&d}|jdkrdS|}t|tƒr8t|ƒdkr8||}|}||kr"t|jjtƒs"t|ƒr"t     |¡s"t
dd„|Dƒƒr"|jjj |dd}t |ƒj |jjdd}t|ƒr
t |d¡r
tjt|ƒtjd    }d
|t|jjƒd…<|jjj||dd d d }    |    |j_dS|jjj|dd d |j_dS)a 
        Ensure that a list-like of column labels are all present by adding them if
        they do not already exist.
 
        Parameters
        ----------
        key : list-like of column labels
            Target labels.
        axis : key axis if known
        rnrmNcss|]}t|ƒVqdSr:)r©Ú.0Úkr;r;r>Ú    <genexpr>'sz<_LocationIndexer._ensure_listlike_indexer.<locals>.<genexpr>F)Úsortr©rwéÿÿÿÿT)r{rSÚ
only_sliceZ use_na_proxy)rSr‡)rar]r^rprXÚcolumnsr3r/rqrrÚallÚunionr2Ú
differenceÚ is_null_sliceruÚarangeÚintpÚ_mgrZreindex_indexerZ reindex_axis)
r<rirSr|Z column_axisZorig_keyÚkeysZdiffr{Znew_mgrr;r;r>r\    s@ 
ÿ þýüûÿz)_LocationIndexer._ensure_listlike_indexercs²ts*tƒr*t ˆj¡dkr*tjttddt    |ƒt
|t ƒrft dd„|Dƒƒ}t ‡fdd„|Dƒƒ}nt   |ˆj¡}ˆ |¡}ˆ |¡ˆjdkr–ˆnˆjj}| ||ˆj¡dS)Nrm)Ú
stacklevelcss"|]}t|ƒrt|ƒn|VqdSr:©rrg©rrjr;r;r>rƒIsz/_LocationIndexer.__setitem__.<locals>.<genexpr>c3s|]}t |ˆj¡VqdSr:©rqÚapply_if_callablerXr“rIr;r>rƒJsrH)rr
ÚsysÚ getrefcountrXÚwarningsÚwarnrrr_r]r^rqr•rlÚ_has_valid_setitem_indexerrWrHÚ_setitem_with_indexer)r<rir|r{rHr;rIr>Ú __setitem__?s 
ÿ
 
 
z_LocationIndexer.__setitem__rr[cCs t|ƒ‚dS)aó
        Ensure that key is valid for current indexer.
 
        Parameters
        ----------
        key : scalar, slice or list-like
            Key requested.
        axis : int
            Dimension on which the indexing is being made.
 
        Raises
        ------
        TypeError
            If the key (or some element of it) has wrong type.
        IndexError
            If the key (or some element of it) is out of bounds.
        KeyError
            If the key was not found.
        N©r©r<rirSr;r;r>Ú _validate_keySsz_LocationIndexer._validate_keyr^©ÚtuprGcCsjtdd„|Dƒƒrf| t¡dkr(ttƒ‚t|ƒ|jkrf| t¡}|d|…tf||dd…}|S|S)zt
        If a tuple key includes an Ellipsis, replace it with an appropriate
        number of null slices.
        css|]}|tkVqdSr:)ÚEllipsisr“r;r;r>rƒosz4_LocationIndexer._expand_ellipsis.<locals>.<genexpr>rnN)    ÚanyÚcountr¢rÚ_one_ellipsis_messagerpraÚindexÚ_NS)r<r¡roÚnew_keyr;r;r>Ú_expand_ellipsisis
"z!_LocationIndexer._expand_ellipsis©rirGc Csr| |¡}| |¡}t|ƒD]P\}}z| ||¡Wqtk
rj}ztd|j›dƒ|‚W5d}~XYqXq|S)zA
        Check the key for valid keys across my indexer.
        z'Location based indexing can only have [z] typesN)Ú_validate_key_lengthr©Ú    enumeraterŸÚ
ValueErrorrR)r<riror‚Úerrr;r;r>Ú_validate_tuple_indexers
 
 ÿýz(_LocationIndexer._validate_tuple_indexercs4tdd„|jjDƒƒr0t‡fdd„|jjDƒƒSdS)ú6
        Returns
        -------
        bool
        css|]}t|tƒVqdSr:)r]r3©rrkr;r;r>rƒ—sz<_LocationIndexer._is_nested_tuple_indexer.<locals>.<genexpr>c3s|]}tˆ|ƒVqdSr:)Úis_nested_tupler±©r¡r;r>rƒ˜sF)r£rXÚaxes©r<r¡r;r³r>Ú_is_nested_tuple_indexersz)_LocationIndexer._is_nested_tuple_indexercs(ˆ |¡‡fdd„t|ƒDƒ}t|ƒS)Ncsg|]\}}ˆj||d‘qS)r[)rh)rror‚rIr;r>Ú
<listcomp>Ÿsz3_LocationIndexer._convert_tuple.<locals>.<listcomp>)r«r¬r^)r<riZkeyidxr;rIr>re›s
z_LocationIndexer._convert_tuplecCsLt|ƒ|jkrH|dtkr@|dd…}t|kr6ttƒ‚| |¡Stdƒ‚|S)NrrnúToo many indexers)rprar¢rr¥r«©r<rir;r;r>r«¢s  
z%_LocationIndexer._validate_key_lengthr³cCsd|j}t|ƒD]:\}}t |¡r"qt||jƒj||d}|j|jkst‚q||jkr`|j    dd}|S)z´
        Index with indexers that should return an object of the same dimension
        as self.obj.
 
        This is only called after a failed call to _getitem_lowerdim.
        r[F©Údeep)
rXr¬rqrŒÚgetattrrWÚ _getitem_axisraÚAssertionErrorÚcopy)r<r¡Úretvalrorir;r;r>Ú_getitem_tuple_same_dim®s
 
 z(_LocationIndexer._getitem_tuple_same_dimc
Cs`|jdk    r&|j |j¡}|j||dS| |¡r:| |¡S|j d¡}t|tƒr˜|j    dkr˜t
dd„|Dƒƒs˜t t ƒt t|ƒ |¡W5QR£SQRX| |¡}t|ƒD]¨\}}t|ƒrª|j||d}|j|jkrø|d|…tf||dd…}n2|d|…||dd…}t|ƒdkr*|d}t |¡r>|St||j    ƒ|Sqªt dƒ‚dS)Nr[rrHcss|]}t|tƒVqdSr:)r]Úslicer“r;r;r>rƒÙsz5_LocationIndexer._getitem_lowerdim.<locals>.<genexpr>rnznot applicable)rSrXrYr½r¶Ú_getitem_nested_tuplerbr]r3rWr£rrrrJÚ"_handle_lowerdim_multi_index_axis0r«r¬Ú is_label_likerar§rprqrŒr¼)r<r¡rSZax0roriÚsectionr¨r;r;r>Ú_getitem_lowerdimÇs6
 
 
 ÿþý    
"
 $ z"_LocationIndexer._getitem_lowerdimc
Cs&|D] }t|ƒqt|ƒ|jkr°|jdkr2tdƒ‚tdd„|Dƒƒrrttƒtt    |ƒ 
|¡W5QR£SQRXn&t |j t ƒr˜tdd„|Dƒƒr˜tdƒ‚|jp d}|j||dS|j }t|ƒd    }|ddd
…D]P}t |¡rè|d    8}qÐt||jƒj||d}|d    8}t|ƒst|d ƒsАq"qÐ|S) NrKzToo many indicescss |]}t|ƒpt |¡VqdSr:)rrqrŒr“r;r;r>rƒsz9_LocationIndexer._getitem_nested_tuple.<locals>.<genexpr>css|]}t|tƒVqdSr:©r]r^r€r;r;r>rƒsr¸rr[rnr†ra)r_rprarWr­r‰rrrrJrÄr]rXr&r£rSr½rqrŒr¼r"Úhasattr)r<r¡rirSrXr;r;r>rÃs6
 
 
 
ÿÿ
 
z&_LocationIndexer._getitem_nested_tuplecCs t|ƒ‚dSr:rržr;r;r>rh>sz$_LocationIndexer._convert_to_indexercsŽt|ƒt|ƒtkrdtdd„|Dƒƒ}t‡fdd„|Dƒƒ}ˆ |¡rZˆjj|dˆjiŽSˆ |¡Sˆjpld}t     
|ˆj¡}ˆj ||dSdS)Ncss"|]}t|ƒrt|ƒn|VqdSr:r’r“r;r;r>rƒEsz/_LocationIndexer.__getitem__.<locals>.<genexpr>c3s|]}t |ˆj¡VqdSr:r”r“rIr;r>rƒFsÚtakeablerr[) r_rVr^Ú_is_scalar_accessrXÚ
_get_valuerUÚ_getitem_tuplerSrqr•r½)r<rirSZmaybe_callabler;rIr>r?As 
 
 
z_LocationIndexer.__getitem__©ricCs
tƒ‚dSr:©ÚNotImplementedErrorr¹r;r;r>rËQsz"_LocationIndexer._is_scalar_accesscCs t|ƒ‚dSr:rrµr;r;r>rÍTsz_LocationIndexer._getitem_tuplecCs
tƒ‚dSr:rÏržr;r;r>r½Wsz_LocationIndexer._getitem_axiscCs t|ƒ‚dSr:r©r<r{r;r;r>ršZsz+_LocationIndexer._has_valid_setitem_indexercCs2|j |¡}t||ƒ}| ¡d}|jj||dS)Nrr[)rXrbÚcheck_bool_indexerrsÚ_take_with_is_copy)r<rirSÚlabelsZindsr;r;r>Ú _getbool_axis]s 
 z_LocationIndexer._getbool_axis)N)NN)r@rArBÚ__annotations__rSr    rZrlr~r\rœrŸr©r¯r¶rer«rÁrÇrÃrhr?rËrÍr½ršrÕr;r;r;r>r7˜sN
 ÿ !
:5
 <9
c@säeZdZUdZded<dZeejƒddœdd„ƒZdd    œd
d „Z    d dd œdd„Z
d ddœdd„Z d dœdd„Z ddœdd„Z d dœdd„Zddœdd„Zd dœdd„Zddœdd „Zd!dd"œd#d$„Zddœd%d&„Zddœd'd(„Zd)S)*rJFrTrUzšlabels (MUST BE IN THE INDEX), slices of labels (BOTH endpoints included! Can be slices of integers if the index is integers), listlike of labels, booleanr r[cCs„|j |¡}t|tƒrPt|ƒsP|jjdksPt|tƒrBt| d¡ƒsPt    |›dƒ‚t|t
ƒr€t|j tƒsrt|j tƒr€t |›dƒ‚dS)NÚbooleanrz7: boolean label can not be used without a boolean indexz+: boolean values can not be used in a slice)rXrbr]rTrrwrWr3Zget_level_valuesrcrÂÚstartÚstopÚ    TypeError)r<rirSrkr;r;r>rŸrs& 
ÿ
þý üÿ
 
ÿ
ÿz_LocIndexer._validate_keyrFcCsdS)NTr;rÑr;r;r>ršˆsz&_LocIndexer._has_valid_setitem_indexerr^rªcCstt|ƒ|jkrdSt|ƒD]T\}}t|ƒs0dS|jj|}t|tƒrLdSt|tƒrb|j    rbdS|j
sdSqdS)r°FT) rprar¬r"rXr´r]r3rQZ!_supports_partial_string_indexingZ_index_as_unique)r<riror‚rkr;r;r>rˋs
 
z_LocIndexer._is_scalar_accessr cCs*tdd„|DƒƒsdStdd„|Dƒƒ S)a§
        Check whether there is the possibility to use ``_multi_take``.
 
        Currently the limit is that all axes being indexed, must be indexed with
        list-likes.
 
        Parameters
        ----------
        tup : tuple
            Tuple of indexers, one per axis.
 
        Returns
        -------
        bool
            Whether the current indexing,
            can be passed through `_multi_take`.
        css|]}t|ƒVqdSr:)r/r“r;r;r>rƒ¿sz6_LocIndexer._multi_take_opportunity.<locals>.<genexpr>Fcss|]}t |¡VqdSr:)rqrrr“r;r;r>rƒÃs)r‰r£rµr;r;r>Ú_multi_take_opportunity­sz#_LocIndexer._multi_take_opportunityr³cs.‡fdd„t|ˆjjƒDƒ}ˆjj|dddS)a±
        Create the indexers for the passed tuple of keys, and
        executes the take operation. This allows the take operation to be
        executed all at once, rather than once for each dimension.
        Improving efficiency.
 
        Parameters
        ----------
        tup : tuple
            Tuple of indexers, one per axis.
 
        Returns
        -------
        values: same type as the object being indexed
        csi|]\}}|ˆ ||¡“qSr;)Ú_get_listlike_indexer)rrirSrIr;r>Ú
<dictcomp>Ösÿz+_LocIndexer._multi_take.<locals>.<dictcomp>T©r¿Ú
allow_dups)ÚziprXZ _AXIS_ORDERSÚ_reindex_with_indexers)r<r¡Údr;rIr>Ú _multi_takeÅs
 þz_LocIndexer._multi_takercCs6| ||¡| ||¡\}}|jj|||gidddS)aé
        Index current object with an iterable collection of keys.
 
        Parameters
        ----------
        key : iterable
            Targeted labels.
        axis : int
            Dimension on which the indexing is being made.
 
        Raises
        ------
        KeyError
            If no key was found. Will change in the future to raise if not all
            keys were found.
 
        Returns
        -------
        scalar, DataFrame, or Series: indexed value(s).
        TrÞ)rŸrÜrXrá)r<rirSÚkeyarrr{r;r;r>Ú_getitem_iterableÞs 
ÿz_LocIndexer._getitem_iterablec
CsXttƒ"| |¡}| |¡W5QR£SQRX| |¡}| |¡rN| |¡S| |¡Sr:)rrr©rÇr¯rÛrãrÁrµr;r;r>rÍýs
 
 
 
 
z_LocIndexer._getitem_tuplecCs|jj||dS)Nr[)rXÚxs)r<ÚlabelrSr;r;r>Ú
_get_label sz_LocIndexer._get_labelc
Cst|jpd}z|j||dWStk
rn}z6|jt|ƒkrL|jjjkrTnn|‚tdƒ|‚W5d}~XYnXdS)Nrr[zNo label returned)    rSrèrcrarprXr¦Únlevelsr)r<r¡rSZekr;r;r>rÄs
$z._LocIndexer._handle_lowerdim_multi_index_axis0cCs,t|ƒ}t|ƒrt|ƒ}|tkr(tdƒ}|j |¡}t|tƒrPt|t    ƒrPt|ƒ}t|tƒrt| 
||¡|j ||dSt   |¡rŒ|j||dSt|ƒrt|tƒrªt|t    ƒsÔt|dƒrÆ|jdkrÆtdƒ‚|j||dSt||ƒr| |¡}tdƒg|j}|||<|jjt|ƒS| 
||¡|j||dS)Nr[rarnz&Cannot index with multidimensional key)r rrgr¢rÂrXrbr]r^r3rŸÚ_get_slice_axisrqrrrÕr/rÉrar­rår²Úget_locsrHrè)r<rirSrÔZlocsr{r;r;r>r½s2 
 
 
 
 z_LocIndexer._getitem_axisr©Ú    slice_objrScCsf|j}t|ƒs|jddS| |¡}| |j|j|j¡}t|t    ƒrR|jj
||dS|jj ||dSdS)zL
        This is pretty simple as we just have to deal with labels.
        Frºr[N) rXÚ
need_slicer¿rbZ slice_indexerrØrÙÚstepr]rÂÚ_sliceÚtake)r<rírSrXrÔr{r;r;r>rêAs 
 
z_LocIndexer._get_slice_axiscCsÒ|j |¡}t|tƒr$|j|ddSt|tƒrVt|tƒsV|jdkrVt|ƒdkrVt    dƒ‚t
|ƒstt|tƒr t |ƒr z |  |¡WSt k
rÄt|tƒrÀt|tƒrÀt|ƒ|jkr¾d|iYS‚YnHtk
rât|tƒsނYn*tk
r
t|ƒsþ‚d|iYSXt||ƒrJ|jdkr@tdd„|Dƒƒr@t    dƒ‚| |¡St|ƒr’t|ƒrft|ƒ}t |¡r€t||ƒ}|S| ||¡dSn<z |  |¡WSt k
rÌt|ƒsÆd|iYS‚YnXd    S)
aÑ
        Convert indexing key into something we can use to do actual fancy
        indexing on a ndarray.
 
        Examples
        ix[:5] -> slice(0, 5)
        ix[[1,2,3]] -> [1,2,3]
        ix[['foo', 'bar', 'baz']] -> [i, j, k] (indices of foo, bar, baz)
 
        Going by Zen of Python?
        'In the face of ambiguity, refuse the temptation to guess.'
        raise AmbiguousIndexError with integer labels?
        - No, prefer label-based indexing
        rK)rxrmrnr¸ricss|]}t|tƒVqdSr:rÈr€r;r;r>rƒ…sz2_LocIndexer._convert_to_indexer.<locals>.<genexpr>N)rXrbr]rÂZ_convert_slice_indexerr^r3rarprr"rrdÚ LookupErrorrérr­rr²r£rër/rrgrqrrrÒrÜ)r<rirSrÔr;r;r>rhTsX 
ÿþý
ü  
 
  
 
 
 
 
 z_LocIndexer._convert_to_indexercCs0|j |¡}|j |¡}| ||¡\}}||fS)aJ
        Transform a list-like of keys into a new index and an indexer.
 
        Parameters
        ----------
        key : list-like
            Targeted labels.
        axis:  int
            Dimension on which the indexing is being made.
 
        Raises
        ------
        KeyError
            If at least one key was requested but none was found.
 
        Returns
        -------
        keyarr: Index
            New index (coinciding with 'key' if the axis is unique).
        values : array-like
            Indexer for the return object, -1 denotes keys not found.
        )rXrbZ_get_axis_nameZ_get_indexer_strict)r<rirSrkZ    axis_namerär{r;r;r>rܜs  z!_LocIndexer._get_listlike_indexerN)r@rArBrUrÖrRrr7rŸršrËrÛrãrårÍrèrÄr½rêrhrÜr;r;r;r>rJfs"
 ÿ    "$HrJc@s*eZdZdZdZddœdd„Zddœd    d
„Zd dd œd d„Zddddœdd„Zd dœdd„Z    ddœdd„Z
ddœdd„Z dddœdd„Z ddœdd „Z d!d"„ZdCd$d%œd&d'„Zd$d%œd(d)„Zd*d+„Zd,d$d-œd.d/„Zddd0œd1d2„Zd$dd3œd4d5„Zd6d7„Zd8d9„ZdDd;dd<œd=d>„Zd,d,d?œd@dA„ZdBS)ErEzlinteger, integer slice (START point is INCLUDED, END point is EXCLUDED), listlike of integers, boolean arrayTrr[cCst |¡r@t|dƒr<t|jtƒr<|jjdkr4tdƒ‚tdƒ‚dSt|t    ƒrNdSt
|ƒrd|  ||¡n²t|t ƒrxt dƒ‚nžt|ƒrt|tƒr”|j}nt|ƒr¢|}n
t |¡}t|j |¡ƒ}t|jƒsÔtd|›ƒ‚t|ƒr| ¡|ksú| ¡| krtdƒ‚ntd|j›d    ƒ‚dS)
Nr¦ÚintegerzDiLocation based boolean indexing on an integer type is not availablezBiLocation based boolean indexing cannot use an indexable as a maskr¸z%.iloc requires numeric indexers, got ú%positional indexers are out-of-boundsz#Can only index by location with a [ú])rqrrrÉr]r¦r2Z inferred_typerÐr­rÂrÚ_validate_integerr^rr/r&Ú_valuesrrur,rprXrbr rwÚ
IndexErrorÚmaxÚminrR)r<rirSÚarrÚlen_axisr;r;r>rŸÆs8
 ÿÿ
 
 
 
 
 
 
&
z_iLocIndexer._validate_keyrTrFcCsœt|tƒrtdƒ‚t|tƒr$tdƒ‚t|tƒs:t|j|ƒ}t|j    j
|ƒD]N\}}t|t ƒr\qHt |ƒrfqHt |ƒr„|t|ƒkr–tdƒ‚qHt|tƒrHtdƒ‚qHdS)zÂ
        Validate that a positional indexer cannot enlarge its target
        will raise if needed, does not modify the indexer externally.
 
        Returns
        -------
        bool
        z%iloc cannot enlarge its target objectzsDataFrame indexer for .iloc is not supported. Consider using .loc with a DataFrame indexer for automatic alignment.T)r]Údictrør%rÚr^Ú_tuplifyraràrXr´rÂr/rrp)r<r{rkror;r;r>ršðs&    
 
ÿ
 
 
 
 
z'_iLocIndexer._has_valid_setitem_indexerr^rªcCs$t|ƒ|jkrdStdd„|DƒƒS)r°Fcss|]}t|ƒVqdSr:)rr€r;r;r>rƒ!sz1_iLocIndexer._is_scalar_access.<locals>.<genexpr>)rprar‰r¹r;r;r>rËs
z_iLocIndexer._is_scalar_accessÚintr)rirSrGcCs.t|j |¡ƒ}||ks"|| kr*tdƒ‚dS)a@
        Check that 'key' is a valid position in the desired axis.
 
        Parameters
        ----------
        key : int
            Requested position.
        axis : int
            Desired axis.
 
        Raises
        ------
        IndexError
            If 'key' is not a valid position in axis 'axis'.
        z*single positional indexer is out-of-boundsN)rprXrbrø)r<rirSrür;r;r>rö#sz_iLocIndexer._validate_integerr³c
Cs:| |¡}ttƒ| |¡W5QR£SQRX| |¡Sr:)r¯rrrÇrÁrµr;r;r>rÍ9s
 
z_iLocIndexer._getitem_tuplec
CsDz|jj||dWStk
r>}ztdƒ|‚W5d}~XYnXdS)a
        Return Series values by list or array of integers.
 
        Parameters
        ----------
        key : list-like positional indexer
        axis : int
 
        Returns
        -------
        Series object
 
        Notes
        -----
        `axis` can only be zero.
        r[rôN)rXrÓrø)r<rirSr®r;r;r>Ú_get_list_axis@sz_iLocIndexer._get_list_axiscCsÒ|tkrtdƒ}nt|tƒr$tdƒ‚t|tƒr<|j||dSt|ƒrLt|ƒ}t|tƒr`t     |¡}t
  |¡r„|  ||¡|j ||dSt|ƒrš|j||dSt|ƒ}t|ƒs²tdƒ‚| ||¡|jj||dSdS)NzWDataFrame indexer is not allowed for .iloc
Consider using .loc for automatic alignment.r[z5Cannot index by location index with a non-integer key)r¢rÂr]r%rørêrrgruÚasarrayrqrrrŸrÕr/rr rrÚrörXZ_ixsržr;r;r>r½Ws,
 
ÿ
 
 
 
  z_iLocIndexer._getitem_axisrÂrìcCs>|j}t|ƒs|jddS| |¡}| |¡|jj||dS)NFrºr[)rXrîr¿rbZ_validate_positional_slicerð)r<rírSrXrÔr;r;r>rê|s  
 
z_iLocIndexer._get_slice_axiscCs|S)zL
        Much simpler as we only have to deal with our valid types.
        r;ržr;r;r>rh‡sz _iLocIndexer._convert_to_indexercCs.t|ƒrt|ƒ}|jdk    r*t|j|j|ƒ}|Sr:)rrgrSr`rar¹r;r;r>rls
 
z!_iLocIndexer._get_setitem_indexerrHrQ©rWcCs |jj}|jjj }|s,t|tƒr,|jj }|s„t|jjjƒr„|jdkr„t|t    ƒr^t
|  ¡ƒn|}|jjjd}t |t |ddƒ }t|tƒrÞt|ƒt|jjƒkrÞt||jjƒD],\}}    t|    tƒr°t|ƒs°t |¡s°d}qÞq°t|tƒr¼g}
t|ƒD]¸\}} t| t    ƒr¦t| ƒ\} } |jdkr||krt|jƒs\t|ƒsLtdƒ‚||j| <dSt |d¡r|||j| <dSt|ƒrìt |dd}dtjt|jƒtjd}t ||¡}t|tƒsà|||d<||j| <dS||j| <nt |ƒ|j| <t!||jjƒ}| "|||¡dS|j #|¡}| $t|ƒ| ¡}tj%t|ƒdtjd}d|d<|||fi}|jj&|dd    }|j|j_|jj'dd
d|j_(|
 )| *| ¡¡qö|
 )| ¡qöt|
ƒ}n"t|ƒ\}}|rÞ| +||¡dS|d krø| ,||¡\}}|r| -|||¡n| .|||¡dS) a­
        _setitem_with_indexer is for setting values on a Series/DataFrame
        using positional indexers.
 
        If the relevant keys are not present, the Series/DataFrame may be
        expanded.
 
        This method is currently broken when dealing with non-unique Indexes,
        since it goes from positional indexers back to labels when calling
        BlockManager methods, see GH#12991, GH#22046, GH#15686.
        rnrT)Z extract_numpyz5cannot set a frame with no defined index and a scalarNr†r…)rß©ÚclearrK)/rXÚ_info_axis_numberrZis_single_blockr]r%rpZarraysrarýrgÚvaluesrr-r^r´ràr3rrqrŒr¬Úconvert_missing_indexerr/r­rruZonesrŽÚalgosZtake_ndr&r'Ú"convert_from_missing_indexer_tupler›rbÚinsertrráÚ_maybe_update_cacherZ_is_copyÚappendrdÚ_setitem_with_indexer_missingr~Ú _setitem_with_indexer_split_pathÚ_setitem_single_block)r<r{r|rWÚ    info_axisZtake_split_pathÚvalrûrorkZnindexerÚidxriÚ_ZtakerZ empty_valueÚ new_indexerr¦rÔZ
reindexersZnew_objÚmissingr;r;r>r›™s˜  
 
ÿ
ÿÿ    
ÿ
 
 
 
 ÿ  ÿ
 
 
z"_iLocIndexer._setitem_with_indexerc Cs²|jdkst‚t|tƒs$t|j|ƒ}t|ƒ|jkr:tdƒ‚t|dtjƒr`|djdkr`t    dƒ‚t|t
ƒrr|dks|t|t ƒr˜ddl m }| |||ƒ¡}|d}| |¡}|d}t||jjƒ}t|ƒr”t|ddƒdkr”t|tƒrø| |||¡q®t |¡dkr| ||¡q®t|ƒdkrT|t|ƒkrTt|ƒsT| |d||¡q®t|ƒdkr¼d|kr~t|ƒkr¼nn:t|ƒdkr²t|ƒs²| ||df|d¡St    d    ƒ‚nÖ|dkrÞt|ƒt|jjƒkrÞn´| |¡rt|jj|dƒr| |d||¡n~t|ƒt|ƒkrLt||ƒD]\}    }
| |    |
|¡q0nFt|ƒdkrŠt  !|¡rŠt|jƒdkrŠ| |d||¡nt    d    ƒ‚n|D]}    | |    ||¡q˜d
S) z&
        Setitem column-wise.
        rmztoo many indices for arrayrzCannot set values with ndim > 2rH©r5rnraz@Must have equal len keys and value when setting with an iterableN)"rar¾r]r^rþrprørurvr­r&rýÚpandasr5rtÚ_ensure_iterable_column_indexerr1rXr¦r/r¼r%Ú!_setitem_with_indexer_frame_valueÚ_setitem_with_indexer_2d_valuer"Ú_setitem_single_columnrr›rËr!ZdtypesràrqrŒ) r<r{r|rWr5rÚilocsr}Zlplane_indexerrKÚvr;r;r>r(sV
 
 
&.ÿ ÿ*ÿz-_iLocIndexer._setitem_with_indexer_split_pathcCsŒ|d}| |d¡}t|ƒs,tj|td}t|ƒ|jdkrFtdƒ‚t|ƒD]8\}}|dd…|f}t    |j
ƒrx|  ¡}|  |||¡qNdS)Nrrnr…z?Must have equal len keys and value when setting with an ndarray) rrrur,Úobjectrpryr­r¬r!rwÚtolistr)r<r{r|r}rrorKZ    value_colr;r;r>rƒsÿ
z+_iLocIndexer._setitem_with_indexer_2d_valuer4)r|rWc CsH| |d¡}t|ƒ}|d}t|jjtƒ}|jj}|dkrpt|ƒD](\}    }
|jdd…|    f} |     |
| |¡qDnÔ|sâ|j 
|jj¡râ|D]V}
|jj|
} | |krÊ| |d<|  t |ƒ|jdd…|
f|¡} nt j} |     |
| |¡qˆnb|sðtdƒ‚nT|D]N}
|jj|
} | |kr.| |d<|  t |ƒ|| |¡} nt j} |     |
| |¡qôdS)NrnrrHz/Setting with non-unique columns is not allowed.)rrgr]rXrˆr3Ú    is_uniquer¬rHrÚequalsrtr^ruÚnanr­) r<r{r|rWrZ sub_indexerr}Úmultiindex_indexerZ unique_colsrorKrÚitemr;r;r>r™sD ý
 
ÿz._iLocIndexer._setitem_with_indexer_frame_value)rKrGc
Cs°|}t |¡pt |t|jƒ¡}t |¡p<t|ƒo<t|ƒdk}|rFdS|rz|jjj|||ddWq¢t    t
t fk
rŒ|j  ||¡Yq¢Xn|jj |||¡|j  ¡dS)zÕ
 
        Parameters
        ----------
        loc : int
            Indexer for column position
        plane_indexer : int, slice, listlike[int]
            The indexer we use for setitem along axis=0.
        rNT)Z inplace_only)rqrŒZ is_full_slicerprXZis_empty_slicerrZcolumn_setitemr­rÚrZisetitemZ_clear_item_cache)r<rKr|Z plane_indexerr}Zis_full_setterZis_null_setterr;r;r>rÊs"
ÿ
z#_iLocIndexer._setitem_single_column)rWrGc    Cs,ddlm}|jj}|j |¡}t|tƒrª|jt|ƒkrDdkr¢nnZt    |dƒr¢t
  |d¡r¢|||}t|  |g¡ƒdkr¢|  |¡}| |||d¡dSt|Ž}t|tƒr¼|dksÆt|tƒrØ| |||ƒ¡}n t|tƒrø|dkrø| ||¡j}|j ¡|jjj||d|j_|jjddd    dS)
zQ
        _setitem_with_indexer for the case when we have a single Block.
        rrrmrnNrH)r{r|T)rZinplace)rr5rXrrbr]r^rarprrqrŒÚget_indexer_forrdrÚmaybe_convert_ixr&rýrtr%rzr÷Z%_check_is_chained_assignment_possiblerÚsetitemr )    r<r{r|rWr5rZ item_labelsÚcolrKr;r;r>rïs4  
ÿÿ
 
þ ý 
 
z"_iLocIndexer._setitem_single_blockcCsŒddlm}|jdkrT|jj}| t|ƒ|¡}|jrb| |dd…¡}|dk     ¡rb| 
||d¡St |ƒspd}nˆt ||jj ƒr®t|jj ƒsšt|jj dd}t|jj |ƒd}nJt|ƒr¼d}n<|jjsôt|jj ƒsô|jj }t|d    |ƒ}t||ƒd}nd}||g|d
j}    t|jjƒr&t|jj|    gƒ}    |jj|    ||jjd j|j_|jjd d n4|jdkrˆt|jjƒsvtdƒ‚t|dƒ}
t|tƒr¦|j|jjd d}||_n\t|t ƒrÈ|||jj|t!d}n:t"|ƒrðt|ƒt|jjƒkrðtdƒ‚|||jj|d }t|jƒsh| #¡j$} |jj} t| t%ƒr4| j&} n| j} t'|g| d| _|
s\| j(dd} | j|j_n|j )|¡j|j_|jjd d dS)zN
        Insert new row(s) or column(s) into the Series or DataFrame.
        rrrnr†NrKF)ÚcompatZ numpy_dtyper…)r¦rWTrrmz*cannot set a frame with no defined columnsrw)r¦r¿)r¦rWrwz(cannot set a row with mismatched columnsr©r¿)*rr5rarXr¦r
rpr Ú get_indexerr£r›r"r(rwr!r*rr)Úemptyr¼r÷r$Z _constructorrWrr rˆr­rÉr]r&Úreindexrýrr/Zto_frameÚTr3Únamesr2Z infer_objectsÚ_append)r<r{r|r5r¦Z    new_indexrZ    new_dtypeZ
curr_dtypeZ
new_valuesZ    has_dtypeÚdfrrWr;r;r>r sx     ÿ  
  ÿ
 
   z*_iLocIndexer._setitem_with_indexer_missingcCsdt|ƒr|g}nPt|tƒr2t t|jjƒ¡|}n.t|tjƒr\t    |j
ƒr\t t|ƒ¡|}n|}|S)zX
        Ensure that our column indexer is something that can be iterated over.
        ) rr]rÂrurrprXrˆrvrrw)r<Zcolumn_indexerrr;r;r>r€s
ÿz,_iLocIndexer._ensure_iterable_column_indexerFr5)Úserr#cCstt|ttjttfƒr|f}t|tƒrÔdd„}tt||ƒƒ}dd„|Dƒ}t|ƒ}|dk}|j    dk}|j
}    |rz|ox|d}||j    krêt dd    „|Dƒƒrê|j |    j d|dd
d j}
t|ƒdkræ|sæt|dƒ} t |
| ¡ | d ¡j}
|
St|ƒD]Þ\} } |    j | }t| ƒst| tƒrŠ|r.t | ¡r.qò|| }t|ƒsLt|gƒ}nt|ƒ}|j |¡slt|ƒsz|j ¡S|  |¡jS|rò|j
j d}|j |¡s²t|ƒsÀ|j ¡S|  |¡jSqòn”t|ƒr.|j    dkr.t|j
ƒrú|S|j
 d¡}|j |¡r|j ¡S|  |¡j|St|ƒrh|j
 d¡}|j |¡r\|j ¡S|  |¡jStd ƒ‚dS)aT
        Parameters
        ----------
        indexer : tuple, slice, scalar
            Indexer used to get the locations that will be set to `ser`.
        ser : pd.Series
            Values to assign to the locations specified by `indexer`.
        multiindex_indexer : bool, optional
            Defaults to False. Should be set to True if `indexer` was from
            a `pd.MultiIndex`, to avoid unnecessary broadcasting.
 
        Returns
        -------
        `np.array` of `ser` broadcast to the appropriate shape for assignment
        to the locations selected by `indexer`
        cSst|tjƒr| ¡S|Sr:)r]rurvÚravel)ror;r;r>r3§sz)_iLocIndexer._align_series.<locals>.ravelcSsg|]}t |¡ ‘qSr;)rqrŒ)rrr;r;r>r·¬sz._iLocIndexer._align_series.<locals>.<listcomp>rnrmrcss|]}t|ƒVqdSr:)r#©rrr;r;r>rƒ½sz-_iLocIndexer._align_series.<locals>.<genexpr>Tr*r†z Incompatible indexer with SeriesN)r]rÂrurvrgr2r^ÚmapÚsumrarXr‰r-r´r÷rpZtileZreshaper.r¬r#rqrŒr/r¦r!r¿rr!rbr­)r<r{r2r#r3ZalignersZ sum_alignersZsingle_alignerÚis_framerXZ
ser_valuesZ len_indexerrorrkZnew_ixr;r;r>rt‘sb 
  ÿ
 
 
 
 
 z_iLocIndexer._align_series)r1rGc Csj|jdk}t|tƒrÞd\}}g}t|ƒD]n\}}|jj|}    t|ƒsNt|tƒrŒt|tj    ƒrb| 
¡}|dkrt|    |}q–|dkr†|    |}q–q˜q(|  |¡q(|dk    rÜ|dk    rÜ|j   |¡rÊ|j  |¡rÊ| ¡}
n|j||d}
|
Sn€t|tƒsòt|ƒr^|r^|jj |}    |j   |    ¡r| ¡}
n>t|    tƒrNt|j tƒrN|    j|j jkrNtdƒ‚|j|    d}
|
Stdƒ‚dS)Nrm)NN)rˆzAcannot align on a multi-index with out specifying the join levels)r¦z#Incompatible indexer with DataFrame)rar]r^r¬rXr´r#rÂrurvr3r r¦r!rˆr¿r-r/r3rérÚr­) r<r{r1r7rÚcolsZ    sindexersroÚixrkrr;r;r>rzösH
 
 
 
 
 
ÿ
þ ýÿ z_iLocIndexer._align_frameN)rH)F)r@rArBrRrUrŸršrËrörÍrr½rêrhrlr›rrrrrr rrtrzr;r;r;r>rE»s0ÿ*$%  [1%*gerEc@s8eZdZUdZded<dd„Zdd„Zdd    œd
d „Zd S) Ú_ScalarAccessIndexerz!
    Access scalars quickly.
    rTrUcCs t|ƒ‚dSr:rr¹r;r;r>Ú _convert_key0    sz!_ScalarAccessIndexer._convert_keycCs@t|tƒs"t|ƒs|f}ntdƒ‚| |¡}|jj|d|jiŽS)Nú)Invalid call for scalar access (getting)!rÊ)r]r^r/r­r;rXrÌrUr¹r;r;r>r?3    s 
 
z _ScalarAccessIndexer.__getitem__rrFcs„t|tƒr"t‡fdd„|Dƒƒ}nt |ˆj¡}t|tƒsFtˆj|ƒ}tˆ |¡ƒ}t    |ƒˆjkrjt
dƒ‚ˆjj ||ˆj dœŽdS)Nc3s|]}t |ˆj¡VqdSr:r”r“rIr;r>rƒ@    sz3_ScalarAccessIndexer.__setitem__.<locals>.<genexpr>z0Not enough indexers for scalar access (setting)!)r|rÊ) r]r^rqr•rXrþrargr;rpr­Z
_set_valuerU©r<rir|r;rIr>rœ>    s
 
 z _ScalarAccessIndexer.__setitem__N)r@rArBrCrÖr;r?rœr;r;r;r>r:(    s
 
 r:csFeZdZdZdd„Zeddœdd„ƒZ‡fdd    „Z‡fd
d „Z‡Z    S) rLFcCs |jdkrt|ƒdkr|f}|S)zd
        Require they keys to be the same type as the index. (so we don't
        fallback)
        rn)rarpr¹r;r;r>r;R    sz_AtIndexer._convert_keyrTrFcCs"|jdkst‚|jjjo |jjjS)Nrm)rar¾rXr¦r rˆrIr;r;r>Ú_axes_are_unique_    sz_AtIndexer._axes_are_uniquecsL|jdkr@|js@t|tƒr,tdd„|Dƒƒs4tdƒ‚|jj|Stƒ     |¡S)Nrmcss|]}t|ƒVqdSr:©r"r“r;r;r>rƒh    sz)_AtIndexer.__getitem__.<locals>.<genexpr>r<)
rar>r]r^r‰r­rXrKÚsuperr?r¹©Ú    __class__r;r>r?e    s
 z_AtIndexer.__getitem__csR|jdkrD|jsDt|tƒr,tdd„|Dƒƒs4tdƒ‚||jj|<dStƒ     ||¡S)Nrmcss|]}t|ƒVqdSr:r?r“r;r;r>rƒq    sz)_AtIndexer.__setitem__.<locals>.<genexpr>z)Invalid call for scalar access (setting)!)
rar>r]r^r‰r­rXrKr@rœr=rAr;r>rœn    s  z_AtIndexer.__setitem__)
r@rArBrUr;rPr>r?rœÚ __classcell__r;r;rAr>rLN    s       rLc@seZdZdZdd„ZdS)rNTcCs|D]}t|ƒstdƒ‚q|S)zH
        Require integer args. (and convert to label arguments)
        z1iAt based indexing can only have integer indexers)rr­)r<riror;r;r>r;~    s
z_iAtIndexer._convert_keyN)r@rArBrUr;r;r;r;r>rNz    srNrÿrztuple[Hashable | slice, ...])rarKrGcCs"dd„t|ƒDƒ}||d<t|ƒS)zÖ
    Given an indexer for the first dimension, create an equivalent tuple
    for indexing over all dimensions.
 
    Parameters
    ----------
    ndim : int
    loc : object
 
    Returns
    -------
    tuple
    cSsg|]}tddƒ‘qSr:)rÂr4r;r;r>r·—    sz_tuplify.<locals>.<listcomp>r)rfr^)rarKZ_tupr;r;r>rþˆ    srþrr^)rarSrGcCstdƒg|}|||<t|ƒS)zI
    If we have an axis, adapt the given key to be axis-independent.
    N)rÂr^)rarSrir¨r;r;r>r`œ    sr`r2z
np.ndarray)r¦rGcCsŒ|}t|tƒrV|j |¡sV|j |¡}d|kr6tdƒ‚| |¡}t|jƒsV|     t
¡j St |ƒrnt j|t
d}nt|ƒs‚t|t
d}t||ƒS)aL
    Check if key is a valid boolean indexer for an object with such index and
    perform reindexing or conversion if needed.
 
    This function assumes that is_bool_indexer(key) == True.
 
    Parameters
    ----------
    index : Index
        Index of the object on which the indexing is done.
    key : list-like
        Boolean indexer to check.
 
    Returns
    -------
    np.array
        Resulting key.
 
    Raises
    ------
    IndexError
        If the key does not have the same length as index.
    IndexingError
        If the index of the key is unalignable to index.
    r†ztUnalignable boolean Series provided as indexer (index of the boolean Series and of the indexed object do not match).r…)r]r&r¦r!r%rrñrrwZastyperTr÷r!rurrÚpd_arrayr.)r¦riÚresultr{r;r;r>rÒ¥    s ÿ
 
  rÒcCs4t|tƒr,|d}t|tƒr$tdƒ‚|dfS|dfS)zƒ
    Reverse convert a missing indexer, which is a dict
    return the scalar indexer and a boolean indicating if we converted
    riz.cannot use a single bool to index into setitemTF)r]rýrTrc)r{r;r;r>rÙ    s 
 
rcs&‡fdd„‰t‡fdd„t|ƒDƒƒS)zK
    Create a filtered indexer that doesn't have any missing indexers.
    cs t|tƒrˆ| |d¡S|S)Nri)r]rýrd)Ú_iÚ_idx)r´r;r>r+î    sz7convert_from_missing_indexer_tuple.<locals>.get_indexerc3s|]\}}ˆ||ƒVqdSr:r;)rrFrG)r+r;r>rƒñ    sz5convert_from_missing_indexer_tuple.<locals>.<genexpr>)r^r¬)r{r´r;)r´r+r>r    é    s r    cGs0|D] }t|tjtttfƒs|Sqtj|ŽS)z3
    We likely want to take the cross-product.
    )r]rurvrgr&r2Zix_)Úargsr=r;r;r>r&ô    s
r&rTrFcCs<t|tƒsdS|D]$}t|ƒs(t|tƒrt|tƒSqdS)ú&
    Returns
    -------
    bool
    F)r]r^rrÂr3)r¡rÔr‚r;r;r>r²þ    s 
r²cCst|tƒ ot|ƒ o|tk    S)rI)r]rÂr/r¢rÎr;r;r>rÅ
s
 ÿýrÅrÂ)rXrGcCs(|jdk    p&|jdk    p&|jdk    o&|jdkS)rINrn)rØrÙrï)rXr;r;r>rî
s
 
ÿýrîrcCs`t|tƒs&t|tƒr.tdd„|Dƒƒr.tdƒ‚t|tƒsTt|tƒr\tdd„|Dƒƒr\tdƒ‚dS)zX
    Check if the indexer is or contains a dict or set, which is no longer allowed.
    css|]}t|tƒVqdSr:)r]Úsetr“r;r;r>rƒ1
sz-check_dict_or_set_indexers.<locals>.<genexpr>zAPassing a set as an indexer is not supported. Use a list instead.css|]}t|tƒVqdSr:)r]rýr“r;r;r>rƒ:
szBPassing a dict as an indexer is not supported. Use a list instead.N)r]rJr^r£rÚrýrÎr;r;r>r_*
s$ÿþýÿÿþýÿr_)mÚ
__future__rÚ
contextlibrr–Útypingrrrrrr    r˜ÚnumpyruZpandas._configr
Zpandas._libs.indexingr Zpandas._libs.libr Zpandas._typingr rZ pandas.compatrZ pandas.errorsrrrrrrZpandas.util._decoratorsrZpandas.core.dtypes.castrrZpandas.core.dtypes.commonrrrrrrrr r!r"r#Zpandas.core.dtypes.concatr$Zpandas.core.dtypes.genericr%r&Zpandas.core.dtypes.missingr'r(r)r*Z pandas.corer+rZpandas.core.commonÚcoreÚcommonrqZpandas.core.constructionr,rDr-Zpandas.core.indexersr.r/r0r1Zpandas.core.indexes.apir2r3rr4r5r6rÂr§r¥r9Z
IndexSlicerDr7rKrJrHrEr:rMrLrOrNrþr`rÒrr    r&r²rÅrîr_r;r;r;r>Ú<module>s‚         4   
, QVr&+     4