@@ -1046,10 +1046,9 @@ def extend(self, labels):
1046
1046
def iswildcard (self ):
1047
1047
return self ._iswildcard
1048
1048
1049
- # XXX: not sure I should offer an *args version
1050
- def group (self , * args , ** kwargs ):
1049
+ def _group (self , * args , ** kwargs ):
1051
1050
"""
1052
- Returns a group (list or unique element) of label(s) usable in .sum or .filter
1051
+ Deprecated.
1053
1052
1054
1053
Parameters
1055
1054
----------
@@ -1058,48 +1057,26 @@ def group(self, *args, **kwargs):
1058
1057
**kwargs
1059
1058
name of the group. There is no other accepted keywords.
1060
1059
1061
- Returns
1062
- -------
1063
- LGroup
1064
- group containing selected label(s).
1065
-
1066
- Notes
1067
- -----
1068
- key is label-based (slice and fancy indexing are supported)
1069
-
1070
- See Also
1071
- --------
1072
- LGroup
1073
-
1074
1060
Examples
1075
1061
--------
1076
1062
>>> time = Axis('time', [2007, 2008, 2009, 2010])
1077
- >>> odd_years = time.group ([2007, 2009], name='odd_years')
1063
+ >>> odd_years = time._group ([2007, 2009], name='odd_years')
1078
1064
>>> odd_years
1079
1065
time[2007, 2009] >> 'odd_years'
1080
1066
"""
1081
1067
name = kwargs .pop ('name' , None )
1082
1068
if kwargs :
1083
- raise ValueError ("invalid keyword argument(s): %s"
1084
- % list (kwargs .keys ()))
1069
+ raise ValueError ("invalid keyword argument(s): %s" % list (kwargs .keys ()))
1085
1070
key = args [0 ] if len (args ) == 1 else args
1086
- if isinstance (key , basestring ):
1087
- key = to_keys (key )
1071
+ return self [key ] >> name if name else self [key ]
1088
1072
1089
- if isinstance (key , (tuple , list )):
1090
- if any (isinstance (k , Group ) for k in key ):
1091
- k0 = key [0 ]
1092
- assert isinstance (k0 , Group )
1093
- cls_ = k0 .__class__
1094
- assert all (isinstance (k , cls_ ) for k in key [1 :])
1095
- res = [k .with_axis (self ) for k in key ]
1096
- res = tuple (res ) if isinstance (key , tuple ) else res
1097
- return res
1098
-
1099
- if isinstance (key , Group ):
1100
- name = name if name is not None else key .name
1101
- return key .__class__ (key .key , name , self )
1102
- return LGroup (key , name , self )
1073
+ def group (self , * args , ** kwargs ):
1074
+ group_name = kwargs .pop ('name' , None )
1075
+ key = args [0 ] if len (args ) == 1 else args
1076
+ syntax = '{}[{}]' .format (self .name if self .name else 'axis' , key )
1077
+ if group_name is not None :
1078
+ syntax += ' >> {}' .format (repr (group_name ))
1079
+ raise NotImplementedError ('Axis.group is deprecated. Use {} instead.' .format (syntax ))
1103
1080
1104
1081
def all (self , name = None ):
1105
1082
"""
@@ -1114,7 +1091,10 @@ def all(self, name=None):
1114
1091
--------
1115
1092
Axis.group
1116
1093
"""
1117
- return self .group (slice (None ), name = name if name is not None else "all" )
1094
+ axis_name = self .name if self .name else 'axis'
1095
+ group_name = name if name else 'all'
1096
+ raise NotImplementedError ('Axis.all is deprecated. '
1097
+ 'Use {}[:] >> {} instead.' .format (axis_name , repr (group_name )))
1118
1098
1119
1099
def subaxis (self , key , name = None ):
1120
1100
"""
@@ -1333,9 +1313,35 @@ def __iter__(self):
1333
1313
1334
1314
def __getitem__ (self , key ):
1335
1315
"""
1316
+ Returns a group (list or unique element) of label(s) usable in .sum or .filter
1317
+
1336
1318
key is a label-based key (slice and fancy indexing are supported)
1319
+
1320
+ Returns
1321
+ -------
1322
+ Group
1323
+ group containing selected label(s)/position(s).
1324
+
1325
+ Notes
1326
+ -----
1327
+ key is label-based (slice and fancy indexing are supported)
1337
1328
"""
1338
- return self .group (key )
1329
+ if isinstance (key , basestring ):
1330
+ key = to_keys (key )
1331
+
1332
+ if isinstance (key , (tuple , list )):
1333
+ if any (isinstance (k , Group ) for k in key ):
1334
+ k0 = key [0 ]
1335
+ assert isinstance (k0 , Group )
1336
+ cls_ = k0 .__class__
1337
+ assert all (isinstance (k , cls_ ) for k in key [1 :])
1338
+ res = [k .with_axis (self ) for k in key ]
1339
+ res = tuple (res ) if isinstance (key , tuple ) else res
1340
+ return res
1341
+
1342
+ if isinstance (key , Group ):
1343
+ return key .__class__ (key .key , key .name , self )
1344
+ return LGroup (key , axis = self )
1339
1345
1340
1346
def __contains__ (self , key ):
1341
1347
return _to_tick (key ) in self ._mapping
0 commit comments