@@ -325,10 +325,34 @@ def __iter__(self):
325
325
326
326
327
327
# TODO: rename to ArrayIndexIndexer or something like that
328
+ # TODO: the first slice in the example below should be documented
328
329
class ArrayPositionalIndexer (object ):
329
- """
330
- equivalent to numpy indexing when indexing along a single axis *but* indexes the cross product of multiple axes
331
- instead of points
330
+ r"""
331
+ Allows selection of a subset using indices of labels.
332
+
333
+ Notes
334
+ -----
335
+ Using .i[] is equivalent to numpy indexing when indexing along a single axis. However, when indexing along multiple
336
+ axes this indexes the cross product instead of points.
337
+
338
+ Examples
339
+ --------
340
+ >>> arr = ndtest((2, 3, 4))
341
+ >>> arr
342
+ a b\c c0 c1 c2 c3
343
+ a0 b0 0 1 2 3
344
+ a0 b1 4 5 6 7
345
+ a0 b2 8 9 10 11
346
+ a1 b0 12 13 14 15
347
+ a1 b1 16 17 18 19
348
+ a1 b2 20 21 22 23
349
+
350
+ >>> arr.i[:, 0:2, [0, 2]]
351
+ a b\c c0 c2
352
+ a0 b0 0 2
353
+ a0 b1 4 6
354
+ a1 b0 12 14
355
+ a1 b1 16 18
332
356
"""
333
357
__slots__ = ('array' ,)
334
358
@@ -386,6 +410,38 @@ def __iter__(self):
386
410
387
411
388
412
class ArrayPointsIndexer (object ):
413
+ r"""
414
+ Allows selection of arbitrary items in the array based on their N-dimensional label index.
415
+
416
+ Examples
417
+ --------
418
+ >>> arr = ndtest((2, 3, 4))
419
+ >>> arr
420
+ a b\c c0 c1 c2 c3
421
+ a0 b0 0 1 2 3
422
+ a0 b1 4 5 6 7
423
+ a0 b2 8 9 10 11
424
+ a1 b0 12 13 14 15
425
+ a1 b1 16 17 18 19
426
+ a1 b2 20 21 22 23
427
+
428
+ To select the two points with label coordinates
429
+ [a0, b0, c0] and [a1, b2, c2], you must do:
430
+
431
+ >>> arr.points[['a0', 'a1'], ['b0', 'b2'], ['c0', 'c2']]
432
+ a_b_c a0_b0_c0 a1_b2_c2
433
+ 0 22
434
+ >>> arr.points['a0,a1', 'b0,b2', 'c0,c2']
435
+ a_b_c a0_b0_c0 a1_b2_c2
436
+ 0 22
437
+
438
+ The number of label(s) on each dimension must be equal:
439
+
440
+ >>> arr.points['a0,a1', 'b0,b2', 'c0,c1,c2'] # doctest: +NORMALIZE_WHITESPACE
441
+ Traceback (most recent call last):
442
+ ...
443
+ ValueError: all combined keys should have the same length
444
+ """
389
445
__slots__ = ('array' ,)
390
446
391
447
def __init__ (self , array ):
@@ -489,11 +545,41 @@ def __len__(self):
489
545
490
546
491
547
# TODO: rename to ArrayIndexPointsIndexer or something like that
548
+ # TODO: show that we need to use a "full slice" for leaving the dimension alone
549
+ # TODO: document explicitly that axes should be in the correct order and missing axes should be slice None
550
+ # (except at the end)
492
551
class ArrayPositionalPointsIndexer (object ):
493
- __slots__ = ('array' ,)
494
- """
495
- the closest to numpy indexing we get, but not 100% the same.
552
+ r"""
553
+ Allows selection of arbitrary items in the array based on their N-dimensional index.
554
+
555
+ Examples
556
+ --------
557
+ >>> arr = ndtest((2, 3, 4))
558
+ >>> arr
559
+ a b\c c0 c1 c2 c3
560
+ a0 b0 0 1 2 3
561
+ a0 b1 4 5 6 7
562
+ a0 b2 8 9 10 11
563
+ a1 b0 12 13 14 15
564
+ a1 b1 16 17 18 19
565
+ a1 b2 20 21 22 23
566
+
567
+ To select the two points with index coordinates
568
+ [0, 0, 0] and [1, 2, 2], you must do:
569
+
570
+ >>> arr.ipoints[[0,1], [0,2], [0,2]]
571
+ a_b_c a0_b0_c0 a1_b2_c2
572
+ 0 22
573
+
574
+ The number of index(es) on each dimension must be equal:
575
+
576
+ >>> arr.ipoints[[0,1], [0,2], [0,1,2]] # doctest: +NORMALIZE_WHITESPACE
577
+ Traceback (most recent call last):
578
+ ...
579
+ ValueError: all combined keys should have the same length
496
580
"""
581
+ __slots__ = ('array' ,)
582
+
497
583
def __init__ (self , array ):
498
584
self .array = array
499
585
@@ -1013,104 +1099,20 @@ def __dir__(self):
1013
1099
def _ipython_key_completions_ (self ):
1014
1100
return list (chain (* [list (labels ) for labels in self .axes .labels ]))
1015
1101
1016
- # TODO: the first slice in example below should be documented
1017
1102
@lazy_attribute
1018
1103
def i (self ):
1019
- r"""
1020
- Allows selection of a subset using indices of labels.
1021
-
1022
- Examples
1023
- --------
1024
- >>> arr = ndtest((2, 3, 4))
1025
- >>> arr
1026
- a b\c c0 c1 c2 c3
1027
- a0 b0 0 1 2 3
1028
- a0 b1 4 5 6 7
1029
- a0 b2 8 9 10 11
1030
- a1 b0 12 13 14 15
1031
- a1 b1 16 17 18 19
1032
- a1 b2 20 21 22 23
1033
-
1034
- >>> arr.i[:, 0:2, [0, 2]]
1035
- a b\c c0 c2
1036
- a0 b0 0 2
1037
- a0 b1 4 6
1038
- a1 b0 12 14
1039
- a1 b1 16 18
1040
- """
1041
1104
return ArrayPositionalIndexer (self )
1105
+ i .__doc__ = ArrayPositionalIndexer .__doc__
1042
1106
1043
1107
@lazy_attribute
1044
1108
def points (self ):
1045
- r"""
1046
- Allows selection of arbitrary items in the array based on their N-dimensional label index.
1047
-
1048
- Examples
1049
- --------
1050
- >>> arr = ndtest((2, 3, 4))
1051
- >>> arr
1052
- a b\c c0 c1 c2 c3
1053
- a0 b0 0 1 2 3
1054
- a0 b1 4 5 6 7
1055
- a0 b2 8 9 10 11
1056
- a1 b0 12 13 14 15
1057
- a1 b1 16 17 18 19
1058
- a1 b2 20 21 22 23
1059
-
1060
- To select the two points with label coordinates
1061
- [a0, b0, c0] and [a1, b2, c2], you must do:
1062
-
1063
- >>> arr.points[['a0', 'a1'], ['b0', 'b2'], ['c0', 'c2']]
1064
- a_b_c a0_b0_c0 a1_b2_c2
1065
- 0 22
1066
- >>> arr.points['a0,a1', 'b0,b2', 'c0,c2']
1067
- a_b_c a0_b0_c0 a1_b2_c2
1068
- 0 22
1069
-
1070
- The number of label(s) on each dimension must be equal:
1071
-
1072
- >>> arr.points['a0,a1', 'b0,b2', 'c0,c1,c2'] # doctest: +NORMALIZE_WHITESPACE
1073
- Traceback (most recent call last):
1074
- ...
1075
- IndexError: shape mismatch: indexing arrays could not be broadcast together with shapes (2,) (2,) (3,)
1076
- """
1077
1109
return ArrayPointsIndexer (self )
1110
+ points .__doc__ = ArrayPointsIndexer .__doc__
1078
1111
1079
- # TODO: show that we need to use a "full slice" for leaving the dimension alone
1080
- # TODO: document explicitly that axes should be in the correct order and missing axes should be slice None
1081
- # (except at the end)
1082
1112
@lazy_attribute
1083
1113
def ipoints (self ):
1084
- r"""
1085
- Allows selection of arbitrary items in the array based on their N-dimensional index.
1086
-
1087
- Examples
1088
- --------
1089
- >>> arr = ndtest((2, 3, 4))
1090
- >>> arr
1091
- a b\c c0 c1 c2 c3
1092
- a0 b0 0 1 2 3
1093
- a0 b1 4 5 6 7
1094
- a0 b2 8 9 10 11
1095
- a1 b0 12 13 14 15
1096
- a1 b1 16 17 18 19
1097
- a1 b2 20 21 22 23
1098
-
1099
- To select the two points with index coordinates
1100
- [0, 0, 0] and [1, 2, 2], you must do:
1101
-
1102
- >>> arr.ipoints[[0,1], [0,2], [0,2]]
1103
- a_b_c a0_b0_c0 a1_b2_c2
1104
- 0 22
1105
-
1106
- The number of index(es) on each dimension must be equal:
1107
-
1108
- >>> arr.ipoints[[0,1], [0,2], [0,1,2]] # doctest: +NORMALIZE_WHITESPACE
1109
- Traceback (most recent call last):
1110
- ...
1111
- IndexError: shape mismatch: indexing arrays could not be broadcast together with shapes (2,) (2,) (3,)
1112
- """
1113
1114
return ArrayPositionalPointsIndexer (self )
1115
+ ipoints .__doc__ = ArrayPositionalPointsIndexer .__doc__
1114
1116
1115
1117
def to_frame (self , fold_last_axis_name = False , dropna = None ):
1116
1118
r"""
0 commit comments