Skip to content

Commit 517260f

Browse files
committed
Fixes
Fixes problems in: - FamaFrenchReader with encoding one file - YahooDailyReader will now return a a DataFrame of nans when a single symbol has no data
1 parent ab26ad2 commit 517260f

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

pandas_datareader/famafrench.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,11 @@ def _read_zipfile(self, url):
5656

5757
with tempfile.TemporaryFile() as tmpf:
5858
tmpf.write(raw)
59-
6059
with ZipFile(tmpf, "r") as zf:
61-
data = zf.open(zf.namelist()[0]).read().decode()
62-
60+
try:
61+
data = zf.open(zf.namelist()[0]).read().decode()
62+
except UnicodeDecodeError:
63+
data = zf.open(zf.namelist()[0]).read().decode(encoding="cp1252")
6364
return data
6465

6566
def read(self):

pandas_datareader/yahoo/daily.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import re
55
import time
66

7-
from pandas import DataFrame, isnull, notnull, to_datetime
7+
from pandas import DataFrame, date_range, isnull, notnull, to_datetime
88

99
from pandas_datareader._utils import RemoteDataError
1010
from pandas_datareader.base import _DailyBaseReader
@@ -157,6 +157,15 @@ def _read_one_data(self, url, params):
157157

158158
# price data
159159
prices = DataFrame(data["prices"])
160+
if len(prices) == 0:
161+
freq = self.interval[1].upper()
162+
if freq == 'W':
163+
freq += '-MON'
164+
dates = date_range(self.start, self.end, freq=freq)
165+
prices = DataFrame(index=dates,
166+
columns=['High', 'Low', 'Open', 'Close', 'Volume', 'Adj Close'])
167+
return prices
168+
160169
prices.columns = [col.capitalize() for col in prices.columns]
161170
prices["Date"] = to_datetime(to_datetime(prices["Date"], unit="s").dt.date)
162171

0 commit comments

Comments
 (0)