2
2
"""
3
3
Internal utilities.
4
4
"""
5
+ # Import statements
6
+ import inspect
7
+ from numbers import Integral , Real
8
+
9
+ import numpy as np
10
+ from matplotlib import rcParams as rc_matplotlib
11
+
5
12
try : # print debugging (used with internal modules)
6
13
from icecream import ic
7
14
except ImportError : # graceful fallback if IceCream isn't installed
8
15
ic = lambda * args : print (* args ) # noqa: E731
9
16
10
- import inspect
11
- from numbers import Integral , Real
12
17
13
- import numpy as np
14
- from matplotlib import rcParams as rc_matplotlib
18
+ def _not_none (* args , default = None , ** kwargs ):
19
+ """
20
+ Return the first non-``None`` value. This is used with keyword arg aliases and
21
+ for setting default values. Use `kwargs` to issue warnings when multiple passed.
22
+ """
23
+ first = default
24
+ if args and kwargs :
25
+ raise ValueError ('_not_none can only be used with args or kwargs.' )
26
+ elif args :
27
+ for arg in args :
28
+ if arg is not None :
29
+ first = arg
30
+ break
31
+ elif kwargs :
32
+ for name , arg in list (kwargs .items ()):
33
+ if arg is not None :
34
+ first = arg
35
+ break
36
+ kwargs = {name : arg for name , arg in kwargs .items () if arg is not None }
37
+ if len (kwargs ) > 1 :
38
+ warnings ._warn_proplot (
39
+ f'Got conflicting or duplicate keyword arguments: { kwargs } . '
40
+ 'Using the first keyword argument.'
41
+ )
42
+ return first
43
+
15
44
45
+ # Internal import statements
46
+ # WARNING: Must come after _not_none because this is leveraged inside other funcs
16
47
from . import ( # noqa: F401
17
48
benchmarks ,
18
49
context ,
29
60
# Style aliases. We use this rather than matplotlib's normalize_kwargs and _alias_maps.
30
61
# NOTE: We add aliases 'edgewidth' and 'fillcolor' for patch edges and faces
31
62
# NOTE: Alias cannot appear as key or else _translate_kwargs will overwrite with None!
32
- ALIAS_MAPS = {
63
+ _alias_maps = {
33
64
'rgba' : {
34
65
'red' : ('r' ,),
35
66
'green' : ('g' ,),
@@ -201,7 +232,7 @@ def _get_aliases(category, *keys):
201
232
aliases = []
202
233
for key in keys :
203
234
aliases .append (key )
204
- aliases .extend (ALIAS_MAPS [category ][key ])
235
+ aliases .extend (_alias_maps [category ][key ])
205
236
return tuple (aliases )
206
237
207
238
@@ -213,7 +244,7 @@ def _kwargs_to_args(options, *args, allow_extra=False, **kwargs):
213
244
nargs , nopts = len (args ), len (options )
214
245
if nargs > nopts and not allow_extra :
215
246
raise ValueError (f'Expected up to { nopts } positional arguments. Got { nargs } .' )
216
- args = list (args )
247
+ args = list (args ) # WARNING: Axes.text() expects return type of list
217
248
args .extend (None for _ in range (nopts - nargs )) # fill missing args
218
249
for idx , keys in enumerate (options ):
219
250
if isinstance (keys , str ):
@@ -227,33 +258,6 @@ def _kwargs_to_args(options, *args, allow_extra=False, **kwargs):
227
258
return args , kwargs
228
259
229
260
230
- def _not_none (* args , default = None , ** kwargs ):
231
- """
232
- Return the first non-``None`` value. This is used with keyword arg aliases and
233
- for setting default values. Use `kwargs` to issue warnings when multiple passed.
234
- """
235
- first = default
236
- if args and kwargs :
237
- raise ValueError ('_not_none can only be used with args or kwargs.' )
238
- elif args :
239
- for arg in args :
240
- if arg is not None :
241
- first = arg
242
- break
243
- elif kwargs :
244
- for name , arg in list (kwargs .items ()):
245
- if arg is not None :
246
- first = arg
247
- break
248
- kwargs = {name : arg for name , arg in kwargs .items () if arg is not None }
249
- if len (kwargs ) > 1 :
250
- warnings ._warn_proplot (
251
- f'Got conflicting or duplicate keyword args: { kwargs } . '
252
- 'Using the first one.'
253
- )
254
- return first
255
-
256
-
257
261
def _pop_kwargs (kwargs , * keys , ** aliases ):
258
262
"""
259
263
Pop the input properties and return them in a new dictionary.
@@ -314,7 +318,7 @@ def _pop_props(input, *categories, prefix=None, ignore=None, skip=None):
314
318
ignore = (ignore ,)
315
319
prefix = prefix or '' # e.g. 'box' for boxlw, boxlinewidth, etc.
316
320
for category in categories :
317
- for key , aliases in ALIAS_MAPS [category ].items ():
321
+ for key , aliases in _alias_maps [category ].items ():
318
322
if isinstance (aliases , str ):
319
323
aliases = (aliases ,)
320
324
opts = {
0 commit comments