SciTools / cartopy

Cartopy - a cartographic python library with matplotlib support
https://scitools.org.uk/cartopy/docs/latest
BSD 3-Clause "New" or "Revised" License
1.44k stars 367 forks source link

Few tests failing with numpy-1.20 because of warnings #1760

Closed lsix closed 3 years ago

lsix commented 3 years ago

Description

Hi,

We are having few failing tests when packaging cartopy in nixpkgs since we bumped to numpy-1.20 (see .https://github.com/NixOS/nixpkgs/issues/118449). The problems seems to come to the fact that numpy adds new warnings, and some tests in cartopy rely on counting the number of warnings generated during some invocations.

This seems straight forward to fix, I’ll provide a PR ASAP.

Code to reproduce

With numpy-1.20+, from cartopy source

$ python -m pytest

Traceback

=================================== FAILURES ===================================                                                         
______________________________ test_ellipse_globe ______________________________                                                         

    def test_ellipse_globe():                                                                                                                                                                                                                                                             globe = ccrs.Globe(ellipse='WGS84')                                                                                              
        with pytest.warns(UserWarning,                                                                                                   
                          match='does not handle elliptical globes.') as w:                                                              
            mill = ccrs.Miller(globe=globe)                                                                                              
>           assert len(w) == 1                                                                                                           
E           assert 2 == 1                                                                                                                
E            +  where 2 = len(WarningsChecker(record=True))                                                                              

/nix/store/7pj22jb61nprjah9f19pv0mk1sal88ig-python3.8-cartopy-0.18.0/lib/python3.8/site-packages/cartopy/tests/crs/test_miller.py:58: AssertionError                                                                                                                              _____________________________ test_eccentric_globe _____________________________                                                         

    def test_eccentric_globe():                                     
        globe = ccrs.Globe(semimajor_axis=1000, semiminor_axis=500,                                                                      
                           ellipse=None)                                                                                                 
        with pytest.warns(UserWarning,                                                                                                   
                          match='does not handle elliptical globes.') as w:                                                              
            mill = ccrs.Miller(globe=globe)                                                                                              
>           assert len(w) == 1                                                                                                           
E           assert 2 == 1                                                                                                                
E            +  where 2 = len(WarningsChecker(record=True))                                                                                                                                                                                                                                                                                                                                                                
/nix/store/7pj22jb61nprjah9f19pv0mk1sal88ig-python3.8-cartopy-0.18.0/lib/python3.8/site-packages/cartopy/tests/crs/test_miller.py:78: AssertionError
______________________________ test_ellipse_globe ______________________________                                                         

    def test_ellipse_globe():                                                                                                            
        globe = ccrs.Globe(ellipse='WGS84')                                                                                              
        with pytest.warns(UserWarning,                             
                          match='does not handle elliptical globes.') as w:                                                                                                                                                                                                       
            ortho = ccrs.Orthographic(globe=globe)                                                                                       
>           assert len(w) == (2                                                                                                          
                              if (5, 0, 0) <= ccrs.PROJ4_VERSION < (5, 1, 0)                                                                                                                                                                                                                                    else 1)                                                                                                    
E           assert 2 == 1                                                                                                                
E            +  where 2 = len(WarningsChecker(record=True))                                                                              

/nix/store/7pj22jb61nprjah9f19pv0mk1sal88ig-python3.8-cartopy-0.18.0/lib/python3.8/site-packages/cartopy/tests/crs/test_orthographic.py:59: AssertionError
_____________________________ test_eccentric_globe _____________________________                                                         

    def test_eccentric_globe():                                                                                                                                                                                                                                                           globe = ccrs.Globe(semimajor_axis=1000, semiminor_axis=500,                                                                      
                           ellipse=None)                                                                                                                                                                                                                                          
        with pytest.warns(UserWarning,                                                                                                   
                          match='does not handle elliptical globes.') as w:                                                              
            ortho = ccrs.Orthographic(globe=globe)                                                                                       
>           assert len(w) == (2                                                                                                          
                              if (5, 0, 0) <= ccrs.PROJ4_VERSION < (5, 1, 0)                                                             
                              else 1)                                                                                                                                                                                                                                             E           assert 2 == 1                                                                                                                
E            +  where 2 = len(WarningsChecker(record=True))                                                                              

/nix/store/7pj22jb61nprjah9f19pv0mk1sal88ig-python3.8-cartopy-0.18.0/lib/python3.8/site-packages/cartopy/tests/crs/test_orthographic.py:77: AssertionError

The captured output of the tests shows the following warnings:

[…]
  /nix/store/7pj22jb61nprjah9f19pv0mk1sal88ig-python3.8-cartopy-0.18.0/lib/python3.8/site-packages/cartopy/crs.py:1476: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify a
ny behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.                                                                                                                                                                                 
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations                                                                                                                                                       
    a = np.float(self.globe.semimajor_axis or WGS84_SEMIMAJOR_AXIS)
[…]
  /nix/store/7pj22jb61nprjah9f19pv0mk1sal88ig-python3.8-cartopy-0.18.0/lib/python3.8/site-packages/cartopy/crs.py:1477: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify a
ny behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.                                        
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations              
    b = np.float(self.globe.semiminor_axis or WGS84_SEMIMINOR_AXIS)
[…]
  /nix/store/7pj22jb61nprjah9f19pv0mk1sal88ig-python3.8-cartopy-0.18.0/lib/python3.8/site-packages/cartopy/crs.py:1553: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify a
ny behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.                                        
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations              
    a = np.float(self.globe.semimajor_axis or WGS84_SEMIMAJOR_AXIS)
[…]
  /nix/store/7pj22jb61nprjah9f19pv0mk1sal88ig-python3.8-cartopy-0.18.0/lib/python3.8/site-packages/cartopy/crs.py:2320: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify a
ny behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.                                        
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations              
    a = np.float(self.globe.semimajor_axis or WGS84_SEMIMAJOR_AXIS)
[…]
  /nix/store/7pj22jb61nprjah9f19pv0mk1sal88ig-python3.8-cartopy-0.18.0/lib/python3.8/site-packages/cartopy/crs.py:2321: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify a
ny behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.                                        
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations              
    b = np.float(self.globe.semiminor_axis or a)
[…]
  /nix/store/7pj22jb61nprjah9f19pv0mk1sal88ig-python3.8-cartopy-0.18.0/lib/python3.8/site-packages/cartopy/crs.py:2110: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify a
ny behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.                                        
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations              
    a = np.float(self.globe.semimajor_axis or WGS84_SEMIMAJOR_AXIS)
[…]
  /nix/store/7pj22jb61nprjah9f19pv0mk1sal88ig-python3.8-cartopy-0.18.0/lib/python3.8/site-packages/cartopy/crs.py:2111: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify a
ny behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.                                        
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations              
    h = np.float(satellite_height)
[…]
  /nix/store/7pj22jb61nprjah9f19pv0mk1sal88ig-python3.8-cartopy-0.18.0/lib/python3.8/site-packages/cartopy/crs.py:1299: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify a
ny behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.                                        
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations              
    a = np.float(self.globe.semimajor_axis or WGS84_SEMIMAJOR_AXIS)
[…]
  /nix/store/7pj22jb61nprjah9f19pv0mk1sal88ig-python3.8-cartopy-0.18.0/lib/python3.8/site-packages/cartopy/crs.py:1342: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify a
ny behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.                                        
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations              
    a = np.float(globe.semimajor_axis or WGS84_SEMIMAJOR_AXIS)
[…]
  /nix/store/7pj22jb61nprjah9f19pv0mk1sal88ig-python3.8-cartopy-0.18.0/lib/python3.8/site-packages/cartopy/crs.py:2177: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify a
ny behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.                                        
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
[…]
  /nix/store/7pj22jb61nprjah9f19pv0mk1sal88ig-python3.8-cartopy-0.18.0/lib/python3.8/site-packages/cartopy/mpl/geoaxes.py:1699: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not mod
ify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.                                     
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations              
    mask = np.zeros(C.shape, dtype=np.bool)
[…]

Here is a confirmation:

$ python -m pytest --pdb                                                                             
============================================================================================================================== test session starts ===============================================================================================================================
platform linux -- Python 3.8.8, pytest-6.2.2, py-1.9.0, pluggy-0.13.1      
rootdir: /home/lsix/nixpkgs/Cartopy-0.18.0                                                                                               
collected 616 items                                                                                                                                                                                                                                                              

lib/cartopy/tests/test_coastline.py .                                                                                                                                                                                                                                      [  0%]
lib/cartopy/tests/test_coding_standards.py s.                                                                                                                                                                                                                              [  0%]
lib/cartopy/tests/test_crs.py ......................                                                                                                                                                                                                                       [  4%]
lib/cartopy/tests/test_crs_transform_vectors.py ........                                                                                                                                                                                                                   [  5%] 
lib/cartopy/tests/test_features.py ......                                                                                                                                                                                                                                  [  6%]
lib/cartopy/tests/test_geodesic.py .............                                                                                                                                                                                                                           [  8%] 
lib/cartopy/tests/test_img_nest.py ......X.X                                                                                                                                                                                                                               [  9%]
lib/cartopy/tests/test_img_tiles.py .........s                                                                                                                                                                                                                             [ 11%]
lib/cartopy/tests/test_img_transform.py ..................................................................                                                                                                                                                                 [ 22%]
lib/cartopy/tests/test_line_string.py ..................x                                                                                                                                                                                                                  [ 25%] 
lib/cartopy/tests/test_linear_ring.py ......                                                                                                                                                                                                                               [ 26%]
lib/cartopy/tests/test_polygon.py ............................                                                                                                                                                                                                             [ 30%] 
lib/cartopy/tests/test_shapereader.py ..s..                                                                                                                                                                                                                                [ 31%]
lib/cartopy/tests/test_util.py ........                                                                                                                                                                                                                                    [ 32%]
lib/cartopy/tests/test_vector_transform.py ......                                                                                                                                                                                                                          [ 33%]
lib/cartopy/tests/crs/test_albers_equal_area.py ........                                                                                                                                                                                                                   [ 35%] lib/cartopy/tests/crs/test_azimuthal_equidistant.py ........                                                                                                                                                                                                               [ 36%]
lib/cartopy/tests/crs/test_eckert.py ..............................................                                                                                                                                                                                        [ 43%]
lib/cartopy/tests/crs/test_equal_earth.py .....                                                                                                                                                                                                                            [ 44%]
lib/cartopy/tests/crs/test_equidistant_conic.py ........                                                                                                                                                                                                                   [ 46%] 
lib/cartopy/tests/crs/test_geostationary.py ....                                                                                                                                                                                                                           [ 46%] 
lib/cartopy/tests/crs/test_gnomonic.py ...............                                                                                                                                                                                                                     [ 49%] 
lib/cartopy/tests/crs/test_interrupted_goode_homolosine.py ....                                                                                                                                                                                                            [ 49%] 
lib/cartopy/tests/crs/test_lambert_azimuthal_equal_area.py .....                                                                                                                                                                                                           [ 50%] 
lib/cartopy/tests/crs/test_lambert_conformal.py ........                                                                                                                                                                                                                   [ 51%] 
lib/cartopy/tests/crs/test_mercator.py ........                                                                                                                                                                                                                            [ 53%] 
lib/cartopy/tests/crs/test_miller.py ..F          
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> traceback >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    def test_ellipse_globe():
        globe = ccrs.Globe(ellipse='WGS84')
        with pytest.warns(UserWarning,
                          match='does not handle elliptical globes.') as w:
            mill = ccrs.Miller(globe=globe)
>           assert len(w) == 1
E           assert 2 == 1
E            +  where 2 = len(WarningsChecker(record=True))

lib/cartopy/tests/crs/test_miller.py:58: AssertionError
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> entering PDB >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PDB post_mortem (IO-capturing turned off) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> /home/lsix/nixpkgs/Cartopy-0.18.0/lib/cartopy/tests/crs/test_miller.py(58)test_ellipse_globe()
-> assert len(w) == 1
(Pdb) p w[0].message
DeprecationWarning('`np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\nDeprecated in NumPy 1
.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations')
(Pdb) p w[1].message
UserWarning('The "Miller" projection does not handle elliptical globes.')
Pdb) c                                                                                                                                                                                                                                                                  [12/1853]

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PDB continue (IO-capturing resumed) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
....                                                                                                                                                                                                                                                                       [ 54%]
lib/cartopy/tests/crs/test_mollweide.py .........                                                                                                                                                                                                                          [ 56%]
lib/cartopy/tests/crs/test_nearside_perspective.py ...                                                                                                                                                                                                                     [ 56%]
lib/cartopy/tests/crs/test_orthographic.py ..F
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> traceback >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    def test_ellipse_globe():
        globe = ccrs.Globe(ellipse='WGS84')
        with pytest.warns(UserWarning,
                          match='does not handle elliptical globes.') as w:
            ortho = ccrs.Orthographic(globe=globe)
>           assert len(w) == (2
                              if (5, 0, 0) <= ccrs.PROJ4_VERSION < (5, 1, 0)
                              else 1)
E           assert 2 == 1
E            +  where 2 = len(WarningsChecker(record=True))

lib/cartopy/tests/crs/test_orthographic.py:59: AssertionError
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> entering PDB >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PDB post_mortem (IO-capturing turned off) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> /home/lsix/nixpkgs/Cartopy-0.18.0/lib/cartopy/tests/crs/test_orthographic.py(59)test_ellipse_globe()
-> assert len(w) == (2
(Pdb) p w[0].message
UserWarning('The "Orthographic" projection does not handle elliptical globes.')
(Pdb) p w[1].message
DeprecationWarning('`np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\nDeprecated in NumPy 1
.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations')
(Pdb) 
DeprecationWarning('`np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\nDeprecated in NumPy 1
.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations')
(Pdb) c
[…]
Full environment definition ### Operating system [Nixos](https://nixos.org) ### Cartopy version 0.18.0
akrherz commented 3 years ago

I believe this is all fixed by #1721, whcih is in for the upcoming 0.19 release.

lsix commented 3 years ago

@akrherz indeed, this fixes it!

Thanks, I’ll backport this fix until 0.19 is released!