18
18
19
19
from mplfinance import _styles
20
20
21
- from mplfinance ._arg_validators import _check_and_prepare_data
22
- from mplfinance ._arg_validators import _mav_validator
23
- from mplfinance ._arg_validators import _process_kwargs
21
+ from mplfinance ._arg_validators import _check_and_prepare_data , _mav_validator
22
+ from mplfinance ._arg_validators import _process_kwargs , _validate_vkwargs_dict
24
23
25
24
26
25
def with_rc_context (func ):
@@ -46,124 +45,77 @@ def _warn_no_xgaps_deprecated(value):
46
45
return isinstance (value ,bool )
47
46
48
47
49
- def _valid_kwargs_table ():
48
+ def _valid_plot_kwargs ():
50
49
'''
51
50
Construct and return the "valid kwargs table" for the mplfinance.plot() function.
52
51
A valid kwargs table is a `dict` of `dict`s. The keys of the outer dict are the
53
52
valid key-words for the function. The value for each key is a dict containing
54
- 3 specific keys: "Default", "Implemented ", and "Validator" with the following values:
53
+ 2 specific keys: "Default", and "Validator" with the following values:
55
54
"Default" - The default value for the kwarg if none is specified.
56
- "Implemented" - Boolean, has this kwarg been implemented or not.
57
- NOTE: A non-implemented kwarg will still be present in the
58
- configuration dict, along with the kwarg's default value.
59
55
"Validator" - A function that takes the caller specified value for the kwarg,
60
56
and validates that it is the correct type, and (for kwargs with
61
57
a limited set of allowed values) may also validate that the
62
58
kwarg value is one of the allowed values.
63
59
'''
60
+
64
61
vkwargs = {
65
62
'type' : { 'Default' : 'ohlc' ,
66
-
67
- 'Implemented' : True ,
68
63
'Validator' : lambda value : value in ['candle' ,'candlestick' ,'ohlc' ,'bars' ,'ohlc bars' ,'line' ] },
69
64
70
65
'style' : { 'Default' : 'default' ,
71
-
72
- 'Implemented' : True ,
73
66
'Validator' : lambda value : value in _styles .available_styles () or isinstance (value ,dict ) },
74
67
75
68
'volume' : { 'Default' : False ,
76
-
77
- 'Implemented' : True ,
78
69
'Validator' : lambda value : isinstance (value ,bool ) },
79
70
80
71
'mav' : { 'Default' : None ,
81
-
82
- 'Implemented' : True ,
83
72
'Validator' : _mav_validator },
84
73
85
74
'study' : { 'Default' : None ,
86
-
87
- 'Implemented' : False ,
88
75
'Validator' : lambda value : isinstance (value ,dict ) }, #{'studyname': {study parms}} example: {'TE':{'mav':20,'upper':2,'lower':2}}
89
76
90
77
'marketcolors' : { 'Default' : None , # use 'style' for default, instead.
91
-
92
- 'Implemented' : True ,
93
78
'Validator' : lambda value : isinstance (value ,dict ) },
94
79
95
80
'no_xgaps' : { 'Default' : True , # None means follow default logic below:
96
- # True for intraday data spanning 2 or more days, else False
97
- 'Implemented' : True ,
98
81
'Validator' : lambda value : _warn_no_xgaps_deprecated (value ) },
99
82
100
- 'show_nontrading' : { 'Default' : False , # None means follow default logic below:
101
- # True for intraday data spanning 2 or more days, else False
102
- 'Implemented' : True ,
83
+ 'show_nontrading' : { 'Default' : False ,
103
84
'Validator' : lambda value : isinstance (value ,bool ) },
104
85
105
86
'figscale' : { 'Default' : 1.0 , # scale base figure size up or down.
106
-
107
- 'Implemented' : True ,
108
87
'Validator' : lambda value : isinstance (value ,float ) or isinstance (value ,int ) },
109
88
110
- 'figratio' : { 'Default' : (8.00 ,5.75 ), # aspect ratio; will equal fig size when figscale=1.0
111
-
112
- 'Implemented' : True ,
89
+ 'figratio' : { 'Default' : (8.00 ,5.75 ), # aspect ratio; will equal fig size when figscale=1.0
113
90
'Validator' : lambda value : isinstance (value ,(tuple ,list ))
114
91
and len (value ) == 2
115
92
and isinstance (value [0 ],(float ,int ))
116
93
and isinstance (value [1 ],(float ,int )) },
117
94
118
- 'title' : { 'Default' : None , # Plot Title
119
-
120
- 'Implemented' : True ,
95
+ 'title' : { 'Default' : None , # Plot Title
121
96
'Validator' : lambda value : isinstance (value ,str ) },
122
97
123
- 'ylabel' : { 'Default' : 'Price' , # y-axis label
124
-
125
- 'Implemented' : True ,
98
+ 'ylabel' : { 'Default' : 'Price' , # y-axis label
126
99
'Validator' : lambda value : isinstance (value ,str ) },
127
100
128
- 'ylabel_lower' : { 'Default' : None , # y-axis label default logic below
129
-
130
- 'Implemented' : True ,
101
+ 'ylabel_lower' : { 'Default' : None , # y-axis label default logic below
131
102
'Validator' : lambda value : isinstance (value ,str ) },
132
103
133
- 'xlabel' : { 'Default' : None , # x-axis label, default is None because obvious it's time or date
134
-
135
- 'Implemented' : False , # x-axis label, NOT implemented because obvious it's time or date (will see if users ask for it).
136
- 'Validator' : lambda value : isinstance (value ,str ) },
104
+ #'xlabel' : { 'Default' : None, # x-axis label, default is None because obvious it's time or date
105
+ # 'Validator' : lambda value: isinstance(value,str) },
137
106
138
107
'addplot' : { 'Default' : None ,
139
-
140
- 'Implemented' : True ,
141
108
'Validator' : lambda value : isinstance (value ,dict ) or (isinstance (value ,list ) and all ([isinstance (d ,dict ) for d in value ])) },
142
109
143
110
'savefig' : { 'Default' : None ,
144
-
145
- 'Implemented' : True ,
146
111
'Validator' : lambda value : isinstance (value ,dict ) or isinstance (value ,str ) },
147
112
148
113
'block' : { 'Default' : True ,
149
-
150
- 'Implemented' : True ,
151
114
'Validator' : lambda value : isinstance (value ,bool ) },
152
115
153
116
}
154
- # Check that we didn't make a typo in any of the things above:
155
- # that should otherwise be the same for all kwags:
156
- for key , value in vkwargs .items ():
157
- if len (value ) != 3 :
158
- raise ValueError ('Items != 3 in valid kwarg table, for kwarg "' + key + '"' )
159
- if 'Default' not in value :
160
- raise ValueError ('Missing "Default" value for kwarg "' + key + '"' )
161
- if 'Implemented' not in value :
162
- raise ValueError ('Missing "Implemented" flag for kwarg "' + key + '"' )
163
- if 'Validator' not in value :
164
- raise ValueError ('Missing "Validator" function for kwarg "' + key + '"' )
165
- if value ['Implemented' ] not in [True ,False ]:
166
- raise ValueError ('"Implemented" flag NOT True or False for kwarg "' + key + '"' )
117
+
118
+ _validate_vkwargs_dict (vkwargs )
167
119
168
120
return vkwargs
169
121
@@ -195,7 +147,7 @@ def plot( data, **kwargs ):
195
147
196
148
dates ,opens ,highs ,lows ,closes ,volumes = _check_and_prepare_data (data )
197
149
198
- config = _process_kwargs (kwargs , _valid_kwargs_table ())
150
+ config = _process_kwargs (kwargs , _valid_plot_kwargs ())
199
151
200
152
style = config ['style' ]
201
153
if isinstance (style ,str ):
@@ -510,7 +462,7 @@ def plot( data, **kwargs ):
510
462
511
463
512
464
513
- def _valid_addplot_kwargs_table ():
465
+ def _valid_addplot_kwargs ():
514
466
515
467
valid_markers = ['.' , ',' , 'o' , 'v' , '^' , '<' , '>' , '1' , '2' , '3' , '4' , '8' ,
516
468
's' , 'p' , '*' , 'h' , 'H' , '+' , 'x' , 'D' , 'd' , '|' , '_' , 'P' ,
@@ -519,49 +471,31 @@ def _valid_addplot_kwargs_table():
519
471
520
472
valid_linestyles = ['-' ,'solid' ,'--' ,'dashed' ,'-.' ,'dashdot' ,'.' ,'dotted' ,None ,' ' ,'' ]
521
473
474
+
522
475
vkwargs = {
523
476
'scatter' : { 'Default' : False ,
524
- 'Implemented' : True ,
525
477
'Validator' : lambda value : isinstance (value ,bool ) },
526
478
527
479
'panel' : { 'Default' : 'main' ,
528
- 'Implemented' : True ,
529
480
'Validator' : lambda value : value in ['main' ,'lower' ] },
530
481
531
482
'marker' : { 'Default' : 'o' ,
532
- 'Implemented' : True ,
533
483
'Validator' : lambda value : value in valid_markers },
534
484
535
485
'markersize' : { 'Default' : 18 ,
536
- 'Implemented' : True ,
537
486
'Validator' : lambda value : isinstance (value ,(int ,float )) },
538
487
539
488
'color' : { 'Default' : None ,
540
- 'Implemented' : True ,
541
489
'Validator' : lambda value : mcolors .is_color_like (value ) },
542
490
543
491
'linestyle' : { 'Default' : None ,
544
- 'Implemented' : True ,
545
492
'Validator' : lambda value : value in valid_linestyles },
546
493
547
494
'secondary_y' : { 'Default' : 'auto' ,
548
- 'Implemented' : True ,
549
495
'Validator' : lambda value : isinstance (value ,bool ) or value == 'auto' }
550
496
}
551
497
552
- # Check that we didn't make a typo in any of the things above
553
- # that should otherwise be the same for all kwags:
554
- for key , value in vkwargs .items ():
555
- if len (value ) != 3 :
556
- raise ValueError ('Items != 3 in valid kwarg table, for kwarg "' + key + '"' )
557
- if 'Default' not in value :
558
- raise ValueError ('Missing "Default" value for kwarg "' + key + '"' )
559
- if 'Implemented' not in value :
560
- raise ValueError ('Missing "Implemented" flag for kwarg "' + key + '"' )
561
- if 'Validator' not in value :
562
- raise ValueError ('Missing "Validator" function for kwarg "' + key + '"' )
563
- if value ['Implemented' ] not in [True ,False ]:
564
- raise ValueError ('"Implemented" flag NOT True or False for kwarg "' + key + '"' )
498
+ _validate_vkwargs_dict (vkwargs )
565
499
566
500
return vkwargs
567
501
@@ -576,6 +510,6 @@ def make_addplot(data, **kwargs):
576
510
if not isinstance (data , (pd .Series , pd .DataFrame , np .ndarray , list )):
577
511
raise TypeError ('Wrong type for data, in make_addplot()' )
578
512
579
- config = _process_kwargs (kwargs , _valid_addplot_kwargs_table ())
513
+ config = _process_kwargs (kwargs , _valid_addplot_kwargs ())
580
514
581
515
return dict ( data = data , ** config )
0 commit comments