@@ -39,6 +39,17 @@ class StrategyUpdater:
3939 "sell" : "exit" ,
4040 }
4141
42+ # Update function names.
43+ # example: `np.NaN` was removed in the NumPy 2.0 release. Use `np.nan` instead.
44+ module_replacements = {
45+ "numpy" : {
46+ "aliases" : set (),
47+ "replacements" : [
48+ ("NaN" , "nan" ),
49+ ],
50+ }
51+ }
52+
4253 # create a dictionary that maps the old column names to the new ones
4354 rename_dict = {"buy" : "enter_long" , "sell" : "exit_long" , "buy_tag" : "enter_tag" }
4455
@@ -153,16 +164,24 @@ def visit_arguments(self, node):
153164 def visit_Name (self , node ):
154165 # if the name is in the mapping, update it
155166 node .id = self .check_dict (StrategyUpdater .name_mapping , node .id )
167+
168+ for mod , info in StrategyUpdater .module_replacements .items ():
169+ for old_attr , new_attr in info ["replacements" ]:
170+ if node .id == old_attr :
171+ node .id = new_attr
156172 return node
157173
158174 def visit_Import (self , node ):
159- # do not update the names in import statements
175+ for alias in node .names :
176+ if alias .name in StrategyUpdater .module_replacements :
177+ as_name = alias .asname or alias .name
178+ StrategyUpdater .module_replacements [alias .name ]["aliases" ].add (as_name )
160179 return node
161180
162181 def visit_ImportFrom (self , node ):
163- # if hasattr( node, " module") :
164- # if node.module == "freqtrade.strategy.hyper":
165- # node.module = "freqtrade.strategy"
182+ if node . module in StrategyUpdater . module_replacements :
183+ mod = node . module
184+ StrategyUpdater . module_replacements [ node .module ][ "aliases" ]. add ( mod )
166185 return node
167186
168187 def visit_If (self , node : ast_comments .If ):
@@ -182,6 +201,12 @@ def visit_Attribute(self, node):
182201 and node .attr == "nr_of_successful_buys"
183202 ):
184203 node .attr = "nr_of_successful_entries"
204+ if isinstance (node .value , ast_comments .Name ):
205+ for mod , info in StrategyUpdater .module_replacements .items ():
206+ if node .value .id in info ["aliases" ]:
207+ for old_attr , new_attr in info ["replacements" ]:
208+ if node .attr == old_attr :
209+ node .attr = new_attr
185210 return node
186211
187212 def visit_ClassDef (self , node ):
0 commit comments