Skip to content

Commit 662d913

Browse files
xlim is working with dates
1 parent 583aac7 commit 662d913

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

examples/scratch_pad/date_to_iloc_extrapolation.ipynb

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

src/mplfinance/_arg_validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def _is_datelike(value):
143143
def _xlim_validator(value):
144144
return (isinstance(value, (list,tuple)) and len(value) == 2
145145
and (all([isinstance(v,(int,float)) for v in value])
146-
or all([_is_date_like(v) for v in value])))
146+
or all([_is_datelike(v) for v in value])))
147147

148148
def _vlines_validator(value):
149149
'''Validate `vlines` kwarg value: must be "datelike" or sequence of "datelike"

src/mplfinance/_utils.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from mplfinance._arg_validators import _process_kwargs, _validate_vkwargs_dict
1717
from mplfinance._arg_validators import _alines_validator, _bypass_kwarg_validation
18+
from mplfinance._arg_validators import _xlim_validator, _is_datelike
1819
from mplfinance._styles import _get_mpfstyle
1920

2021
from six.moves import zip
@@ -75,7 +76,7 @@ def _check_and_convert_xlim_configuration(data, config):
7576
if not _xlim_validator(xlim):
7677
raise ValueError('Bad xlim configuration #1')
7778

78-
if all([_is_date_like(dt) for dt in xlim]):
79+
if all([_is_datelike(dt) for dt in xlim]):
7980
if config['show_nontrading']:
8081
xlim = [ _date_to_mdate(dt) for dt in xlim]
8182
else:
@@ -222,8 +223,10 @@ def _date_to_iloc(dtseries,date):
222223
return (loc1+loc2)/2.0
223224

224225
def _date_to_iloc_linear(dtseries,date,trace=False):
225-
'''Find the slope and yintercept for the line:
226-
iloc = (slope)*(date) + (yintercept)
226+
'''Find the location of a date using linear extrapolation.
227+
Use the endpoints of `dtseriews` to the slope and yintercept
228+
for the line: iloc = (slope)*(dtseries) + (yintercept)
229+
The use them to calculate the location of `date`
227230
'''
228231
d1 = _date_to_mdate(dtseries.index[0])
229232
d2 = _date_to_mdate(dtseries.index[-1])

0 commit comments

Comments
 (0)