File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -770,6 +770,23 @@ def validate_cycler(s):
770770 return cycler_inst
771771
772772
773+ def validate_hist_bins (s ):
774+ if isinstance (s , six .text_type ) and s == 'auto' :
775+ return s
776+ try :
777+ return int (s )
778+ except (TypeError , ValueError ):
779+ pass
780+
781+ try :
782+ return validate_floatlist (s )
783+ except ValueError :
784+ pass
785+
786+ raise ValueError ("'hist.bins' must be 'auto', an int or " +
787+ "a sequence of floats" )
788+
789+
773790# a map from key -> value, converter
774791defaultParams = {
775792 'backend' : ['Agg' , validate_backend ], # agg is certainly
@@ -814,7 +831,7 @@ def validate_cycler(s):
814831 'patch.antialiased' : [True , validate_bool ], # antialiased (no jaggies)
815832
816833 ## Histogram properties
817- 'hist.bins' : [10 , validate_any ],
834+ 'hist.bins' : [10 , validate_hist_bins ],
818835
819836 ## Boxplot properties
820837 'boxplot.notch' : [False , validate_bool ],
Original file line number Diff line number Diff line change 2727 validate_nseq_int ,
2828 validate_nseq_float ,
2929 validate_cycler ,
30- validate_hatch )
30+ validate_hatch ,
31+ validate_hist_bins )
3132
3233
3334mpl .rc ('text' , usetex = False )
@@ -363,7 +364,17 @@ def test_validators():
363364 ),
364365 'fail' : (('fish' , ValueError ),
365366 ),
366- }
367+ },
368+ {'validator' : validate_hist_bins ,
369+ 'success' : (('auto' , 'auto' ),
370+ ('10' , 10 ),
371+ ('1, 2, 3' , [1 , 2 , 3 ]),
372+ ([1 , 2 , 3 ], [1 , 2 , 3 ]),
373+ (np .arange (15 ), np .arange (15 ))
374+ ),
375+ 'fail' : (('aardvark' , ValueError ),
376+ )
377+ }
367378 )
368379
369380 for validator_dict in validation_tests :
You can’t perform that action at this time.
0 commit comments