Skip to content

Commit a9c8802

Browse files
author
David Stephens
committed
BUG: Fix tests for google & yahoo options.
Currently only 4 expiries for GOOG options. Datatype on open interest & volume changed to float to deal with NaNs
1 parent 2bc8338 commit a9c8802

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

pandas_datareader/google/options.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ def _process_data(self, jd, expiry):
137137
indexes = ['Strike', 'Expiry', 'Type', 'Symbol']
138138
rows_list, index = self._process_rows(jd, now, expiry)
139139
df = DataFrame(rows_list, columns=columns, index=MultiIndex.from_tuples(index, names=indexes))
140+
141+
# Make dtype consistent, requires float64 as there can be NaNs
142+
df['Vol'] = df['Vol'].astype('float64')
143+
df['Open_Int'] = df['Open_Int'].astype('float64')
144+
140145
return df.sort_index()
141146

142147
def _process_rows(self, jd, now, expiry):

pandas_datareader/tests/test_google_options.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def assert_option_result(self, df):
3131
tm.assert_index_equal(df.columns, exp_columns)
3232
tm.assert_equal(df.index.names, [u'Strike', u'Expiry', u'Type', u'Symbol'])
3333

34-
dtypes = ['float64'] * 6 + ['int64', 'object', 'float64', 'datetime64[ns]']
34+
dtypes = ['float64'] * 7 + ['object', 'float64', 'datetime64[ns]']
3535
dtypes = [np.dtype(x) for x in dtypes]
3636
tm.assert_series_equal(df.dtypes, pd.Series(dtypes, index=exp_columns))
3737

@@ -54,7 +54,7 @@ def test_expiry_dates(self):
5454
except RemoteDataError as e: # pragma: no cover
5555
raise nose.SkipTest(e)
5656

57-
self.assertTrue(len(dates) >= 5)
57+
self.assertTrue(len(dates) >= 4)
5858
self.assertIsInstance(dates, list)
5959
self.assertTrue(all(isinstance(dt, date) for dt in dates))
6060

pandas_datareader/tests/test_yahoo_options.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def assert_option_result(self, df):
5050
tm.assert_index_equal(df.columns, exp_columns)
5151
tm.assert_equal(df.index.names, [u'Strike', u'Expiry', u'Type', u'Symbol'])
5252

53-
dtypes = [np.dtype(x) for x in ['float64'] * 5 +
54-
['int64', 'int64', 'float64', 'object', 'bool', 'object', 'float64', 'datetime64[ns]',
53+
dtypes = [np.dtype(x) for x in ['float64'] * 7 +
54+
['float64', 'object', 'bool', 'object', 'float64', 'datetime64[ns]',
5555
'datetime64[ns]', 'object']]
5656
tm.assert_series_equal(df.dtypes, pd.Series(dtypes, index=exp_columns))
5757

pandas_datareader/yahoo/options.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,10 @@ def _process_data(self, jd):
684684

685685
df['IsNonstandard'] = df['Root'] != self.symbol.replace('-', '')
686686

687+
# Make dtype consistent, requires float64 as there can be NaNs
688+
df['Vol'] = df['Vol'].astype('float64')
689+
df['Open_Int'] = df['Open_Int'].astype('float64')
690+
687691
return df.sort_index()
688692

689693
def _process_rows(self, jd):

0 commit comments

Comments
 (0)