Spaces:
Sleeping
Sleeping
File size: 1,623 Bytes
77a71b4 | 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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | """
NumPy compatibility patches.
This module patches NumPy to restore deprecated attributes for compatibility
with older packages like madmom that still use np.float, np.int, etc.
"""
import warnings
import numpy as np
# Suppress the deprecation warnings for numpy patches
warnings.filterwarnings("ignore", message=".*np.float.*deprecated.*")
warnings.filterwarnings("ignore", message=".*np.int.*deprecated.*")
warnings.filterwarnings("ignore", message=".*np.bool.*deprecated.*")
import os
_DEBUG = (os.getenv('FLASK_ENV') == 'development' or str(os.getenv('DEBUG', 'false')).lower() == 'true')
_LOGGED = False
def patch_numpy_compatibility():
"""
Patch numpy to restore deprecated attributes for compatibility with older packages.
This fixes compatibility issues with:
- madmom (uses np.float in io/__init__.py)
- other packages that rely on deprecated numpy attributes
"""
global _LOGGED
msgs = []
# Restore deprecated numpy attributes if they don't exist
if not hasattr(np, 'float'):
np.float = np.float64
msgs.append("Applied numpy patch: np.float -> np.float64")
if not hasattr(np, 'int'):
np.int = np.int_
msgs.append("Applied numpy patch: np.int -> np.int_")
if not hasattr(np, 'complex'):
np.complex = np.complex128
msgs.append("Applied numpy patch: np.complex -> np.complex128")
if not hasattr(np, 'bool'):
np.bool = np.bool_
msgs.append("Applied numpy patch: np.bool -> np.bool_")
if _DEBUG and not _LOGGED and msgs:
for m in msgs:
print(m)
_LOGGED = True
|