22"""
33Internal utilities.
44"""
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+
512try : # print debugging (used with internal modules)
613 from icecream import ic
714except ImportError : # graceful fallback if IceCream isn't installed
815 ic = lambda * args : print (* args ) # noqa: E731
916
10- import inspect
11- from numbers import Integral , Real
1217
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+
1544
45+ # Internal import statements
46+ # WARNING: Must come after _not_none because this is leveraged inside other funcs
1647from . import ( # noqa: F401
1748 benchmarks ,
1849 context ,
2960# Style aliases. We use this rather than matplotlib's normalize_kwargs and _alias_maps.
3061# NOTE: We add aliases 'edgewidth' and 'fillcolor' for patch edges and faces
3162# NOTE: Alias cannot appear as key or else _translate_kwargs will overwrite with None!
32- ALIAS_MAPS = {
63+ _alias_maps = {
3364 'rgba' : {
3465 'red' : ('r' ,),
3566 'green' : ('g' ,),
@@ -201,7 +232,7 @@ def _get_aliases(category, *keys):
201232 aliases = []
202233 for key in keys :
203234 aliases .append (key )
204- aliases .extend (ALIAS_MAPS [category ][key ])
235+ aliases .extend (_alias_maps [category ][key ])
205236 return tuple (aliases )
206237
207238
@@ -213,7 +244,7 @@ def _kwargs_to_args(options, *args, allow_extra=False, **kwargs):
213244 nargs , nopts = len (args ), len (options )
214245 if nargs > nopts and not allow_extra :
215246 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
217248 args .extend (None for _ in range (nopts - nargs )) # fill missing args
218249 for idx , keys in enumerate (options ):
219250 if isinstance (keys , str ):
@@ -227,33 +258,6 @@ def _kwargs_to_args(options, *args, allow_extra=False, **kwargs):
227258 return args , kwargs
228259
229260
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-
257261def _pop_kwargs (kwargs , * keys , ** aliases ):
258262 """
259263 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):
314318 ignore = (ignore ,)
315319 prefix = prefix or '' # e.g. 'box' for boxlw, boxlinewidth, etc.
316320 for category in categories :
317- for key , aliases in ALIAS_MAPS [category ].items ():
321+ for key , aliases in _alias_maps [category ].items ():
318322 if isinstance (aliases , str ):
319323 aliases = (aliases ,)
320324 opts = {
0 commit comments