Skip to content

TST/CLN: some RunTimeWarnings #14057

Closed
Closed

Description

@jreback

after #13145 some RunTimeWarnings remain in the codebase. We should look at these and silence (using np.errstate), or fix if we are testing something odd. (running the full test suite will show these; I have extracted them, some are showing a level too low in the stack).

  • pandas/pandas/tseries/index.py:526: RuntimeWarning: overflow encountered in long_scalars return lambda x: Timestamp(x, freq=self.offset, tz=self.tz)
  • pandas/pandas/tseries/tests/test_tslib.py:453: RuntimeWarning: overflow encountered in long_scalar self.assertIs(ts.tz_localize(tz, errors='coerce'),
  • pandas/pandas/core/internals.py:2341: RuntimeWarning: overflow encountered in long_scalar f = lambda x: lib.Timestamp(x, tz=self.values.tz)
  • pandas/pandas/core/internals.py:4753: ComplexWarning: Casting complex values to real discards the imaginary part nn_at = nn.astype(v.dtype)
  • pandas/pandas/tests/test_algos.py:735: RuntimeWarning: overflow encountered in long_scalars np.array([pd.Timestamp(d, tz='US/Eastern') for d in dt]),
  • pandas/pandas/core/ops.py:650: RuntimeWarning: invalid value encountered in double_scalars lambda x: op(x, rvalues))

Activity

  1. added this to the milestone on Aug 21, 2016
  2. jreback commented on Aug 21, 2016

    @jreback
    ContributorAuthor
  3. Liam3851 commented on Oct 28, 2016

    @Liam3851
    Contributor

    Also since 0.19.0 but still in current master: pandas/pandas/core/generic.py:5126: RuntimeWarning: invalid value encountered in absolute return np.abs(self)

    
    In [1]: import numpy as np; import pandas as pd                                                       
    
    In [2]: pd.__version__                                                                                
    Out[2]: '0.19.0+52.g096d886' 
    
    In [3]: pd.Series([1, -2.0, np.NaN]).abs()                                                            
    C:\AnacondaBleeding\lib\site-packages\pandas\core\generic.py:5126: RuntimeWarning: invalid value encountered in absolute                                                                                    
      return np.abs(self)                                                                                 
    Out[3]:                                                                                               
    0    1.0                                                                                              
    1    2.0                                                                                              
    2    NaN                                                                                              
    dtype: float64                                                                                        
    
    
  4. jreback commented on Oct 29, 2016

    @jreback
    ContributorAuthor

    @Liam3851 you would have to show more information, e.g. pd.show_versions(). This has worked for quite a number of versions already as is not related this issue. more likely a numpy / platform version I think.

    In [2]: pd.__version__
    Out[2]: '0.19.0+53.g7f5a45c'
    
    In [3]: pd.Series([1, -2.0, np.NaN]).abs()     
    Out[3]: 
    0    1.0
    1    2.0
    2    NaN
    dtype: float64
    
    In [4]: np.__version__
    Out[4]: '1.11.2'
    
    
  5. Liam3851 commented on Nov 1, 2016

    @Liam3851
    Contributor

    Thanks Jeff. I'm still showing with numpy 1.11.2 on Windows 7. Here's pd.show_versions;

    In [1]: import numpy as np; import pandas as pd                                                                        
    
    In [2]: pd.show_versions()                                                                                             
    
    INSTALLED VERSIONS                                                                                                     
    ------------------                                                                                                     
    commit: 096d8866a90c8cbb44ab8243320e811fc24190bd                                                                       
    python: 2.7.12.final.0                                                                                                 
    python-bits: 64                                                                                                        
    OS: Windows                                                                                                            
    OS-release: 7                                                                                                          
    machine: AMD64                                                                                                         
    processor: Intel64 Family 6 Model 62 Stepping 4, GenuineIntel                                                          
    byteorder: little                                                                                                      
    LC_ALL: None                                                                                                           
    LANG: None                                                                                                             
    LOCALE: None.None                                                                                                      
    
    pandas: 0.19.0+52.g096d886                                                                                             
    nose: 1.3.7                                                                                                            
    pip: 8.1.2                                                                                                             
    setuptools: 27.2.0                                                                                                     
    Cython: 0.24.1                                                                                                         
    numpy: 1.11.2                                                                                                          
    scipy: 0.18.1                                                                                                          
    statsmodels: None                                                                                                      
    xarray: None                                                                                                           
    IPython: 5.1.0                                                                                                         
    sphinx: 1.4.8                                                                                                          
    patsy: None                                                                                                            
    dateutil: 2.5.3                                                                                                        
    pytz: 2016.7                                                                                                           
    blosc: None                                                                                                            
    bottleneck: None                                                                                                       
    tables: 3.2.2                                                                                                          
    numexpr: 2.6.1                                                                                                         
    matplotlib: 1.5.3                                                                                                      
    openpyxl: 2.4.0                                                                                                        
    xlrd: 1.0.0                                                                                                            
    xlwt: 1.1.2                                                                                                            
    xlsxwriter: None                                                                                                       
    lxml: 3.6.4                                                                                                            
    bs4: None                                                                                                              
    html5lib: None                                                                                                         
    httplib2: None                                                                                                         
    apiclient: None                                                                                                        
    sqlalchemy: 1.0.13                                                                                                     
    pymysql: None                                                                                                          
    psycopg2: None                                                                                                         
    jinja2: 2.8                                                                                                            
    boto: None                                                                                                             
    pandas_datareader: None                                                                                                
    
    In [3]: pd.Series([1, -2.0, np.NaN]).abs()                                                                             
    pandas\core\generic.py:5126: RuntimeWarning: invalid value encountered in absolute                                     
      return np.abs(self)                                                                                                  
    Out[3]:                                                                                                                
    0    1.0                                                                                                               
    1    2.0                                                                                                               
    2    NaN                                                                                                               
    dtype: float64                                                                                                         
    
  6. jreback commented on Nov 1, 2016

    @jreback
    ContributorAuthor

    can you step thru and see exactly where this is coming from? I cannot repro

  7. Liam3851 commented on Nov 1, 2016

    @Liam3851
    Contributor

    Odd. Do you see the error with raw numpy outside pandas?

    In [1]: import numpy as np                                                                                             
    
    In [2]: np.abs(np.array([1, -2, np.nan]))                                                                              
    C:\AnacondaBleeding\envs\pandas_dev\Scripts\ipython-script.py:1: RuntimeWarning: invalid value encountered in absolute 
      if __name__ == '__main__':                                                                                           
    Out[2]: array([  1.,   2.,  nan])                                                                                      
    

    NDFrame.abs is just calling np.abs(self). I can kill the warning by adding

    with np.errstate(invalid='ignore'):

    before the return np.abs(self) at line 5126.

  8. jreback commented on Nov 1, 2016

    @jreback
    ContributorAuthor

    actually I can repro only on 2.7 on windows. I think this is a numpy bug actually (if you'd like to search / report if its not there).

    λ python
    Python 2.7.12 |Continuum Analytics, Inc.| (default, Jun 29 2016, 11:07:13) [MSC v.1500 64 bit (AMD64)] on win32
    >>> import numpy as np
    >>> np.abs(np.array([1, -2., np.nan]))
    __main__:1: RuntimeWarning: invalid value encountered in absolute
    array([  1.,   2.,  nan])
    >>>
    

    In any event, let's up a np.errstate in pandas around in .abs()

  9. mroeschke commented on May 1, 2021

    @mroeschke
    Member

    I believe we took care of our warnings a while back so going to close this issue. Should open up separate newer issues if they still exist

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    CleanClosing CandidateMay be closeable, needs more eyeballsTestingpandas testing functions or related to the test suite

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions