speedlens / fix_code.py
sidchak-gh
fix np.float replacement logic
d44acb9
import os
import re
def fix_file(path):
with open(path, "r", encoding="utf-8", errors="ignore") as f:
content = f.read()
# Replace deprecated numpy aliases with python builtins
# Use negative lookahead to avoid matching keys like np.float32, np.int64, etc.
# np.float -> float
new_content = re.sub(r'np\.float(?![0-9_a-zA-Z])', 'float', content)
# np.int -> int (deprecated in recent numpy)
new_content = re.sub(r'np\.int(?![0-9_a-zA-Z])', 'int', new_content)
# np.bool -> bool (deprecated in recent numpy)
new_content = re.sub(r'np\.bool(?![0-9_a-zA-Z])', 'bool', new_content)
if new_content != content:
print(f"Fixed deprecated types in: {path}")
with open(path, "w", encoding="utf-8") as f:
f.write(new_content)
def main():
print("Scanning for deprecated numpy types...")
for root, dirs, files in os.walk("."):
if ".git" in root: continue
for file in files:
if file.endswith(".py"):
path = os.path.join(root, file)
fix_file(path)
print("Fix complete.")
if __name__ == "__main__":
main()