@@ -103,7 +103,7 @@ def readRDF(self, *ar, **kw):
103103 self .cols = list (map (lambda k : str (k ), self .df .GetColumnNames ()))
104104 return self
105105
106- def Define (self , a , b , includeVariations = True ):
106+ def Define (self , a , b , excludeVariations = [] ):
107107 r"""Define a new column, if the column already exists redefine it.
108108
109109 Parameters
@@ -114,8 +114,9 @@ def Define(self, a, b, includeVariations=True):
114114 b : str
115115 The expression to be evaluated to define the new column
116116
117- includeVariations : bool, optional, default: True
118- Whether to include variations or not
117+ excludeVariations : `list of str`, optional, default: []
118+ List of pattern of variations to exlude. If ``*`` is used, all variations will
119+ be excluded and the defined column will be nominal only.
119120
120121 Returns
121122 -------
@@ -124,8 +125,9 @@ def Define(self, a, b, includeVariations=True):
124125
125126 Notes
126127 -----
127- If ``includeVariations`` is ``True``, the define expression (``b``) will be checked for variations.
128- If variations of the define expression are found, they will be defined for the new column as well.
128+ If ``excludeVariations`` is ``[]``, the define expression (``b``) will be checked for all possible variations.
129+ If variations of the define expression are found, they will be defined for the new column as well
130+ (i.e. varied ``b`` will be defined as variations of ``a``).
129131 """
130132
131133 c = self .Copy ()
@@ -138,41 +140,40 @@ def Define(self, a, b, includeVariations=True):
138140 c .df = c .df .Redefine (colName , b )
139141 c .cols = list (set (c .cols + [colName ]))
140142
141- if includeVariations :
142- # check variations
143- depVars = ParseCpp .listOfVariables (ParseCpp .parse (b ))
144- variations = {}
145- for variationName in c .variations .keys ():
146- s = list (
147- filter (
148- lambda k : k in depVars , c .variations [variationName ]["variables" ]
143+ # check variations
144+ depVars = ParseCpp .listOfVariables (ParseCpp .parse (b ))
145+ variations = {}
146+ for variationName in c .variations .keys ():
147+ if len ([1 for x in excludeVariations if fnmatch (variationName , x )]) > 0 :
148+ # if variationName matches a pattern of excludeVariations, skip it
149+ continue
150+
151+ s = list (
152+ filter (lambda k : k in depVars , c .variations [variationName ]["variables" ])
153+ )
154+ if len (s ) > 0 :
155+ # only register variations if they have an impact on "a" variable
156+ variations [variationName ] = {
157+ "tags" : c .variations [variationName ]["tags" ],
158+ "variables" : s ,
159+ }
160+
161+ for variationName in variations .keys ():
162+ varied_bs = []
163+ for tag in variations [variationName ]["tags" ]:
164+ varied_b = ParseCpp .parse (b )
165+ for variable in variations [variationName ]["variables" ]:
166+ varied_b = ParseCpp .replace (
167+ varied_b ,
168+ variable ,
169+ mRDF .variationNaming (variationName , tag , variable ),
149170 )
150- )
151- if len (s ) > 0 :
152- # only register variations if they have an impact on "a" variable
153- variations [variationName ] = {
154- "tags" : c .variations [variationName ]["tags" ],
155- "variables" : s ,
156- }
157-
158- for variationName in variations .keys ():
159- varied_bs = []
160- for tag in variations [variationName ]["tags" ]:
161- varied_b = ParseCpp .parse (b )
162- for variable in variations [variationName ]["variables" ]:
163- varied_b = ParseCpp .replace (
164- varied_b ,
165- variable ,
166- mRDF .variationNaming (variationName , tag , variable ),
167- )
168- varied_bs .append (ParseCpp .format (varied_b ))
169- _type = c .df .GetColumnType (colName )
170- expression = (
171- ParseCpp .RVecExpression (_type ) + " {" + ", " .join (varied_bs ) + "}"
172- )
173- c = c .Vary (
174- a , expression , variations [variationName ]["tags" ], variationName
175- )
171+ varied_bs .append (ParseCpp .format (varied_b ))
172+ _type = c .df .GetColumnType (colName )
173+ expression = (
174+ ParseCpp .RVecExpression (_type ) + " {" + ", " .join (varied_bs ) + "}"
175+ )
176+ c = c .Vary (a , expression , variations [variationName ]["tags" ], variationName )
176177
177178 # move back nominal value to the right column name -> a
178179 if a not in (c .cols + c .cols_d ):
@@ -244,14 +245,14 @@ def Vary(self, colName, expression, variationTags=["down", "up"], variationName=
244245
245246 # define a column that will contain the two variations in a vector of len 2
246247 c = c .Define (
247- colName + "__" + variationName , expression , includeVariations = False
248+ colName + "__" + variationName , expression , excludeVariations = [ "*" ]
248249 )
249250
250251 for i , variationTag in enumerate (variationTags ):
251252 c = c .Define (
252253 mRDF .variationNaming (variationName , variationTag , colName ),
253254 colName + "__" + variationName + "[" + str (i ) + "]" ,
254- includeVariations = False ,
255+ excludeVariations = [ "*" ] ,
255256 )
256257
257258 c = c .DropColumns (colName + "__" + variationName )
0 commit comments