Skip to content

Commit 7b45500

Browse files
committed
Improve deprecation warnings, remove figure setters
1 parent c2dcab8 commit 7b45500

File tree

9 files changed

+167
-165
lines changed

9 files changed

+167
-165
lines changed

proplot/axes/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
from .geo import GeoAxes # noqa: F401
1111
from .geo import BasemapAxes, CartopyAxes
1212
from ..internals import warnings
13-
XYAxes = warnings._rename_obj('XYAxes', CartesianAxes)
14-
ProjAxes = warnings._rename_obj('ProjAxes', GeoAxes)
13+
XYAxes, ProjAxes = warnings._rename_objs(
14+
'0.6',
15+
XYAxes=CartesianAxes,
16+
ProjAxes=GeoAxes,
17+
)
1518

1619
import matplotlib.projections as mproj
1720
mproj.register_projection(CartesianAxes)

proplot/axes/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ def _update_title_position(self, renderer):
722722
)
723723

724724
@staticmethod
725-
@warnings._rename_kwargs(mode='rc_mode')
725+
@warnings._rename_kwargs('0.6', mode='rc_mode')
726726
def _parse_format(rc_kw=None, rc_mode=None, **kwargs):
727727
"""
728728
Separate `~proplot.config.rc` setting name value pairs from

proplot/axes/plot.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ def _deprecate_add_errorbars(func):
956956
for _rename_kwargs. Use a decorator to avoid call signature pollution.
957957
"""
958958
@functools.wraps(func)
959-
def _wrapper(
959+
def wrapper(
960960
*args,
961961
bars=None, boxes=None, barstd=None, boxstd=None, barrange=None, boxrange=None,
962962
**kwargs
@@ -966,9 +966,9 @@ def _wrapper(
966966
):
967967
if b is not None or std is not None or span is not None:
968968
warnings._warn_proplot(
969-
f'Keyword args "{prefix}s", "{prefix}std", and "{prefix}range" '
969+
f"Keyword args '{prefix}s', '{prefix}std', and '{prefix}range' "
970970
'are deprecated and will be removed in a future version. '
971-
f'Please use "{prefix}stds" or "{prefix}pctiles" instead.'
971+
f"Please use '{prefix}stds' or '{prefix}pctiles' instead."
972972
)
973973
if span is None and b: # means 'use the default range'
974974
span = b
@@ -977,7 +977,7 @@ def _wrapper(
977977
else:
978978
kwargs.setdefault(prefix + 'pctiles', span)
979979
return func(*args, **kwargs)
980-
return _wrapper
980+
return wrapper
981981

982982

983983
@_deprecate_add_errorbars
@@ -2636,7 +2636,7 @@ def _build_discrete_norm(
26362636
return norm, cmap, levels, ticks
26372637

26382638

2639-
@warnings._rename_kwargs(centers='values')
2639+
@warnings._rename_kwargs('0.6', centers='values')
26402640
@docstring.add_snippets
26412641
def cmap_changer(
26422642
self, func, *args, extend='neither',
@@ -3783,13 +3783,13 @@ def _basemap_redirect(func):
37833783
name = func.__name__
37843784

37853785
@functools.wraps(func)
3786-
def _wrapper(self, *args, **kwargs):
3786+
def wrapper(self, *args, **kwargs):
37873787
if getattr(self, 'name', '') == 'basemap':
37883788
return getattr(self.projection, name)(*args, ax=self, **kwargs)
37893789
else:
37903790
return func(self, *args, **kwargs)
3791-
_wrapper.__doc__ = None
3792-
return _wrapper
3791+
wrapper.__doc__ = None
3792+
return wrapper
37933793

37943794

37953795
def _basemap_norecurse(func):
@@ -3801,14 +3801,14 @@ def _basemap_norecurse(func):
38013801
func._called_from_basemap = False
38023802

38033803
@functools.wraps(func)
3804-
def _wrapper(self, *args, **kwargs):
3804+
def wrapper(self, *args, **kwargs):
38053805
if func._called_from_basemap:
38063806
result = getattr(maxes.Axes, name)(self, *args, **kwargs)
38073807
else:
38083808
with _state_context(func, _called_from_basemap=True):
38093809
result = func(self, *args, **kwargs)
38103810
return result
3811-
return _wrapper
3811+
return wrapper
38123812

38133813

38143814
def _generate_decorator(driver):
@@ -3827,11 +3827,11 @@ def decorator(func):
38273827
# Define wrapper and suppress documentation
38283828
# We only document wrapper functions, not the methods they wrap
38293829
@functools.wraps(func)
3830-
def _wrapper(self, *args, **kwargs):
3830+
def wrapper(self, *args, **kwargs):
38313831
return driver(self, func, *args, **kwargs)
38323832
name = func.__name__
38333833
if name not in proplot_methods:
3834-
_wrapper.__doc__ = None
3834+
wrapper.__doc__ = None
38353835

38363836
# List wrapped methods in the driver function docstring
38373837
# Prevents us from having to both explicitly apply decorators in
@@ -3852,7 +3852,7 @@ def _wrapper(self, *args, **kwargs):
38523852
+ methods[-1]
38533853
)
38543854
driver.__doc__ = docstring.format(methods=string)
3855-
return _wrapper
3855+
return wrapper
38563856
return decorator
38573857

38583858

proplot/colors.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,10 +1176,13 @@ def from_list(cls, name, colors, ratios=None, **kwargs):
11761176
return cls(name, cdict, **kwargs)
11771177

11781178
# Rename methods
1179-
concatenate = warnings._rename_obj('concatenate', append)
1180-
punched = warnings._rename_obj('punched', cut)
1181-
truncated = warnings._rename_obj('truncated', truncate)
1182-
updated = warnings._rename_obj('updated', copy)
1179+
concatenate, punched, truncated, updated = warnings._rename_objs(
1180+
'0.6',
1181+
concatenate=append,
1182+
punched=cut,
1183+
truncated=truncate,
1184+
updated=copy,
1185+
)
11831186

11841187

11851188
class ListedColormap(mcolors.ListedColormap, _Colormap):
@@ -1375,9 +1378,12 @@ def from_file(cls, path, warn_on_failure=False):
13751378
return cls._from_file(path, warn_on_failure=warn_on_failure)
13761379

13771380
# Rename methods
1378-
concatenate = warnings._rename_obj('concatenate', append)
1379-
truncated = warnings._rename_obj('truncated', truncate)
1380-
updated = warnings._rename_obj('updated', copy)
1381+
concatenate, truncated, updated = warnings._rename_objs(
1382+
'0.6',
1383+
concatenate=append,
1384+
truncated=truncate,
1385+
updated=copy,
1386+
)
13811387

13821388

13831389
class PerceptuallyUniformColormap(LinearSegmentedColormap, _Colormap):
@@ -2377,7 +2383,10 @@ def _sanitize_key(self, key, mirror=True):
23772383
setattr(mcm, _cmap_database_attr, _cmap_database)
23782384

23792385
# Deprecations
2380-
CmapDict = warnings._rename_obj('CmapDict', ColormapDatabase)
2381-
ColorDict = warnings._rename_obj('ColorDict', ColorDatabase)
2382-
MidpointNorm = warnings._rename_obj('MidpointNorm', DivergingNorm)
2383-
BinNorm = warnings._rename_obj('BinNorm', DiscreteNorm)
2386+
CmapDict, ColorDict, MidpointNorm, BinNorm = warnings._rename_objs(
2387+
'0.6',
2388+
CmapDict=ColormapDatabase,
2389+
ColorDict=ColorDatabase,
2390+
MidpointNorm=DivergingNorm,
2391+
BinNorm=DiscreteNorm
2392+
)

proplot/config.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,5 +1581,8 @@ def _validate_fontsize_None(s):
15811581
cmap.N = lut
15821582

15831583
# Deprecated
1584-
inline_backend_fmt = warnings._rename_obj('inline_backend_fmt', config_inline_backend)
1585-
rc_configurator = warnings._rename_obj('RcConfigurator', config_inline_backend)
1584+
inline_backend_fmt, rc_configurator = warnings._rename_objs(
1585+
'0.6',
1586+
inline_backend_fmt=config_inline_backend,
1587+
RcConfigurator=config_inline_backend,
1588+
)

proplot/figure.py

Lines changed: 51 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import numpy as np
77
import matplotlib.figure as mfigure
88
import matplotlib.transforms as mtransforms
9-
from numbers import Integral
109
from . import axes as paxes
1110
from . import gridspec as pgridspec
1211
from .config import rc
@@ -237,12 +236,28 @@ def __init__(
237236
warnings._warn_proplot('"aligny" has no effect when spany=True.')
238237
alignx = _not_none(alignx, align, rc['subplots.align'])
239238
aligny = _not_none(aligny, align, rc['subplots.align'])
240-
self.set_alignx(alignx)
241-
self.set_aligny(aligny)
242-
self.set_sharex(sharex)
243-
self.set_sharey(sharey)
244-
self.set_spanx(spanx)
245-
self.set_spany(spany)
239+
if int(sharex) not in range(4):
240+
raise ValueError(
241+
'Invalid sharing level sharex={value!r}. '
242+
'Axis sharing level can be 0 (share nothing), '
243+
'1 (hide axis labels), '
244+
'2 (share limits and hide axis labels), or '
245+
'3 (share limits and hide axis and tick labels).'
246+
)
247+
if int(sharey) not in range(4):
248+
raise ValueError(
249+
'Invalid sharing level sharey={sharey!r}. '
250+
'Axis sharing level can be 0 (share nothing), '
251+
'1 (hide axis labels), '
252+
'2 (share limits and hide axis labels), or '
253+
'3 (share limits and hide axis and tick labels).'
254+
)
255+
self._alignx = bool(alignx)
256+
self._aligny = bool(aligny)
257+
self._sharex = int(sharex)
258+
self._sharey = int(sharey)
259+
self._spanx = bool(spanx)
260+
self._spany = bool(spany)
246261

247262
# Various other attributes
248263
gridspec_kw = gridspec_kw or {}
@@ -1293,102 +1308,48 @@ def set_size_inches(self, w, h=None, forward=True, auto=False):
12931308
with context():
12941309
super().set_size_inches(width, height, forward=forward)
12951310

1296-
def get_alignx(self):
1311+
@property
1312+
def alignx(self):
12971313
"""
1298-
Return the *x* axis label alignment mode.
1314+
The *x* axis label alignment mode.
12991315
"""
13001316
return self._alignx
13011317

1302-
def get_aligny(self):
1318+
@property
1319+
def aligny(self):
13031320
"""
1304-
Return the *y* axis label alignment mode.
1321+
The *y* axis label alignment mode.
13051322
"""
13061323
return self._aligny
13071324

1308-
def get_sharex(self):
1325+
@property
1326+
def sharex(self):
13091327
"""
1310-
Return the *x* axis sharing level.
1328+
The *x* axis sharing level.
13111329
"""
13121330
return self._sharex
13131331

1314-
def get_sharey(self):
1332+
@property
1333+
def sharey(self):
13151334
"""
1316-
Return the *y* axis sharing level.
1335+
The *y* axis sharing level.
13171336
"""
13181337
return self._sharey
13191338

1320-
def get_spanx(self):
1339+
@property
1340+
def spanx(self):
13211341
"""
1322-
Return the *x* axis label spanning mode.
1342+
The *x* axis label spanning mode.
13231343
"""
13241344
return self._spanx
13251345

1326-
def get_spany(self):
1346+
@property
1347+
def spany(self):
13271348
"""
1328-
Return the *y* axis label spanning mode.
1349+
The *y* axis label spanning mode.
13291350
"""
13301351
return self._spany
13311352

1332-
def set_alignx(self, value):
1333-
"""
1334-
Set the *x* axis label alignment mode.
1335-
"""
1336-
self.stale = True
1337-
self._alignx = bool(value)
1338-
1339-
def set_aligny(self, value):
1340-
"""
1341-
Set the *y* axis label alignment mode.
1342-
"""
1343-
self.stale = True
1344-
self._aligny = bool(value)
1345-
1346-
def set_sharex(self, value):
1347-
"""
1348-
Set the *x* axis sharing level.
1349-
"""
1350-
value = int(value)
1351-
if value not in range(4):
1352-
raise ValueError(
1353-
'Invalid sharing level sharex={value!r}. '
1354-
'Axis sharing level can be 0 (share nothing), '
1355-
'1 (hide axis labels), '
1356-
'2 (share limits and hide axis labels), or '
1357-
'3 (share limits and hide axis and tick labels).'
1358-
)
1359-
self.stale = True
1360-
self._sharex = value
1361-
1362-
def set_sharey(self, value):
1363-
"""
1364-
Set the *y* axis sharing level.
1365-
"""
1366-
value = int(value)
1367-
if value not in range(4):
1368-
raise ValueError(
1369-
'Invalid sharing level sharey={value!r}. '
1370-
'Axis sharing level can be 0 (share nothing), '
1371-
'1 (hide axis labels), '
1372-
'2 (share limits and hide axis labels), or '
1373-
'3 (share limits and hide axis and tick labels).'
1374-
)
1375-
self.stale = True
1376-
self._sharey = value
1377-
1378-
def set_spanx(self, value):
1379-
"""
1380-
Set the *x* axis label spanning mode.
1381-
"""
1382-
self.stale = True
1383-
self._spanx = bool(value)
1384-
1385-
def set_spany(self, value):
1386-
"""
1387-
Set the *y* axis label spanning mode.
1388-
"""
1389-
self.stale = True
1390-
self._spany = bool(value)
1391-
13921353
@property
13931354
def gridspec(self):
13941355
"""
@@ -1405,16 +1366,7 @@ def ref(self):
14051366
`~proplot.ui.figure` arguments are applied to this axes, and
14061367
aspect ratio is conserved for this axes in tight layout adjustment.
14071368
"""
1408-
return self._ref
1409-
1410-
@ref.setter
1411-
def ref(self, ref):
1412-
if not isinstance(ref, Integral) or ref < 1:
1413-
raise ValueError(
1414-
f'Invalid axes number {ref!r}. Must be integer >=1.'
1415-
)
1416-
self.stale = True
1417-
self._ref = ref
1369+
return self._ref_num
14181370

14191371
def _iter_axes(self, hidden=False, children=False):
14201372
"""
@@ -1438,3 +1390,13 @@ def _iter_axes(self, hidden=False, children=False):
14381390
if not hidden and ax._panel_hidden:
14391391
continue # ignore hidden panel and its colorbar/legend child
14401392
yield from ax._iter_axes(hidden=hidden, children=children)
1393+
1394+
# Deprecations
1395+
# NOTE: None of these even *worked* after drawing the figure. And not sure
1396+
# what value (if any) they add even if we do get them to work.
1397+
get_alignx, set_alignx = warnings._read_only_property('0.6', 'alignx')
1398+
get_aligny, set_aligny = warnings._read_only_property('0.6', 'aligny')
1399+
get_sharex, set_sharex = warnings._read_only_property('0.6', 'sharex')
1400+
get_sharey, set_sharey = warnings._read_only_property('0.6', 'sharey')
1401+
get_spanx, set_spanx = warnings._read_only_property('0.6', 'spanx')
1402+
get_spany, set_spany = warnings._read_only_property('0.6', 'spany')

0 commit comments

Comments
 (0)