Skip to content

Fixed two dividend related issues #602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pandas_datareader/tests/yahoo/test_yahoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,24 @@ def test_yahoo_DataReader(self):
exp.index.name = 'Date'
tm.assert_frame_equal(result.reindex_like(exp).round(5), exp.round(5))


# test cases with "1/0" split ratio in actions- no split, just chnage symbol from POT to NTR
start = datetime(2017, 12, 30)
end = datetime(2018, 12, 30)

result = web.DataReader('NTR', 'yahoo-actions', start, end)

exp_idx = pd.DatetimeIndex(['2018-12-28', '2018-09-27',
'2018-06-28', '2018-03-28',
'2018-01-02'])

exp = pd.DataFrame({'action': ['DIVIDEND', 'DIVIDEND', 'DIVIDEND',
'DIVIDEND', 'SPLIT'],
'value': [0.43, 0.40, 0.40, 0.40, 1.00]},
index=exp_idx)
exp.index.name = 'Date'
tm.assert_frame_equal(result.reindex_like(exp).round(2), exp.round(2))

@skip_on_exception(RemoteDataError)
def test_yahoo_DataReader_multi(self):
start = datetime(2010, 1, 1)
Expand Down
6 changes: 3 additions & 3 deletions pandas_datareader/yahoo/daily.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ def _read_one_data(self, url, params):

if 'SPLIT' in types:
splits = actions[actions.Type == 'SPLIT'].copy()
splits['SplitRatio'] = splits['Splitratio'].apply(
lambda x: eval(x))
splits['SplitRatio'] = splits.apply(
lambda row: eval(row['Splitratio']) if float(row['Numerator'])>0 else 1, axis = 1 )
splits = splits.reset_index(drop=True)
splits = splits.set_index('Date')
splits['Splits'] = 1.0 / splits['SplitRatio']
splits['Splits'] = splits['SplitRatio']
prices = prices.join(splits['Splits'], how='outer')

if 'DIVIDEND' in types and self.adjust_dividends:
Expand Down