Skip to content

Commit 7522f75

Browse files
authored
Merge pull request #602 from peijiche/master
Fixed two dividend related issues
2 parents 4ff9a3e + ac49e27 commit 7522f75

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

pandas_datareader/tests/yahoo/test_yahoo.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,24 @@ def test_yahoo_DataReader(self):
278278
exp.index.name = 'Date'
279279
tm.assert_frame_equal(result.reindex_like(exp).round(5), exp.round(5))
280280

281+
282+
# test cases with "1/0" split ratio in actions- no split, just chnage symbol from POT to NTR
283+
start = datetime(2017, 12, 30)
284+
end = datetime(2018, 12, 30)
285+
286+
result = web.DataReader('NTR', 'yahoo-actions', start, end)
287+
288+
exp_idx = pd.DatetimeIndex(['2018-12-28', '2018-09-27',
289+
'2018-06-28', '2018-03-28',
290+
'2018-01-02'])
291+
292+
exp = pd.DataFrame({'action': ['DIVIDEND', 'DIVIDEND', 'DIVIDEND',
293+
'DIVIDEND', 'SPLIT'],
294+
'value': [0.43, 0.40, 0.40, 0.40, 1.00]},
295+
index=exp_idx)
296+
exp.index.name = 'Date'
297+
tm.assert_frame_equal(result.reindex_like(exp).round(2), exp.round(2))
298+
281299
@skip_on_exception(RemoteDataError)
282300
def test_yahoo_DataReader_multi(self):
283301
start = datetime(2010, 1, 1)

pandas_datareader/yahoo/daily.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ def _read_one_data(self, url, params):
174174

175175
if 'SPLIT' in types:
176176
splits = actions[actions.Type == 'SPLIT'].copy()
177-
splits['SplitRatio'] = splits['Splitratio'].apply(
178-
lambda x: eval(x))
177+
splits['SplitRatio'] = splits.apply(
178+
lambda row: eval(row['Splitratio']) if float(row['Numerator'])>0 else 1, axis = 1 )
179179
splits = splits.reset_index(drop=True)
180180
splits = splits.set_index('Date')
181-
splits['Splits'] = 1.0 / splits['SplitRatio']
181+
splits['Splits'] = splits['SplitRatio']
182182
prices = prices.join(splits['Splits'], how='outer')
183183

184184
if 'DIVIDEND' in types and self.adjust_dividends:

0 commit comments

Comments
 (0)