Skip to content

Commit 3423550

Browse files
committed
Add stacklevel and category to warnings.
For top-level functions and class init, bump stack level to 2; for internal methods, bump to 3.
1 parent a9192f8 commit 3423550

File tree

5 files changed

+49
-22
lines changed

5 files changed

+49
-22
lines changed

lib/cartopy/crs.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,9 @@ def __init__(self, central_longitude=-96.0, central_latitude=39.0,
11721172
elif secant_latitudes is not None:
11731173
warnings.warn('secant_latitudes has been deprecated in v0.12. '
11741174
'The standard_parallels keyword can be used as a '
1175-
'direct replacement.')
1175+
'direct replacement.',
1176+
DeprecationWarning,
1177+
stacklevel=2)
11761178
standard_parallels = secant_latitudes
11771179
elif standard_parallels is None:
11781180
# The default. Put this as a keyword arg default once
@@ -1436,12 +1438,14 @@ def __init__(self, central_latitude=0.0, central_longitude=0.0,
14361438
'The Stereographic projection in Proj older than '
14371439
'5.0.0 incorrectly transforms points when '
14381440
'central_latitude=0. Use this projection with '
1439-
'caution.')
1441+
'caution.',
1442+
stacklevel=2)
14401443
else:
14411444
warnings.warn(
14421445
'Cannot determine Proj version. The Stereographic '
14431446
'projection may be unreliable and should be used with '
1444-
'caution.')
1447+
'caution.',
1448+
stacklevel=2)
14451449

14461450
proj4_params = [('proj', 'stere'), ('lat_0', central_latitude),
14471451
('lon_0', central_longitude),
@@ -1451,7 +1455,8 @@ def __init__(self, central_latitude=0.0, central_longitude=0.0,
14511455
if central_latitude not in (-90., 90.):
14521456
warnings.warn('"true_scale_latitude" parameter is only used '
14531457
'for polar stereographic projections. Consider '
1454-
'the use of "scale_factor" instead.')
1458+
'the use of "scale_factor" instead.',
1459+
stacklevel=2)
14551460
proj4_params.append(('lat_ts', true_scale_latitude))
14561461

14571462
if scale_factor is not None:
@@ -1529,11 +1534,13 @@ def __init__(self, central_longitude=0.0, central_latitude=0.0,
15291534
warnings.warn(
15301535
'The Orthographic projection in the v5.0.x series of Proj '
15311536
'incorrectly transforms points. Use this projection with '
1532-
'caution.')
1537+
'caution.',
1538+
stacklevel=2)
15331539
else:
15341540
warnings.warn(
15351541
'Cannot determine Proj version. The Orthographic projection '
1536-
'may be unreliable and should be used with caution.')
1542+
'may be unreliable and should be used with caution.',
1543+
stacklevel=2)
15371544

15381545
proj4_params = [('proj', 'ortho'), ('lon_0', central_longitude),
15391546
('lat_0', central_latitude)]
@@ -1865,11 +1872,13 @@ def __init__(self, central_longitude=0, globe=None,
18651872
warnings.warn('The Robinson projection in the v4.8.x series '
18661873
'of Proj contains a discontinuity at '
18671874
'40 deg latitude. Use this projection with '
1868-
'caution.')
1875+
'caution.',
1876+
stacklevel=2)
18691877
else:
18701878
warnings.warn('Cannot determine Proj version. The Robinson '
18711879
'projection may be unreliable and should be used '
1872-
'with caution.')
1880+
'with caution.',
1881+
stacklevel=2)
18731882

18741883
proj4_params = [('proj', 'robin'), ('lon_0', central_longitude)]
18751884
super(Robinson, self).__init__(proj4_params, central_longitude,
@@ -2291,11 +2300,13 @@ def __init__(self, central_longitude=0.0, central_latitude=0.0,
22912300
warnings.warn('The Azimuthal Equidistant projection in Proj '
22922301
'older than 4.9.2 incorrectly transforms points '
22932302
'farther than 90 deg from the origin. Use this '
2294-
'projection with caution.')
2303+
'projection with caution.',
2304+
stacklevel=2)
22952305
else:
22962306
warnings.warn('Cannot determine Proj version. The Azimuthal '
22972307
'Equidistant projection may be unreliable and '
2298-
'should be used with caution.')
2308+
'should be used with caution.',
2309+
stacklevel=2)
22992310

23002311
proj4_params = [('proj', 'aeqd'), ('lon_0', central_longitude),
23012312
('lat_0', central_latitude),

lib/cartopy/io/img_tiles.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,9 @@ class StamenTerrain(Stamen):
348348
def __init__(self):
349349
warnings.warn(
350350
"The StamenTerrain class was deprecated in v0.17. "
351-
"Please use Stamen('terrain-background') instead.")
351+
"Please use Stamen('terrain-background') instead.",
352+
DeprecationWarning,
353+
stacklevel=2)
352354

353355
# NOTE: This subclass of Stamen exists for legacy reasons.
354356
# No further Stamen subclasses will be accepted as

lib/cartopy/io/srtm.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# (C) British Crown Copyright 2011 - 2018, Met Office
1+
# (C) British Crown Copyright 2011 - 2019, Met Office
22
#
33
# This file is part of cartopy.
44
#
@@ -242,7 +242,9 @@ def srtm(lon, lat):
242242
Elevation is in meters.
243243
"""
244244
warnings.warn("This method has been deprecated. "
245-
"See the \"What's new\" section for v0.12.")
245+
"See the \"What's new\" section for v0.12.",
246+
DeprecationWarning,
247+
stacklevel=2)
246248
return SRTM3Source().single_tile(lon, lat)
247249

248250

@@ -294,7 +296,9 @@ def fill_gaps(elevation, max_distance=10):
294296
295297
"""
296298
warnings.warn("The fill_gaps function has been deprecated. "
297-
"See the \"What's new\" section for v0.14.")
299+
"See the \"What's new\" section for v0.14.",
300+
DeprecationWarning,
301+
stacklevel=2)
298302
# Lazily import osgeo - it is only an optional dependency for cartopy.
299303
from osgeo import gdal
300304
from osgeo import gdal_array
@@ -314,7 +318,9 @@ def fill_gaps(elevation, max_distance=10):
314318

315319
def srtm_composite(lon_min, lat_min, nx, ny):
316320
warnings.warn("This method has been deprecated. "
317-
"See the \"What's new\" section for v0.12.")
321+
"See the \"What's new\" section for v0.12.",
322+
DeprecationWarning,
323+
stacklevel=2)
318324
return SRTM3Source().combined(lon_min, lat_min, nx, ny)
319325

320326

@@ -382,7 +388,9 @@ def SRTM3_retrieve(lon, lat):
382388
383389
"""
384390
warnings.warn("This method has been deprecated. "
385-
"See the \"What's new\" section for v0.12.")
391+
"See the \"What's new\" section for v0.12.",
392+
DeprecationWarning,
393+
stacklevel=2)
386394
return SRTM3Source().srtm_fname(lon, lat)
387395

388396

lib/cartopy/mpl/clip_path.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# (C) British Crown Copyright 2013 - 2018, Met Office
1+
# (C) British Crown Copyright 2013 - 2019, Met Office
22
#
33
# This file is part of cartopy.
44
#
@@ -62,7 +62,9 @@ def clip_path(subject, clip_bbox):
6262
warnings.warn("This method has been deprecated. "
6363
"You can replace ``clip_path(subject, clip_bbox)`` by "
6464
"``subject.clip_to_bbox(clip_bbox)``. "
65-
"See the \"What's new\" section for v0.17.")
65+
"See the \"What's new\" section for v0.17.",
66+
DeprecationWarning,
67+
stacklevel=2)
6668
return subject.clip_to_bbox(clip_bbox)
6769

6870

lib/cartopy/mpl/geoaxes.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,9 @@ def outline_patch(self):
332332
"""
333333
warnings.warn("The outline_patch property is deprecated. Use "
334334
"GeoAxes.spines['geo'] or the default Axes properties "
335-
"instead.")
335+
"instead.",
336+
DeprecationWarning,
337+
stacklevel=2)
336338
return self.spines['geo']
337339

338340
def add_image(self, factory, *args, **kwargs):
@@ -612,7 +614,9 @@ def natural_earth_shp(self, name='land', resolution='110m',
612614
613615
"""
614616
warnings.warn('This method has been deprecated.'
615-
' Please use `add_feature` instead.')
617+
' Please use `add_feature` instead.',
618+
DeprecationWarning,
619+
stacklevel=2)
616620
kwargs.setdefault('edgecolor', 'face')
617621
kwargs.setdefault('facecolor', cartopy.feature.COLORS['land'])
618622
feature = cartopy.feature.NaturalEarthFeature(category, name,
@@ -1584,7 +1588,6 @@ def _pcolormesh_patched(self, *args, **kwargs):
15841588
See PATCH comments below.
15851589
15861590
"""
1587-
import warnings
15881591
import matplotlib.colors as mcolors
15891592
import matplotlib.collections as mcoll
15901593

@@ -1697,7 +1700,8 @@ def _pcolormesh_patched(self, *args, **kwargs):
16971700
if collection.get_cmap()._rgba_bad[3] != 0.0:
16981701
warnings.warn("The colormap's 'bad' has been set, but "
16991702
"in order to wrap pcolormesh across the "
1700-
"map it must be fully transparent.")
1703+
"map it must be fully transparent.",
1704+
stacklevel=3)
17011705

17021706
# at this point C has a shape of (Ny-1, Nx-1), to_mask has
17031707
# a shape of (Ny, Nx-1) and pts has a shape of (Ny*Nx, 2)

0 commit comments

Comments
 (0)