Skip to content

Commit b1815d4

Browse files
authored
finish deprecation of positional arguments (#178)
* finish deprecation of positional arguments * changelog
1 parent b60e32d commit b1815d4

File tree

7 files changed

+1
-270
lines changed

7 files changed

+1
-270
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717

1818
- Removed `infer_interval_breaks` function deprecated in v0.3.0 ([#177](https://github.com/mpytools/mplotutils/pull/177)).
19+
- Finish deprecation of positional arguments started in v0.3.0 ([#178](https://github.com/mpytools/mplotutils/pull/178)).
1920

2021
### Enhancements
2122

mplotutils/_cartopy_utils.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from cartopy.mpl.gridliner import LATITUDE_FORMATTER, LONGITUDE_FORMATTER
88

99
from mplotutils._colormaps import _get_label_attr
10-
from mplotutils._deprecate import _deprecate_positional_args
1110

1211

1312
def sample_data_map(nlons, nlats):
@@ -133,7 +132,6 @@ def cyclic_dataarray(obj, coord="lon"):
133132
return obj.assign_coords({coord: lon})
134133

135134

136-
@_deprecate_positional_args("0.3")
137135
def ylabel_map(s, *, labelpad=None, size=None, weight=None, y=0.5, ax=None, **kwargs):
138136
"""add ylabel to cartopy plot
139137
@@ -197,7 +195,6 @@ def ylabel_map(s, *, labelpad=None, size=None, weight=None, y=0.5, ax=None, **kw
197195
return h
198196

199197

200-
@_deprecate_positional_args("0.3")
201198
def xlabel_map(s, *, labelpad=None, size=None, weight=None, x=0.5, ax=None, **kwargs):
202199
"""add xlabel to cartopy plot
203200
@@ -261,7 +258,6 @@ def xlabel_map(s, *, labelpad=None, size=None, weight=None, x=0.5, ax=None, **kw
261258
return h
262259

263260

264-
@_deprecate_positional_args("0.3")
265261
def yticklabels(
266262
y_ticks,
267263
*,
@@ -362,7 +358,6 @@ def yticklabels(
362358
)
363359

364360

365-
@_deprecate_positional_args("0.3")
366361
def xticklabels(
367362
x_ticks,
368363
*,

mplotutils/_colorbar.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import matplotlib.transforms as mtransforms
66
import numpy as np
77

8-
from mplotutils._deprecate import _deprecate_positional_args
9-
108

119
def _deprecate_ax1_ax2(ax, ax2, ax1):
1210
if ax is None:
@@ -50,7 +48,6 @@ def _deprecate_ax1_ax2(ax, ax2, ax1):
5048
return ax
5149

5250

53-
@_deprecate_positional_args("0.3")
5451
def colorbar(
5552
mappable,
5653
ax=None,

mplotutils/_deprecate.py

Lines changed: 0 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,4 @@
1-
# Adapted from scikit-learn https://github.com/scikit-learn/scikit-learn/pull/13311
2-
# For reference, here is a copy of their copyright notice:
3-
4-
# BSD 3-Clause License
5-
6-
# Copyright (c) 2007-2021 The scikit-learn developers.
7-
# All rights reserved.
8-
9-
# Redistribution and use in source and binary forms, with or without
10-
# modification, are permitted provided that the following conditions are met:
11-
12-
# * Redistributions of source code must retain the above copyright notice, this
13-
# list of conditions and the following disclaimer.
14-
15-
# * Redistributions in binary form must reproduce the above copyright notice,
16-
# this list of conditions and the following disclaimer in the documentation
17-
# and/or other materials provided with the distribution.
18-
19-
# * Neither the name of the copyright holder nor the names of its
20-
# contributors may be used to endorse or promote products derived from
21-
# this software without specific prior written permission.
22-
23-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24-
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25-
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26-
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
27-
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28-
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29-
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30-
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31-
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32-
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33-
34-
import inspect
351
import warnings
36-
from functools import wraps
37-
38-
POSITIONAL_OR_KEYWORD = inspect.Parameter.POSITIONAL_OR_KEYWORD
39-
KEYWORD_ONLY = inspect.Parameter.KEYWORD_ONLY
40-
POSITIONAL_ONLY = inspect.Parameter.POSITIONAL_ONLY
41-
EMPTY = inspect.Parameter.empty
42-
43-
44-
def _deprecate_positional_args(version):
45-
"""Decorator for methods that issues warnings for positional arguments
46-
Using the keyword-only argument syntax in pep 3102, arguments after the
47-
``*`` will issue a warning when passed as a positional argument.
48-
49-
Parameters
50-
----------
51-
version : str
52-
version of the library when the positional arguments were deprecated
53-
54-
Examples
55-
--------
56-
Deprecate passing `b` as positional argument:
57-
>>> def func(a, b=1):
58-
... pass
59-
>>> @_deprecate_positional_args("v0.1.0")
60-
... def func(a, *, b=2):
61-
... pass
62-
>>> func(1, 2)
63-
64-
Notes
65-
-----
66-
This function is adapted from scikit-learn under the terms of its license. See
67-
"""
68-
69-
def _decorator(func):
70-
signature = inspect.signature(func)
71-
72-
pos_or_kw_args = []
73-
kwonly_args = []
74-
for name, param in signature.parameters.items():
75-
if param.kind in (POSITIONAL_OR_KEYWORD, POSITIONAL_ONLY):
76-
pos_or_kw_args.append(name)
77-
elif param.kind == KEYWORD_ONLY:
78-
kwonly_args.append(name)
79-
if param.default is EMPTY:
80-
# IMHO `def f(a, *, b):` does not make sense -> disallow it
81-
# if removing this constraint -> need to add these to kwargs as well
82-
raise TypeError("Keyword-only param without default disallowed.")
83-
84-
@wraps(func)
85-
def inner(*args, **kwargs):
86-
name = func.__name__
87-
n_extra_args = len(args) - len(pos_or_kw_args)
88-
if n_extra_args > 0:
89-
extra_args = ", ".join(kwonly_args[:n_extra_args])
90-
91-
warnings.warn(
92-
f"Passing '{extra_args}' as positional argument(s) to {name} "
93-
f"was deprecated in version {version} and will raise an error two "
94-
"releases later. Please pass them as keyword arguments."
95-
"",
96-
FutureWarning,
97-
stacklevel=2,
98-
)
99-
100-
zip_args = zip(kwonly_args[:n_extra_args], args[-n_extra_args:])
101-
kwargs.update({name: arg for name, arg in zip_args})
102-
103-
return func(*args[:-n_extra_args], **kwargs)
104-
105-
return func(*args, **kwargs)
106-
107-
return inner
108-
109-
return _decorator
1102

1113

1124
def _module_renamed_warning_init(attr):

mplotutils/_map_layout.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
import numpy as np
66
from mpl_toolkits.axes_grid1 import AxesGrid
77

8-
from mplotutils._deprecate import _deprecate_positional_args
98
from mplotutils._mpl import _get_renderer
109

1110

12-
@_deprecate_positional_args("0.3")
1311
def set_map_layout(obj=None, width=17.0, *, nrow=None, ncol=None, axes=None):
1412
"""set figure height, given width, taking axes' aspect ratio into account
1513

mplotutils/tests/test_colorbar.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,6 @@ def test_parse_size_aspect_pad():
7979
# =============================================================================
8080

8181

82-
@pytest.mark.parametrize("orientation", ("vertical", "horizontal"))
83-
@pytest.mark.filterwarnings("ignore:Passing axes individually")
84-
def test_colorbar_deprecate_positional(orientation):
85-
with subplots_context(1, 2) as (f, axs):
86-
h = axs[0].pcolormesh([[0, 1]])
87-
88-
with pytest.warns(
89-
FutureWarning, match="Passing 'orientation' as positional argument"
90-
):
91-
mpu.colorbar(h, axs[0], axs[0], orientation)
92-
93-
9482
def test_colorbar_deprecate_ax1_ax2_errors():
9583

9684
h = None

mplotutils/tests/test_deprecate.py

Lines changed: 0 additions & 140 deletions
This file was deleted.

0 commit comments

Comments
 (0)