File size: 1,166 Bytes
d44acb9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | 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()
|