File tree 3 files changed +24
-3
lines changed
3 files changed +24
-3
lines changed Original file line number Diff line number Diff line change 26
26
# The record array stores python datetime.date as an object array in
27
27
# the date column
28
28
datafile = cbook .get_sample_data ('goog.npy' )
29
- r = np .load (datafile ).view (np .recarray )
29
+ try :
30
+ # Python3 cannot load python2 .npy files with datetime(object) arrays
31
+ # unless the encoding is set to bytes. Hovever this option was
32
+ # not added until numpy 1.10 so this example will only work with
33
+ # python 2 or with numpy 1.10 and later.
34
+ r = np .load (datafile , encoding = 'bytes' ).view (np .recarray )
35
+ except TypeError :
36
+ r = np .load (datafile ).view (np .recarray )
30
37
31
38
fig , ax = plt .subplots ()
32
39
ax .plot (r .date , r .adj_close )
Original file line number Diff line number Diff line change 20
20
21
21
# load some financial data; apple's stock price
22
22
fh = cbook .get_sample_data ('aapl.npy.gz' )
23
- r = np .load (fh )
23
+ try :
24
+ # Python3 cannot load python2 .npy files with datetime(object) arrays
25
+ # unless the encoding is set to bytes. Hovever this option was
26
+ # not added until numpy 1.10 so this example will only work with
27
+ # python 2 or with numpy 1.10 and later.
28
+ r = np .load (fh , encoding = 'bytes' )
29
+ except TypeError :
30
+ r = np .load (fh )
24
31
fh .close ()
25
32
r = r [- 250 :] # get the last 250 days
26
33
Original file line number Diff line number Diff line change 10
10
# The record array stores python datetime.date as an object array in
11
11
# the date column
12
12
datafile = cbook .get_sample_data ('goog.npy' )
13
- price_data = np .load (datafile ).view (np .recarray )
13
+ try :
14
+ # Python3 cannot load python2 .npy files with datetime(object) arrays
15
+ # unless the encoding is set to bytes. Hovever this option was
16
+ # not added until numpy 1.10 so this example will only work with
17
+ # python 2 or with numpy 1.10 and later
18
+ price_data = np .load (datafile , encoding = 'bytes' ).view (np .recarray )
19
+ except TypeError :
20
+ price_data = np .load (datafile ).view (np .recarray )
14
21
price_data = price_data [- 250 :] # get the most recent 250 trading days
15
22
16
23
delta1 = np .diff (price_data .adj_close )/ price_data .adj_close [:- 1 ]
You can’t perform that action at this time.
0 commit comments