Skip to content

Commit 9acc0d0

Browse files
addisonlynchbashtage
authored andcommitted
Repaired Morningstar volume for indicies (#488)
Repaired Morningstar volume for indicies
1 parent f3d754c commit 9acc0d0

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

docs/source/whatsnew/v0.7.0.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ Bug Fixes
2828

2929
- Added support for passing the API KEY to QuandlReader either directly or by
3030
setting the environmental variable QUANDL_API_KEY (:issue:`485`).
31+
- Handle Morningstar index volume data properly (:issue:`486`).

pandas_datareader/mstar/daily.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import requests
66
from pandas import DataFrame
7+
import numpy as np
78

89
from pandas_datareader._utils import SymbolWarning
910
from pandas_datareader.base import _BaseReader
@@ -161,7 +162,10 @@ def _restruct_json(self, symbol, jsondata):
161162

162163
pricedata = jsondata["PriceDataList"][0]["Datapoints"]
163164
dateidx = jsondata["PriceDataList"][0]["DateIndexs"]
164-
volumes = jsondata["VolumeList"]["Datapoints"]
165+
if jsondata["VolumeList"]:
166+
volumes = jsondata["VolumeList"]["Datapoints"]
167+
else:
168+
volumes = None
165169

166170
dates = self._convert_index2date(indexvals=dateidx)
167171
barss = []
@@ -192,7 +196,10 @@ def _restruct_json(self, symbol, jsondata):
192196
else:
193197
pass
194198
if self.incl_vol is True:
195-
bardict.update({"Volume": int(volumes[p] * 1000000)})
199+
if volumes is None:
200+
bardict.update({"Volume": np.nan})
201+
else:
202+
bardict.update({"Volume": int(volumes[p] * 1000000)})
196203
else:
197204
pass
198205

0 commit comments

Comments
 (0)