From 9ef3b9f5dcca312c80cad0d78e8e83ef79afe6eb Mon Sep 17 00:00:00 2001 From: y-p Date: Mon, 27 Jan 2014 04:57:26 +0200 Subject: [PATCH 1/2] TST: get_options_data ValueError if given only one of month/year GH6105 --- pandas/io/tests/test_data.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pandas/io/tests/test_data.py b/pandas/io/tests/test_data.py index cbd7a0fb76ecc..a6c0deb6d7827 100644 --- a/pandas/io/tests/test_data.py +++ b/pandas/io/tests/test_data.py @@ -266,6 +266,12 @@ def test_get_options_data(self): assert len(calls)>1 assert len(puts)>1 + def test_get_options_data(self): + + # regression test GH6105 + self.assertRaises(ValueError,self.aapl.get_options_data,month=3) + self.assertRaises(ValueError,self.aapl.get_options_data,year=1992) + @network def test_get_near_stock_price(self): try: From c55511bbef52830c588752587433447074685e60 Mon Sep 17 00:00:00 2001 From: y-p Date: Mon, 27 Jan 2014 04:58:18 +0200 Subject: [PATCH 2/2] BUG: get_options_data should raise ValueError if given only one of month/year GH6105 --- doc/source/release.rst | 1 + pandas/io/data.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/doc/source/release.rst b/doc/source/release.rst index aa7b701ee39a3..6593ba78ad3e6 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -156,6 +156,7 @@ Bug Fixes - Subtle ``iloc`` indexing bug, surfaced in (:issue:`6059`) - Bug with insert of strings into DatetimeIndex (:issue:`5818`) - Fixed unicode bug in to_html/HTML repr (:issue:`6098`) + - Fixed missing arg validation in get_options_data (:issue:`6105`) pandas 0.13.0 ------------- diff --git a/pandas/io/data.py b/pandas/io/data.py index b3332df3c8866..eb182e77a5db5 100644 --- a/pandas/io/data.py +++ b/pandas/io/data.py @@ -632,6 +632,10 @@ def get_options_data(self, month=None, year=None, expiry=None): _OPTIONS_BASE_URL = 'http://finance.yahoo.com/q/op?s={sym}' def _get_option_data(self, month, year, expiry, table_loc, name): + if (month is None or year is None) and expiry is None: + msg = "You must specify either (`year` and `month`) or `expiry`." + raise ValueError(msg) + year, month = self._try_parse_dates(year, month, expiry) url = self._OPTIONS_BASE_URL.format(sym=self.symbol)