Skip to content

test_constrained fail #4108

Closed
Closed

Description

@thequackdaddy

It looks like there are some fails in appveyor.

https://ci.appveyor.com/project/josef-pkt/statsmodels/build/1.0.2611/job/qfcsfnc0jcxxbg2h

statsmodels.discrete.tests.test_constrained

I think what is happening is that patsy is decoding integers as 1L, 2L, 3L, 4L, and 5L on the failing test cases, while it is just 1, 2, 3, 4, and 5 on the passing ones. Thus, you'd need to set the constraint as 'C(agecat)[T.5L] = C(agecat)[T.4L]' to pass the 2.7 case. Of course, that will break the other, currently working cases.

Perhaps we could change the variables to be strings or floats so the L doesn't get added? Happy to play with this if someone has an idea.

Activity

  1. changed the title [-]test_discrete fail[/-] [+]test_constrained fail[/+] on Nov 7, 2017
  2. josef-pkt commented on Nov 7, 2017

    @josef-pkt
    Member

    It's the first time that I saw it today in your PR.
    If it shows up more often or regularly now, then I'll investigate. Right now I have no idea what might have changed. Those tests are a few years old.

    Names are created within patsy, so we don't control them. If we have to, then we need to adjust the tests if the names that patsy creates change by operating system or version as you point out as source of the problem. (maybe just a change in the dtype of the integers works.)

  3. added this to the 0.9 milestone on Nov 7, 2017
  4. josef-pkt commented on Nov 7, 2017

    @josef-pkt
    Member

    and thanks for checking
    When I looked at those failures earlier today, I had no clue what might be going on.

  5. thequackdaddy commented on Nov 7, 2017

    @thequackdaddy
    MemberAuthor

    I think the difference is pandas updated to 0.21...

    this passes

    The following NEW packages will be INSTALLED:
        cython:          0.26.1-py27h45dccc8_0
        icc_rt:          2017.0.4-h97af966_0  
        intel-openmp:    2018.0.0-hcd89f80_7  
        mkl:             2018.0.0-h36b65af_4  
        nose:            1.3.7-py27h84c72c6_2 
        numpy:           1.13.3-py27h9ac254c_0
        pandas:          0.20.3-py27he04484b_2
        patsy:           0.4.1-py27h5f67e4e_0 
        python-dateutil: 2.6.1-py27hbdcc174_1 
        pytz:            2017.2-py27haecbe8f_1
        scipy:           0.19.1-py27h069396b_3
    

    This fails...

    The following NEW packages will be INSTALLED:
        cython:          0.26.1-py27h45dccc8_0
        icc_rt:          2017.0.4-h97af966_0  
        intel-openmp:    2018.0.0-hcd89f80_7  
        mkl:             2018.0.0-h36b65af_4  
        nose:            1.3.7-py27h84c72c6_2 
        numpy:           1.13.3-py27h9ac254c_0
        pandas:          0.21.0-py27h3b50df0_1
        patsy:           0.4.1-py27h5f67e4e_0 
        python-dateutil: 2.6.1-py27hbdcc174_1 
        pytz:            2017.2-py27haecbe8f_1
        scipy:           0.19.1-py27h069396b_3
    
  6. josef-pkt commented on Nov 7, 2017

    @josef-pkt
    Member

    does converting the data in the test module to a numpy.int64 dtype work?

    @TomAugspurger did the internal int representation change in pandas 0.21?

  7. TomAugspurger commented on Nov 7, 2017

    @TomAugspurger
    Contributor

    @TomAugspurger did the internal int representation change in pandas 0.21?

    Nothing major like that. I'm unfortunately not able to reproduce on my Mac.

  8. thequackdaddy commented on Nov 7, 2017

    @thequackdaddy
    MemberAuthor

    So this is some weird patsy/pandas thing... don't fully understand it... I can't get it to show up on pandas 0.21 on python 3.6.

    Here's the "expected" behavior.

    IPython 5.3.0 -- An enhanced Interactive Python.
    ?         -> Introduction and overview of IPython's features.
    %quickref -> Quick reference.
    help      -> Python's own help system.
    object?   -> Details about 'object', use 'object??' for extra details.
    
    In [1]: from patsy import dmatrix
    
    In [2]: from io import StringIO
    
    In [3]: import pandas as pd
    
    In [4]: import statsmodels.api as sm
    C:\ProgramData\Anaconda3\lib\site-packages\statsmodels\compat\pandas.py:56: FutureWarning: The pandas.core.datetools module is deprecated and will be removed in a future version. Please use the pandas.tseries module instead.
      from pandas.core import datetools
    
    In [5]: ss='''\
       ...: agecat smokes deaths pyears
       ...: 1 1 32 52407
       ...: 2 1 104 43248
       ...: 3 1 206 28612
       ...: 4 1 186 12663
       ...: 5 1 102 5317
       ...: 1 0 2 18790
       ...: 2 0 12 10673
       ...: 3 0 28 5710
       ...: 4 0 28 2585
       ...: 5 0 31 1462'''
       ...:
       ...: data = pd.read_csv(StringIO(ss), delimiter='\s')
       ...:
    C:\ProgramData\Anaconda3\Scripts\ipython-script.py:13: ParserWarning: Falling back to the 'python' engine because the 'c' engine does not support regex separators (separators > 1 char and different from '\s+' are interpreted as regex); you can avoid this warning by specifying engine='python'.
    
    In [6]: data.dtypes
    Out[6]:
    agecat    int64
    smokes    int64
    deaths    int64
    pyears    int64
    dtype: object
    
    In [7]: dmatrix('C(agecat)', data=data)
    Out[7]:
    DesignMatrix with shape (10, 5)
      Intercept  C(agecat)[T.2]  C(agecat)[T.3]  C(agecat)[T.4]  C(agecat)[T.5]
              1               0               0               0               0
              1               1               0               0               0
              1               0               1               0               0
              1               0               0               1               0
              1               0               0               0               1
              1               0               0               0               0
              1               1               0               0               0
              1               0               1               0               0
              1               0               0               1               0
              1               0               0               0               1
      Terms:
        'Intercept' (column 0)
        'C(agecat)' (columns 1:5)
    
    In [8]: sm.show_versions()
    
    INSTALLED VERSIONS
    ------------------
    Python: 3.6.1.final.0
    
    Statsmodels
    ===========
    
    Installed: 0.8.0 (C:\ProgramData\Anaconda3\lib\site-packages\statsmodels)
    
    Required Dependencies
    =====================
    
    cython: 0.25.2 (C:\ProgramData\Anaconda3\lib\site-packages\Cython)
    numpy: 1.12.1 (C:\ProgramData\Anaconda3\lib\site-packages\numpy)
    scipy: 0.19.0 (C:\ProgramData\Anaconda3\lib\site-packages\scipy)
    pandas: 0.20.1 (C:\ProgramData\Anaconda3\lib\site-packages\pandas)
        dateutil: 2.6.0 (C:\ProgramData\Anaconda3\lib\site-packages\dateutil)
    patsy: 0.4.1 (C:\ProgramData\Anaconda3\lib\site-packages\patsy)
    
    Optional Dependencies
    =====================
    
    matplotlib: 2.0.2 (C:\ProgramData\Anaconda3\lib\site-packages\matplotlib)
    cvxopt: Not installed
    
    Developer Tools
    ================
    
    IPython: 5.3.0 (C:\ProgramData\Anaconda3\lib\site-packages\IPython)
        jinja2: 2.9.6 (C:\ProgramData\Anaconda3\lib\site-packages\jinja2)
    sphinx: 1.5.6 (C:\ProgramData\Anaconda3\lib\site-packages\Sphinx-1.5.6-py3.6.egg\sphinx)
        pygments: 2.2.0 (C:\ProgramData\Anaconda3\lib\site-packages\pygments)
    nose: 1.3.7 (C:\ProgramData\Anaconda3\lib\site-packages\nose)
    virtualenv: Not installed

    Here's the "weird" behavior.

    Python 2.7.13 |Anaconda, Inc.| (default, Sep 30 2017, 11:12:42) [MSC v.1500 64 bit (AMD64)]
    Type "copyright", "credits" or "license" for more information.
    
    IPython 5.4.1 -- An enhanced Interactive Python.
    ?         -> Introduction and overview of IPython's features.
    %quickref -> Quick reference.
    help      -> Python's own help system.
    object?   -> Details about 'object', use 'object??' for extra details.
    
    In [1]: from StringIO import StringIO
    
    In [2]: import pandas as pd
    
    In [3]: ss='''\
       ...: agecat smokes deaths pyears
       ...: 1 1 32 52407
       ...: 2 1 104 43248
       ...: 3 1 206 28612
       ...: 4 1 186 12663
       ...: 5 1 102 5317
       ...: 1 0 2 18790
       ...: 2 0 12 10673
       ...: 3 0 28 5710
       ...: 4 0 28 2585
       ...: 5 0 31 1462'''
       ...:
       ...: data = pd.read_csv(StringIO(ss), delimiter='\s')
       ...:
    C:\ProgramData\Anaconda3\envs\smtest272\Scripts\ipython:13: ParserWarning: Falling back to the 'python' engine because the 'c' engine does not support regex separators (separators > 1 char and different from '\s+' are interpreted as regex); you can avoid this warning by specifying engine='python'.
    
    In [4]: data.dtypes
    Out[4]:
    agecat    int64
    smokes    int64
    deaths    int64
    pyears    int64
    dtype: object
    
    In [5]: from patsy import dmatrix
    
    In [6]: dmatrix('C(agecat)', data=data)
    Out[6]:
    DesignMatrix with shape (10L, 5L)
      Columns:
        ['Intercept',
         'C(agecat)[T.2L]',
         'C(agecat)[T.3L]',
         'C(agecat)[T.4L]',
         'C(agecat)[T.5L]']
      Terms:
        'Intercept' (column 0), 'C(agecat)' (columns 1:5)
      (to view full data, use np.asarray(this_obj))
    
    In [7]: import statsmodels.api as sm
    
    In [8]: sm.show_versions()
    
    INSTALLED VERSIONS
    ------------------
    Python: 2.7.13.final.0
    
    Statsmodels
    ===========
    
    Installed: 0.8.0.dev0+8b83bc3 (c:\users\User\git\statsmodels\statsmodels)
    
    Required Dependencies
    =====================
    
    cython: 0.26.1 (C:\ProgramData\Anaconda3\envs\smtest272\lib\site-packages\Cython)
    numpy: 1.13.3 (C:\ProgramData\Anaconda3\envs\smtest272\lib\site-packages\numpy)
    scipy: 0.19.1 (C:\ProgramData\Anaconda3\envs\smtest272\lib\site-packages\scipy)
    pandas: 0.21.0 (C:\ProgramData\Anaconda3\envs\smtest272\lib\site-packages\pandas)
        dateutil: 2.6.1 (C:\ProgramData\Anaconda3\envs\smtest272\lib\site-packages\dateutil)
    patsy: 0.4.1 (C:\ProgramData\Anaconda3\envs\smtest272\lib\site-packages\patsy)
    
    Optional Dependencies
    =====================
    
    matplotlib: Not installed
    cvxopt: Not installed
    joblib: Not installed
    
    Developer Tools
    ================
    
    IPython: 5.4.1 (C:\ProgramData\Anaconda3\envs\smtest272\lib\site-packages\IPython)
        jinja2: Not installed
    sphinx: Not installed
        pygments: 2.2.0 (C:\ProgramData\Anaconda3\envs\smtest272\lib\site-packages\pygments)
    nose: 1.3.7 (C:\ProgramData\Anaconda3\envs\smtest272\lib\site-packages\nose)
    pytest: 3.2.3 (C:\ProgramData\Anaconda3\envs\smtest272\lib\site-packages)
    virtualenv: Not installed

    Notice the addition of the "L" in the patsy dmatrix in the "weird" one.

  9. TomAugspurger commented on Nov 7, 2017

    @TomAugspurger
    Contributor

    Thanks @thequackdaddy. It's possible this is due to pandas-dev/pandas#17491, where iterating over a pandas DataFrame always returns a python scalar (instead of a NumPy 0d scalar). I suspect that (again, may be wrong), since AFAICT, NumPy doesn't have a "long" integer, so those must be coming from Python? Does statsmodels iterate over the DataFrame (maybe calling .tolist) anywhere? Or would that be in Patsy?

  10. josef-pkt commented on Nov 7, 2017

    @josef-pkt
    Member

    It's patsy that has to loop over the unique values to create the name for the categorical variables or dummy variables and I guess uses repr or str.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions