Repository: statsmodels/statsmodels

Issue:
bug: pandas 0.8.1 incompatibility
Debian default pandas

I can replicate this in a virtualenv with pandas 0.8.1

```
======================================================================
ERROR: statsmodels.tsa.base.tests.test_base.test_predict_freq
----------------------------------------------------------------------
Traceback (most recent call last):
  File "e:\josef\testing\tox\py27aa\lib\site-packages\nose-1.2.1-py2.7.egg\nose\case.py", line 197, in runTest
    self.test(*self.arg)
  File "E:\Josef\testing\tox\py27aa\lib\site-packages\statsmodels\tsa\base\tests\test_base.py", line 34, in test_predict_freq
    start = model._get_predict_start("2006-4-30")
  File "E:\Josef\testing\tox\py27aa\lib\site-packages\statsmodels\tsa\base\tsa_model.py", line 123, in _get_predict_start
    (str(start), str(dtstart)))
UnboundLocalError: local variable 'dtstart' referenced before assignment

======================================================================
ERROR: statsmodels.tsa.tests.test_arima.test_arima_predict_pandas_nofreq
----------------------------------------------------------------------
Traceback (most recent call last):
  File "e:\josef\testing\tox\py27aa\lib\site-packages\nose-1.2.1-py2.7.egg\nose\case.py", line 197, in runTest
    self.test(*self.arg)
  File "E:\Josef\testing\tox\py27aa\lib\site-packages\statsmodels\tsa\tests\test_arima.py", line 1623, in test_arima_predict_pandas_nofreq
    assert_raises(ValueError, arma.predict, start="2010-1-9", end=10)
  File "E:\Josef\testing\tox\py27aa\lib\site-packages\numpy\testing\utils.py", line 1008, in assert_raises
    return nose.tools.assert_raises(*args,**kwargs)
  File "C:\Programs\Python27\Lib\unittest\case.py", line 456, in assertRaises
    callableObj(*args, **kwargs)
  File "E:\Josef\testing\tox\py27aa\lib\site-packages\statsmodels\base\wrapper.py", line 90, in wrapper
    return data.wrap_output(func(results, *args, **kwargs), how)
  File "E:\Josef\testing\tox\py27aa\lib\site-packages\statsmodels\tsa\arima_model.py", line 1318, in predict
    return self.model.predict(self.params, start, end, exog, dynamic)
  File "E:\Josef\testing\tox\py27aa\lib\site-packages\statsmodels\tsa\arima_model.py", line 607, in predict
    start = self._get_predict_start(start, dynamic)
  File "E:\Josef\testing\tox\py27aa\lib\site-packages\statsmodels\tsa\arima_model.py", line 543, in _get_predict_start
    method)
  File "E:\Josef\testing\tox\py27aa\lib\site-packages\statsmodels\tsa\arima_model.py", line 285, in _validate
    start = _index_date(start, dates)
  File "E:\Josef\testing\tox\py27aa\lib\site-packages\statsmodels\tsa\base\datetools.py", line 36, in _index_date
    date = date_parser(date)
  File "E:\Josef\testing\tox\py27aa\lib\site-packages\statsmodels\tsa\base\datetools.py", line 162, in date_parser
    return pandas_datetools.parser.parse(timestr, parserinfo, **kwargs)
AttributeError: 'module' object has no attribute 'parser'
```



Discussion:
I've fixed the second, but I don't see the first. What numpy version?


Resolving patch:
diff --git a/statsmodels/tsa/base/datetools.py b/statsmodels/tsa/base/datetools.py
--- a/statsmodels/tsa/base/datetools.py
+++ b/statsmodels/tsa/base/datetools.py
@@ -139,10 +139,10 @@ def _is_leap(year):
 
 def date_parser(timestr, parserinfo=None, **kwargs):
     """
-    Uses dateutils.parser.parse, but also handles monthly dates of the form
+    Uses dateutil.parser.parse, but also handles monthly dates of the form
     1999m4, 1999:m4, 1999:mIV, 1999mIV and the same for quarterly data
     with q instead of m. It is not case sensitive. The default for annual
-    data is the end of the year, which also differs from dateutils.
+    data is the end of the year, which also differs from dateutil.
     """
     flags = re.IGNORECASE | re.VERBOSE
     if re.search(_q_pattern, timestr, flags):
@@ -159,7 +159,14 @@ def date_parser(timestr, parserinfo=None, **kwargs):
         month, day = 12, 31
         year = int(timestr)
     else:
-        return pandas_datetools.parser.parse(timestr, parserinfo, **kwargs)
+        if hasattr(pandas_datetools, 'parser'):
+
+            return pandas_datetools.parser.parse(timestr, parserinfo,
+                                                 **kwargs)
+        else: # older pandas version didn't import this into namespace
+            from dateutil import parser
+            return parser.parse(timestr, parserinfo, **kwargs)
+
 
     return datetime.datetime(year, month, day)
 


Test patch: