File tree Expand file tree Collapse file tree 2 files changed +31
-3
lines changed Expand file tree Collapse file tree 2 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -770,6 +770,23 @@ def validate_cycler(s):
770
770
return cycler_inst
771
771
772
772
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
+
773
790
# a map from key -> value, converter
774
791
defaultParams = {
775
792
'backend' : ['Agg' , validate_backend ], # agg is certainly
@@ -814,7 +831,7 @@ def validate_cycler(s):
814
831
'patch.antialiased' : [True , validate_bool ], # antialiased (no jaggies)
815
832
816
833
## Histogram properties
817
- 'hist.bins' : [10 , validate_any ],
834
+ 'hist.bins' : [10 , validate_hist_bins ],
818
835
819
836
## Boxplot properties
820
837
'boxplot.notch' : [False , validate_bool ],
Original file line number Diff line number Diff line change 27
27
validate_nseq_int ,
28
28
validate_nseq_float ,
29
29
validate_cycler ,
30
- validate_hatch )
30
+ validate_hatch ,
31
+ validate_hist_bins )
31
32
32
33
33
34
mpl .rc ('text' , usetex = False )
@@ -363,7 +364,17 @@ def test_validators():
363
364
),
364
365
'fail' : (('fish' , ValueError ),
365
366
),
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
+ }
367
378
)
368
379
369
380
for validator_dict in validation_tests :
You can’t perform that action at this time.
0 commit comments