Change Finance Options signatures and deprecate year/month parameters
State: closed

#3817


Labels:

Comments:
This is the error this build gets (my local unit test was running without errors ...). Investigating:

```
======================================================================

ERROR: test_options (pandas.io.tests.test_yahoo.TestYahoo)

----------------------------------------------------------------------

Traceback (most recent call last):

  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pandas-0.11.1.dev_d26f4b6-py2.7-linux-x86_64.egg/pandas/io/tests/test_yahoo.py", line 131, in test_options

    (calls, puts) = aapl.get_near_stock_price(call=True, put=True, dt=dt)

  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pandas-0.11.1.dev_d26f4b6-py2.7-linux-x86_64.egg/pandas/io/data.py", line 768, in get_near_stock_price

    start_index = np.where(df_c['Strike'] > price)[0][0]

IndexError: index out of bounds

======================================================================

ERROR: test_options_warnings (pandas.io.tests.test_yahoo.TestYahoo)

----------------------------------------------------------------------

Traceback (most recent call last):

  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pandas-0.11.1.dev_d26f4b6-py2.7-linux-x86_64.egg/pandas/io/tests/test_yahoo.py", line 155, in test_options_warnings

    (calls, puts) = aapl.get_near_stock_price(call=True, put=True, month=month, year=year)

  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pandas-0.11.1.dev_d26f4b6-py2.7-linux-x86_64.egg/pandas/io/data.py", line 768, in get_near_stock_price

    start_index = np.where(df_c['Strike'] > price)[0][0]

IndexError: index out of bounds

----------------------------------------------------------------------

Ran 3263 tests in 85.929s

FAILED (SKIP=42, errors=2)
```

Why wouldn't lxml.html be available under Python 2.6?

```
======================================================================
ERROR: test_options_warnings (pandas.io.tests.test_yahoo.TestYahoo)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/virtualenv/python2.6_with_system_site_packages/lib/python2.6/site-packages/pandas-0.11.1.dev_23952c9-py2.6-linux-x86_64.egg/pandas/io/tests/test_yahoo.py", line 185, in test_options_warnings
    (calls, puts) = aapl.get_options_data(month=month, year=year)
  File "/home/travis/virtualenv/python2.6_with_system_site_packages/lib/python2.6/site-packages/pandas-0.11.1.dev_23952c9-py2.6-linux-x86_64.egg/pandas/io/data.py", line 526, in get_options_data
    from lxml.html import parse
ImportError: No module named lxml.html
```

Could somebody offer some comments on this? I cannot reproduce the same error locally running with/without network connectivity.

@gliptak can you rebase to a smaller num of commits?

e.g

`git rebase -i <your starting commit>`
then `f` or `s`

`git rebase -i upstream/master` is nice too if you've already fetched and rebased. then u don't have to use commit hashes to remember where you started

That's a nice tip! I also recommend squashing before doing a rebase (that way you do fewer steps / one step for conflicts, and more likely to understand how they can be resolved).

@cpcloud maybe also add these tips to developer page? and It hink should have a link to developer page from somewhere in main docs......

there's a link...dev workflow is on my pandas to-do list: 2nd after `eval`!

#3156 :)

@jreback I did squash several commits. Thanks

@gliptak Right now the test cases for network errors aren't really doing what you want, because they catch _all_ exceptions for bad tests, as opposed to specifically describing the behavior you want (e.g., should `get_quote_yahoo` bubble up a network error, or should it replace it with its own error?)

Catching exceptions with the baseclass `Exception` (and raising exceptions that are just Exception) is not great, because it means that users of the library have to catch bare Exceptions, as opposed to just opting into the exceptions they care about (i.e., you want to be able to see that you misspelled something as opposed to hitting a NetworkError).

Also, I suggest you consider changing the `raise Exception(...)` in `io/data.py` to raise a specific exception, i.e.:

``` python
from pandas.core.common import PandasError
class DataError(PandasError):
    pass
```

And that way you can catch these in your test cases, etc.

@jtratner note that in the code I'm not raising exceptions, although not catching/converting them to 'known' exceptions either. I believe the test code works, as it only marks the failing test skip if it notes a network problem (by trying to connect to google.com) The change you are suggesting is not related to this enhancement, I would be happy to work modifying current code as a separate pull request.

the reason that I widened to catching `IOError` in the tests, is that I have seen other errors beside `URLError` showing up in my testing

as per http://stackoverflow.com/a/3465796/304690 `urllib2.urlopen` throws `HTTPError`, `URLError` and `ValueError`

I mean exceptions like this:

``` python

    raise Exception("after %d tries, Yahoo did not "
                    "return a 200 for url %s" % (pause, url))

```

And in test cases, when it tests `assertRaises(Exception, ...` it makes it much less clear what behavior to expect.

@jtratner Jeff, that is existing code, unmodified from current HEAD. As I said above, i would be happy to continue refactoring under a new pull request.

@gliptak this needs release notes / mention in v0.11.1

@jreback updated RELEASE.rst

@gliptak You're going to need to rebase again (it happens pretty often with the RELEASE.rst as everyone is adding to it) 

Tip: don't add your release note at the end, that way it's less likely to conflict :)

@hayd Thanks Andy. Moved my note higher up.

(There's no guarantee it will merge cleanly even when not at the bottom, (I claim) it just makes it less lightly - so there still could be a conflict even when moved, only way to be sure is to do the rebase :) )

@gliptak can you edit this after the new decorators are merged in and remove the in-test IOError checks?

@jtratner I can work that tomorrow afternoon/evening.

@gliptak can you rebase?

@jreback couldn't quite rebase. or this or #3914 has to be pulled to complete this ...

Sorry @gliptak,got no Internet to push the last set of changes. Working on it :) 

@gliptak / @cpcloud can you sort this one?

@gliptak looks like you tried to merge from upstream. i'm going to pull down ur branch and take a look

i used to do this until i understood merge vs. rebase. going forward it's key that u understand the differences so that your contributions will be merged faster...

ok so all you need to do is the following

``` sh
git fetch upstream
git rebase upstream/master
# resolve the merge conflict generated here
git add pandas/io/data.py
git rebase --continue
```

i use the first 2 commands so often that i have them aliased as 

``` sh
alias gfrb='git fetch upstream && git rebase upstream/master'
```

@cpcloud fyi.....should put `how to rebase` on the wiki (I think you put on developer pages as well?)