Repository: pandas-dev/pandas

Issue:
TST: YahooOptions get_all_data failure
cc @dstephens99

Almost certainly a bad data failure

for the first should guard this with a `try: except:` (and make that value nan)
2nd needs a guard on the test to skip with a RemoteError? (I think this is done with some of the other tests)?

```
======================================================================
ERROR: test_get_all_data (pandas.io.tests.test_data.TestYahooOptions)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "c:\Users\Jeff Reback\Documents\GitHub\pandas\build\lib.win-amd64-2.7\pandas\util\testing.py", line 1308, in wrapper
    return t(*args, **kwargs)
  File "c:\Users\Jeff Reback\Documents\GitHub\pandas\build\lib.win-amd64-2.7\pandas\io\tests\test_data.py", line 316, in test_get_all_data
    data = self.aapl.get_all_data(put=True)
  File "c:\Users\Jeff Reback\Documents\GitHub\pandas\build\lib.win-amd64-2.7\pandas\io\data.py", line 1107, in get_all_data
    frame = getattr(self, meth_name)(expiry=month)
  File "c:\Users\Jeff Reback\Documents\GitHub\pandas\build\lib.win-amd64-2.7\pandas\io\data.py", line 792, in get_call_data
    return self._get_option_data(month, year, expiry, 'calls').sortlevel()
  File "c:\Users\Jeff Reback\Documents\GitHub\pandas\build\lib.win-amd64-2.7\pandas\io\data.py", line 719, in _get_option_data
    tables = self._get_option_tables(month, year, expiry)
  File "c:\Users\Jeff Reback\Documents\GitHub\pandas\build\lib.win-amd64-2.7\pandas\io\data.py", line 686, in _get_option_tables
    self.underlying_price, self.quote_time = self._get_underlying_price(root)
  File "c:\Users\Jeff Reback\Documents\GitHub\pandas\build\lib.win-amd64-2.7\pandas\io\data.py", line 691, in _get_underlying_price
    underlying_price = float(root.xpath('.//*[@class="time_rtq_ticker"]')[0]\
IndexError: list index out of range

======================================================================
ERROR: test_get_all_data_calls_only (pandas.io.tests.test_data.TestYahooOptions)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "c:\Users\Jeff Reback\Documents\GitHub\pandas\build\lib.win-amd64-2.7\pandas\util\testing.py", line 1308, in wrapper
    return t(*args, **kwargs)
  File "c:\Users\Jeff Reback\Documents\GitHub\pandas\build\lib.win-amd64-2.7\pandas\io\tests\test_data.py", line 325, in test_get_all_data_calls_only
    data = self.aapl.get_all_data(call=True, put=False)
  File "c:\Users\Jeff Reback\Documents\GitHub\pandas\build\lib.win-amd64-2.7\pandas\io\data.py", line 1107, in get_all_data
    frame = getattr(self, meth_name)(expiry=month)
  File "c:\Users\Jeff Reback\Documents\GitHub\pandas\build\lib.win-amd64-2.7\pandas\io\data.py", line 792, in get_call_data
    return self._get_option_data(month, year, expiry, 'calls').sortlevel()
  File "c:\Users\Jeff Reback\Documents\GitHub\pandas\build\lib.win-amd64-2.7\pandas\io\data.py", line 727, in _get_option_data
    " found".format(table_loc, ntables))
IndexError: Table location 9 invalid, 2 tables found
```



Discussion:
Agreed on the first one, I will add the try, except.

The second one is more strange, we discussed in #7392 that we should have it fail if it found some tables, but no the right one.  Otherwise you'd have no idea from the tests if Yahoo changed their formatting around.  

I wonder if this is related somehow to expiry day.  I'll run the tests on my computer and see if they pass.

this is the first time that I saw this fail at all, so prob random....


Resolving patch:
diff --git a/pandas/io/data.py b/pandas/io/data.py
--- a/pandas/io/data.py
+++ b/pandas/io/data.py
@@ -683,7 +683,10 @@ def _get_option_tables(self, month, year, expiry):
         table_name = '_tables' + m1 + str(year)[-2:]
         setattr(self, table_name, tables)
 
-        self.underlying_price, self.quote_time = self._get_underlying_price(root)
+        try:
+            self.underlying_price, self.quote_time = self._get_underlying_price(root)
+        except IndexError:
+            self.underlying_price, self.quote_time = np.nan, np.nan
 
         return tables
 
@@ -723,7 +726,7 @@ def _get_option_data(self, month, year, expiry, name):
         if ntables == 0:
             raise RemoteDataError("No tables found at {0!r}".format(url))
         elif table_loc - 1 > ntables:
-            raise IndexError("Table location {0} invalid, {1} tables"
+            raise RemoteDataError("Table location {0} invalid, {1} tables"
                              " found".format(table_loc, ntables))
 
         option_data = _parse_options_data(tables[table_loc])


Test patch: