@@ -459,50 +459,34 @@ def funcy(ax, x, y, z, bar=None):
459459
460460
461461def test_positional_parameter_names_as_function ():
462- #
463- # this is a replace for plot, which can take args as
464- # x,y,c,x,y,c or x,y,x,y,c,x,y
465- def replacer (args , data ):
466- _replacer = []
467- remaining = args
468- while 1 :
469- if len (remaining ) == 1 :
470- import warnings
471-
472- msg = "Missing argument: color spec ('c=..') is in data?"
473- warnings .warn (msg , RuntimeWarning , stacklevel = 3 )
474- _replacer += ["x" ]
475- elif len (remaining ) == 2 :
476- _replacer += ["x" , "y" ]
477- elif len (remaining ) == 3 :
478- if remaining [2 ] in data :
479- import warnings
480-
481- msg = "Found a color spec ('c') in data."
482- warnings .warn (msg , RuntimeWarning , stacklevel = 3 )
483- _replacer += ["x" , "y" , "c" ]
484-
485- if len (remaining ) <= 3 :
486- return _replacer
487-
488- # More than 3 -> split off the beginning and continue
489- if remaining [2 ] not in data :
490- _replacer += ["x" , "y" , "c" ]
491- isplit = 3
492- else :
493- _replacer += ["x" , "y" ]
494- isplit = 2
495- remaining = remaining [isplit :]
462+ # Also test the _plot_arg_replacer for plot...
463+ from matplotlib .axes ._axes import _plot_args_replacer
496464
465+ # this is a replace for plot, which can take args as
466+ # x,y,c,x,y,c or x,y,x,y,c,x,y or any other way... :-/
497467 @unpack_labeled_data (replace_names = ["x" , "y" ],
498- positional_parameter_names = replacer )
468+ positional_parameter_names = _plot_args_replacer )
499469 def funcy (ax , * args , ** kwargs ):
500470 return "{args} | {kwargs}" .format (args = args , kwargs = kwargs )
501471
502472 data = {"x" : "X" , "y" : "Y" }
473+ assert_equal (funcy (None , "x" , "y" , data = data ),
474+ "('X', 'Y') | {}" )
475+ assert_equal (funcy (None , "x" , "y" , "c" , data = data ),
476+ "('X', 'Y', 'c') | {}" )
503477 assert_equal (funcy (None , "x" , "y" , "c" , "x" , "y" , "x" , "y" , data = data ),
504478 "('X', 'Y', 'c', 'X', 'Y', 'X', 'Y') | {}" )
479+
480+ # the color spec should not be in data...
505481 data = {"x" : "X" , "y" : "Y" , "c" : "!!" }
506482 with assert_produces_warning (RuntimeWarning ):
507483 assert_equal (funcy (None , "x" , "y" , "c" , "x" , "y" , "x" , "y" , data = data ),
508484 "('X', 'Y', '!!', 'X', 'Y', 'X', 'y') | {}" )
485+
486+ # And this is the case which we screw up, as we can't distinguish
487+ # between a color spec and data...
488+ # -> This test should actually produce a warning, if someone finds a way
489+ # to distinguish between data and color spec...
490+ with assert_produces_warning (False ):
491+ assert_equal (funcy (None , "x" , "y" , "c" , "x" , "y" , "c" , data = data ),
492+ "('X', 'Y', '!!', 'X', 'Y', '!!') | {}" )
0 commit comments