@@ -223,6 +223,10 @@ def _range_str_to_range(s, stack_depth=1):
223223 >>> list(_range_str_to_range('2..6 step 2'))
224224 [2, 4, 6]
225225
226+ 0 padding
227+ >>> list(_range_str_to_range('01..12'))
228+ ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']
229+
226230 any special character except . and spaces should work
227231 >>> _range_str_to_range('a|+*@-b .. a|+*@-d')
228232 ['a|+*@-b', 'a|+*@-c', 'a|+*@-d']
@@ -236,6 +240,8 @@ def _range_str_to_range(s, stack_depth=1):
236240 if stop is None :
237241 raise ValueError ("no stop bound provided in range: %r" % s )
238242 stop = _parse_bound (stop , stack_depth + 1 )
243+ if isinstance (start , basestring ) or isinstance (stop , basestring ):
244+ start , stop = str (start ), str (stop )
239245 # TODO: use parse_bound
240246 step = int (step ) if step is not None else 1
241247 return generalized_range (start , stop , step )
@@ -365,6 +371,7 @@ def _to_tick(v):
365371 return str (v )
366372
367373
374+ # TODO: remove the conversion to list in doctests once Python 2 is dropped
368375def _to_ticks (s , parse_single_int = False ):
369376 """
370377 Makes a (list of) value(s) usable as the collection of labels for an Axis (ie hashable).
@@ -378,53 +385,52 @@ def _to_ticks(s, parse_single_int=False):
378385
379386 Returns
380387 -------
381- collection of labels
382-
383- Notes
384- -----
385- This function is only used in Axis.__init__ and union().
388+ Numpy 1D array containing labels
386389
387390 Examples
388391 --------
389- >>> _to_ticks('M , F')
392+ >>> list( _to_ticks('M , F') )
390393 ['M', 'F']
391- >>> _to_ticks('A,C..E,F..G,Z')
394+ >>> list( _to_ticks('A,C..E,F..G,Z') )
392395 ['A', 'C', 'D', 'E', 'F', 'G', 'Z']
393- >>> _to_ticks('U')
396+ >>> list( _to_ticks('U') )
394397 ['U']
395398 >>> list(_to_ticks('..3'))
396399 [0, 1, 2, 3]
400+ >>> list(_to_ticks('01..12'))
401+ ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']
402+ >>> list(_to_ticks('01,02,03,10,11,12'))
403+ ['01', '02', '03', '10', '11', '12']
397404 """
398405 if isinstance (s , ABCAxis ):
399406 return s .labels
400407 if isinstance (s , Group ):
401408 # a single LGroup used for all ticks of an Axis
402409 return _to_ticks (s .eval ())
403- elif isinstance (s , pd .Index ):
404- return s .values
405410 elif isinstance (s , np .ndarray ):
406411 # we assume it has already been translated
407412 # XXX: Is it a safe assumption?
408413 return s
414+
415+ if isinstance (s , pd .Index ):
416+ ticks = s .values
409417 elif isinstance (s , (list , tuple )):
410- return [_to_tick (e ) for e in s ]
418+ ticks = [_to_tick (e ) for e in s ]
411419 elif sys .version >= '3' and isinstance (s , range ):
412- return list ( s )
420+ ticks = s
413421 elif isinstance (s , basestring ):
414422 seq = _seq_str_to_seq (s , parse_single_int = parse_single_int )
415423 if isinstance (seq , slice ):
416424 raise ValueError ("using : to define axes is deprecated, please use .. instead" )
417- elif isinstance (seq , (basestring , int )):
418- return [seq ]
419- else :
420- return seq
425+ ticks = [seq ] if isinstance (seq , (basestring , int )) else seq
421426 elif hasattr (s , '__array__' ):
422- return s .__array__ ()
427+ ticks = s .__array__ ()
423428 else :
424429 try :
425- return list (s )
430+ ticks = list (s )
426431 except TypeError :
427432 raise TypeError ("ticks must be iterable (%s is not)" % type (s ))
433+ return np .asarray (ticks )
428434
429435
430436_axis_name_pattern = re .compile ('\s*(([A-Za-z]\w*)(\.i)?\s*\[)?(.*)' )
0 commit comments