Skip to content

Commit 6e6421c

Browse files
committed
Added description fields in remaining kwarg dicts
1 parent 4896efa commit 6e6421c

File tree

6 files changed

+158
-68
lines changed

6 files changed

+158
-68
lines changed

TODO.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
- documentation (replace old `https://matplotlib.org/api/finance_api.html`)
1010
- make code more efficient (ex: tlines reconstructing data frame).
1111
- **daily plot slower than intraday ???**
12-
- add 'description' to valid kwargs table, and kwarg to print all kwargs information (kwarg and short description).
12+
- add kwarg to print all kwargs information (kwarg and short description).
13+
- fill the 'Description' fields in the kwarg dicts of these functions: `egrep -i 'def .*valid.*kwarg' *.py`
1314

src/mplfinance/_arg_validators.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ def _validate_vkwargs_dict(vkwargs):
286286
raise ValueError('Items != 3 in valid kwarg table, for kwarg "'+key+'"')
287287
if 'Default' not in value:
288288
raise ValueError('Missing "Default" value for kwarg "'+key+'"')
289+
if 'Description' not in value:
290+
raise ValueError('Missing "Description" value for kwarg "'+key+'"')
289291
if 'Validator' not in value:
290292
raise ValueError('Missing "Validator" function for kwarg "'+key+'"')
291293

src/mplfinance/_styles.py

Lines changed: 68 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -61,54 +61,70 @@ def _apply_mpfstyle(style):
6161
def _valid_make_mpf_style_kwargs():
6262
vkwargs = {
6363
'base_mpf_style': { 'Default' : None,
64+
'Description' : '',
6465
'Validator' : lambda value: value in _styles.keys() },
6566

6667
'base_mpl_style': { 'Default' : None,
68+
'Description' : '',
6769
'Validator' : lambda value: isinstance(value,str) }, # and is in plt.style.available
6870

69-
'marketcolors' : { 'Default' : None, #
71+
'marketcolors' : { 'Default' : None,
72+
'Description' : '',
7073
'Validator' : lambda value: isinstance(value,dict) },
7174

7275
'mavcolors' : { 'Default' : None,
76+
'Description' : '',
7377
'Validator' : lambda value: isinstance(value,list) }, # TODO: all([mcolors.is_color_like(v) for v in value.values()])
7478

7579
'facecolor' : { 'Default' : None,
80+
'Description' : '',
7681
'Validator' : lambda value: isinstance(value,str) },
7782

7883
'edgecolor' : { 'Default' : None,
84+
'Description' : '',
7985
'Validator' : lambda value: isinstance(value,str) },
8086

8187
'figcolor' : { 'Default' : None,
88+
'Description' : '',
8289
'Validator' : lambda value: isinstance(value,str) },
8390

8491
'gridcolor' : { 'Default' : None,
92+
'Description' : '',
8593
'Validator' : lambda value: isinstance(value,str) },
8694

8795
'gridstyle' : { 'Default' : None,
96+
'Description' : '',
8897
'Validator' : lambda value: isinstance(value,str) },
8998

9099
'gridaxis' : { 'Default' : None,
100+
'Description' : '',
91101
'Validator' : lambda value: value in [ 'vertical'[0:len(value)], 'horizontal'[0:len(value)], 'both'[0:len(value)] ] },
92102

93103
'y_on_right' : { 'Default' : None,
104+
'Description' : '',
94105
'Validator' : lambda value: isinstance(value,bool) },
95106

96107
'rc' : { 'Default' : None,
108+
'Description' : '',
97109
'Validator' : lambda value: isinstance(value,dict) },
98110

99111
'legacy_rc' : { 'Default' : None, # Just in case someone depended upon old behavior
112+
'Description' : '',
100113
'Validator' : lambda value: isinstance(value,dict) },
101114

102115
'style_name' : { 'Default' : None,
103116
'Validator' : lambda value: isinstance(value,str) },
104117

105118
}
119+
106120
_validate_vkwargs_dict(vkwargs)
121+
107122
return vkwargs
108123

124+
109125
def available_styles():
110126
return list(_styles.keys())
111-
127+
112128
def make_mpf_style( **kwargs ):
113129
config = _process_kwargs(kwargs, _valid_make_mpf_style_kwargs())
114130
if config['rc'] is not None and config['legacy_rc'] is not None:
@@ -187,51 +203,66 @@ def _valid_mpf_style(value):
187203
return False
188204
return True
189205

206+
190207
def _valid_make_marketcolors_kwargs():
191208
vkwargs = {
192-
'up' : { 'Default' : None,
193-
'Validator' : lambda value: mcolors.is_color_like(value) },
194-
195-
'down' : { 'Default' : None,
196-
'Validator' : lambda value: mcolors.is_color_like(value) },
197-
198-
'hollow' : { 'Default' : None,
199-
'Validator' : lambda value: mcolors.is_color_like(value) },
200-
201-
'alpha' : { 'Default' : None,
202-
'Validator' : lambda value: ( isinstance(value,float) and
203-
0.0 <= value and 1.0 >= value ) },
204-
205-
'edge' : { 'Default' : None,
206-
'Validator' : lambda value: _valid_mpf_color_spec(value) },
207-
208-
'wick' : { 'Default' : None,
209-
'Validator' : lambda value: isinstance(value,dict)
210-
or isinstance(value,str)
211-
or mcolors.is_color_like(value) },
212-
213-
'ohlc' : { 'Default' : None,
214-
'Validator' : lambda value: isinstance(value,dict)
215-
or isinstance(value,str)
216-
or mcolors.is_color_like(value) },
217-
218-
'volume' : { 'Default' : None,
219-
'Validator' : lambda value: isinstance(value,dict)
220-
or isinstance(value,str)
221-
or mcolors.is_color_like(value) },
222-
223-
'vcdopcod' : { 'Default' : False,
224-
'Validator' : lambda value: isinstance(value,bool) },
209+
'up' : { 'Default' : None,
210+
'Description' : '',
211+
'Validator' : lambda value: mcolors.is_color_like(value) },
212+
213+
'down' : { 'Default' : None,
214+
'Description' : '',
215+
'Validator' : lambda value: mcolors.is_color_like(value) },
216+
217+
'hollow' : { 'Default' : None,
218+
'Description' : '',
219+
'Validator' : lambda value: mcolors.is_color_like(value) },
220+
221+
'alpha' : { 'Default' : None,
222+
'Description' : '',
223+
'Validator' : lambda value: (isinstance(value,float)
224+
and 0.0 <= value and 1.0 >= value ) },
225+
226+
'edge' : { 'Default' : None,
227+
'Description' : '',
228+
'Validator' : lambda value: _valid_mpf_color_spec(value) },
229+
230+
'wick' : { 'Default' : None,
231+
'Description' : '',
232+
'Validator' : lambda value: isinstance(value,dict)
233+
or isinstance(value,str)
234+
or mcolors.is_color_like(value) },
235+
236+
'ohlc' : { 'Default' : None,
237+
'Description' : '',
238+
'Validator' : lambda value: isinstance(value,dict)
239+
or isinstance(value,str)
240+
or mcolors.is_color_like(value) },
241+
242+
'volume' : { 'Default' : None,
243+
'Description' : '',
244+
'Validator' : lambda value: isinstance(value,dict)
245+
or isinstance(value,str)
246+
or mcolors.is_color_like(value) },
247+
248+
'vcdopcod' : { 'Default' : False,
249+
'Description' : '',
250+
'Validator' : lambda value: isinstance(value,bool) },
225251

226-
'inherit' : { 'Default' : False,
227-
'Validator' : lambda value: isinstance(value,bool) },
252+
'inherit' : { 'Default' : False,
253+
'Description' : '',
254+
'Validator' : lambda value: isinstance(value,bool) },
228255

229256
'base_mpf_style': { 'Default' : None,
257+
'Description' : '',
230258
'Validator' : lambda value: isinstance(value,str) },
231259
}
260+
232261
_validate_vkwargs_dict(vkwargs)
262+
233263
return vkwargs
234264

265+
235266
def make_marketcolors(**kwargs):
236267
'''
237268
Create a 'marketcolors' dict that is structured as expected

src/mplfinance/_utils.py

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -355,58 +355,73 @@ def _valid_renko_kwargs():
355355
'''
356356
Construct and return the "valid renko kwargs table" for the mplfinance.plot(type='renko')
357357
function. A valid kwargs table is a `dict` of `dict`s. The keys of the outer dict are
358-
the valid key-words for the function. The value for each key is a dict containing 2
359-
specific keys: "Default", and "Validator" with the following values:
358+
the valid key-words for the function. The value for each key is a dict containing 3
359+
specific keys: "Default", "Description" and "Validator" with the following values:
360360
"Default" - The default value for the kwarg if none is specified.
361+
"Description" - The description for the kwarg.
361362
"Validator" - A function that takes the caller specified value for the kwarg,
362363
and validates that it is the correct type, and (for kwargs with
363364
a limited set of allowed values) may also validate that the
364365
kwarg value is one of the allowed values.
365366
'''
366367
vkwargs = {
367368
'brick_size' : { 'Default' : 'atr',
368-
'Validator' : lambda value: isinstance(value,(float,int)) or value == 'atr' },
369+
'Description' : '',
370+
'Validator' : lambda value: isinstance(value,(float,int))
371+
or value == 'atr' },
369372
'atr_length' : { 'Default' : 14,
370-
'Validator' : lambda value: isinstance(value,int) or value == 'total' },
373+
'Description' : '',
374+
'Validator' : lambda value: isinstance(value,int)
375+
or value == 'total' },
371376
}
372377

373378
_validate_vkwargs_dict(vkwargs)
374379

375380
return vkwargs
376381

382+
377383
def _valid_pnf_kwargs():
378384
'''
379385
Construct and return the "valid pnf kwargs table" for the mplfinance.plot(type='pnf')
380386
function. A valid kwargs table is a `dict` of `dict`s. The keys of the outer dict are
381-
the valid key-words for the function. The value for each key is a dict containing 2
382-
specific keys: "Default", and "Validator" with the following values:
387+
the valid key-words for the function. The value for each key is a dict containing 3
388+
specific keys: "Default", "Description" and "Validator" with the following values:
383389
"Default" - The default value for the kwarg if none is specified.
390+
"Description" - The description for the kwarg.
384391
"Validator" - A function that takes the caller specified value for the kwarg,
385392
and validates that it is the correct type, and (for kwargs with
386393
a limited set of allowed values) may also validate that the
387394
kwarg value is one of the allowed values.
388395
'''
389396
vkwargs = {
390397
'box_size' : { 'Default' : 'atr',
391-
'Validator' : lambda value: isinstance(value,(float,int)) or value == 'atr' },
398+
'Description' : '',
399+
'Validator' : lambda value: isinstance(value,(float,int))
400+
or value == 'atr' },
392401
'atr_length' : { 'Default' : 14,
393-
'Validator' : lambda value: isinstance(value,int) or value == 'total' },
402+
'Description' : '',
403+
'Validator' : lambda value: isinstance(value,int)
404+
or value == 'total' },
405+
394406
'reversal' : { 'Default' : 1,
395-
'Validator' : lambda value: isinstance(value,int) }
407+
'Description' : '',
408+
'Validator' : lambda value: isinstance(value,int) },
396409
}
397410

398411
_validate_vkwargs_dict(vkwargs)
399412

400413
return vkwargs
401414

415+
402416
def _valid_lines_kwargs():
403417
'''
404418
Construct and return the "valid lines (hlines,vlines,alines,tlines) kwargs table"
405419
for the mplfinance.plot() `[h|v|a|t]lines=` kwarg functions.
406420
A valid kwargs table is a `dict` of `dict`s. The keys of the outer dict are
407-
the valid key-words for the function. The value for each key is a dict containing 2
408-
specific keys: "Default", and "Validator" with the following values:
421+
the valid key-words for the function. The value for each key is a dict containing 3
422+
specific keys: "Default", "Description" and "Validator" with the following values:
409423
"Default" - The default value for the kwarg if none is specified.
424+
"Description" - The description for the kwarg.
410425
"Validator" - A function that takes the caller specified value for the kwarg,
411426
and validates that it is the correct type, and (for kwargs with
412427
a limited set of allowed values) may also validate that the
@@ -415,32 +430,53 @@ def _valid_lines_kwargs():
415430
valid_linestyles = ['-','solid','--','dashed','-.','dashdot',':','dotted',None,' ','']
416431
vkwargs = {
417432
'hlines' : { 'Default' : None,
433+
'Description' : '',
418434
'Validator' : _bypass_kwarg_validation },
435+
419436
'vlines' : { 'Default' : None,
437+
'Description' : '',
420438
'Validator' : _bypass_kwarg_validation },
439+
421440
'alines' : { 'Default' : None,
441+
'Description' : '',
422442
'Validator' : _bypass_kwarg_validation },
443+
423444
'tlines' : { 'Default' : None,
445+
'Description' : '',
424446
'Validator' : _bypass_kwarg_validation },
447+
425448
'colors' : { 'Default' : None,
426-
'Validator' : lambda value: value is None or
427-
mcolors.is_color_like(value) or
428-
( isinstance(value,(list,tuple)) and
429-
all([mcolors.is_color_like(v) for v in value]) ) },
449+
'Description' : '',
450+
'Validator' : lambda value: value is None
451+
or mcolors.is_color_like(value)
452+
or (isinstance(value,(list,tuple))
453+
and all([mcolors.is_color_like(v) for v in value]) ) },
454+
430455
'linestyle' : { 'Default' : '-',
431-
'Validator' : lambda value: value is None or value in valid_linestyles },
456+
'Description' : '',
457+
'Validator' : lambda value: value is None
458+
or value in valid_linestyles },
459+
432460
'linewidths': { 'Default' : None,
433-
'Validator' : lambda value: value is None or
434-
isinstance(value,(float,int)) or
435-
all([isinstance(v,(float,int)) for v in value]) },
461+
'Description' : '',
462+
'Validator' : lambda value: value is None
463+
or isinstance(value,(float,int))
464+
or all([isinstance(v,(float,int)) for v in value]) },
465+
436466
'alpha' : { 'Default' : 1.0,
467+
'Description' : '',
437468
'Validator' : lambda value: isinstance(value,(float,int)) },
438469

439-
'tline_use' : { 'Default' : 'close',
440-
'Validator' : lambda value: isinstance(value,str) or (isinstance(value,(list,tuple)) and
441-
all([isinstance(v,str) for v in value]) ) },
442-
'tline_method': { 'Default' : 'point-to-point',
443-
'Validator' : lambda value: value in ['point-to-point','least-squares'] }
470+
471+
'tline_use' : { 'Default' : 'close',
472+
'Description' : '',
473+
'Validator' : lambda value: isinstance(value,str)
474+
or (isinstance(value,(list,tuple))
475+
and all([isinstance(v,str) for v in value]) ) },
476+
477+
'tline_method': { 'Default' : 'point-to-point',
478+
'Description' : '',
479+
'Validator' : lambda value: value in ['point-to-point','least-squares'] }
444480
}
445481

446482
_validate_vkwargs_dict(vkwargs)

0 commit comments

Comments
 (0)