Skip to content

Commit 51e66ce

Browse files
Merge pull request #299 from DanielGoldfarb/master
Fix timezone bug (issue 236)
2 parents 51b2482 + 150816f commit 51e66ce

File tree

6 files changed

+467
-581
lines changed

6 files changed

+467
-581
lines changed

examples/scratch_pad/issue296.a.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@
1212
idf.shape
1313
idf.head(3)
1414
idf.tail(3)
15-
df = idf.loc['2011-07-01':'2011-12-30',:]
15+
# df = idf.loc['2011-07-01':'2011-12-30',:]
1616

17-
# df.loc[:,'Volume'] *= (0.003*0.9869459423651993)
18-
# df.loc[:,'Volume'] *= (0.003*0.9869459423651994)
19-
# df.loc[:,'Volume'] *= (0.003*90000000000000.)
20-
# df.loc[:,'Volume'] *= (0.003*90000000000.)
21-
# df.loc[:,'Volume'] *= (0.003*90000000.)
22-
# df.loc[:,'Volume'] *= (0.003*900000.)
23-
# df.loc[:,'Volume'] *= (0.003*30000.)
24-
# df.loc[:,'Volume'] *= (0.003*3000.)
25-
# df.loc[:,'Volume'] *= (0.003*300.)
26-
# df.loc[:,'Volume'] *= (0.003*30.)
27-
# df.loc[:,'Volume'] *= (0.003*10.)
28-
# df.loc[:,'Volume'] *= (0.003*1.0)
29-
# df.loc[:,'Volume'] *= (0.003*0.1)
30-
# df.loc[:,'Volume'] *= (0.003*0.01)
31-
df.loc[:,'Volume'] *= (0.003*0.001)
17+
factors = [0.9869459423651993, 0.9869459423651994, 90000000000000., 90000000000.,
18+
90000000., 900000., 30000., 3000., 300., 30., 10., 1.0, 0.1, 0.01, 0.001 ]
3219

33-
vmin = np.nanmin(df.iloc[0:20]['Volume'])
34-
vmax = np.nanmax(df.iloc[0:20]['Volume'])
20+
# factors = [0.9869459423651993,]
3521

36-
print('vmin=',vmin,' vmax=',vmax)
22+
for factor in factors:
23+
df = idf.loc['2011-07-01':'2011-12-30',:]
24+
df.loc[:,'Volume'] *= (0.003*factor)
25+
vmin = np.nanmin(df.iloc[0:20]['Volume'])
26+
vmax = np.nanmax(df.iloc[0:20]['Volume'])
27+
print('vmin=',vmin,' vmax=',vmax)
28+
mpf.plot(df.iloc[0:20],volume=True,type='candle')
3729

38-
mpf.plot(df.iloc[0:20],volume=True,type='candle')
30+
df = idf.loc['2011-07-01':'2011-12-30',:]
31+
df.loc[:,'Volume'] *= (0.003*30000.)
32+
mpf.plot(df.iloc[0:20],volume=True,type='candle',volume_exponent='legacy')
33+
mpf.plot(df.iloc[0:20],volume=True,type='candle',volume_exponent=3)
34+
mpf.plot(df.iloc[0:20],volume=True,type='candle',volume_exponent=5)
35+
mpf.plot(df.iloc[0:20],volume=True,type='candle',volume_exponent=8)
36+
mpf.plot(df.iloc[0:20],volume=True,type='candle',volume_exponent=11)
37+
mpf.plot(df.iloc[0:20],volume=True,type='candle',volume_exponent=13)
38+
mpf.plot(df.iloc[0:20],volume=True,type='candle',volume_exponent='what?')

examples/scratch_pad/issues/issue#236_timezone_bug.ipynb

Lines changed: 0 additions & 559 deletions
This file was deleted.

examples/scratch_pad/issues/issue236_timezone_bug.ipynb

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

src/mplfinance/_arg_validators.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ def _check_and_prepare_data(data, config):
4040
o, h, l, c, v = columns
4141
cols = [o, h, l, c]
4242

43-
dates = mdates.date2num(data.index.to_pydatetime())
43+
if config['tz_localize']:
44+
dates = mdates.date2num(data.index.tz_localize(None).to_pydatetime())
45+
else: # Just in case someone was depending on this bug (Issue 236)
46+
dates = mdates.date2num(data.index.to_pydatetime())
4447
opens = data[o].values
4548
highs = data[h].values
4649
lows = data[l].values

src/mplfinance/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
version_info = (0, 12, 7, 'alpha', 3)
2+
version_info = (0, 12, 7, 'alpha', 4)
33

44
_specifier_ = {'alpha': 'a','beta': 'b','candidate': 'rc','final': ''}
55

src/mplfinance/plotting.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ def _valid_plot_kwargs():
256256

257257
'volume_exponent' : { 'Default' : None,
258258
'Validator' : lambda value: isinstance(value,int) or value == 'legacy'},
259+
260+
'tz_localize' : { 'Default' : True,
261+
'Validator' : lambda value: isinstance(value,bool) },
259262
}
260263

261264
_validate_vkwargs_dict(vkwargs)

0 commit comments

Comments
 (0)