88itself, whereas the generatable content must be edited via templates in
99this file.
1010
11+ This file is python 3 only due to the use of `inspect`
1112"""
1213# We did try to do the wrapping the smart way,
1314# with callable functions and new.function, but could never get the
@@ -209,9 +210,12 @@ def format_value(value):
209210 mappable = ''
210211
211212 # Get argspec of wrapped function
212- work_func = getattr (Axes , func )
213- if hasattr (work_func , '__wrapped__' ):
214- work_func = work_func .__wrapped__
213+ base_func = getattr (Axes , func )
214+ has_data = 'data' in inspect .signature (base_func ).parameters
215+ if hasattr (base_func , '__wrapped__' ):
216+ work_func = base_func .__wrapped__
217+ else :
218+ work_func = base_func
215219
216220 args , varargs , varkw , defaults = inspect .getargspec (work_func )
217221
@@ -227,6 +231,15 @@ def format_value(value):
227231 def_edited .append (val )
228232 defaults = tuple (def_edited )
229233
234+ # Add a data keyword argument if needed (fmt is PLOT_TEMPLATE) and
235+ # possible (if *args is used, we can't just add a data
236+ # argument in front of it since it would gobble one of the
237+ # arguments the user means to pass via *args)
238+ # This needs to be done here so that it goes into call
239+ if not varargs and fmt is PLOT_TEMPLATE and has_data :
240+ args .append ('data' )
241+ defaults = defaults + (None ,)
242+
230243 # How to call the wrapped function
231244 call = []
232245 for i , arg in enumerate (args ):
@@ -235,6 +248,14 @@ def format_value(value):
235248 else :
236249 call .append ('%s=%s' % (arg , arg ))
237250
251+ # remove the data keyword as it was needed above to go into the
252+ # call but should go after `hold` in the signature.
253+ # This is janky as all get out, but hopefully boilerplate will
254+ # be retired soon.
255+ if not varargs and fmt is PLOT_TEMPLATE and has_data :
256+ args .pop ()
257+ defaults = defaults [:- 1 ]
258+
238259 if varargs is not None :
239260 call .append ('*' + varargs )
240261 if varkw is not None :
@@ -254,6 +275,9 @@ def format_value(value):
254275 elif fmt is PLOT_TEMPLATE :
255276 args .append ('hold' )
256277 defaults = defaults + (None ,)
278+ if has_data :
279+ args .append ('data' )
280+ defaults = defaults + (None ,)
257281 sethold = ''
258282
259283 # Now we can build the argspec for defining the wrapper
0 commit comments