Skip to content

Commit 540544b

Browse files
fix: add NumPy 2.0 compatibility for np.float_
- Handle AttributeError when np.float_ is not available in NumPy 2.0+ - Use try/except to gracefully fall back for newer NumPy versions
1 parent 47f0681 commit 540544b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

easysearch/serializer.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@
4343
np.uint32,
4444
np.uint64,
4545
)
46-
FLOAT_TYPES += (
47-
np.float_,
48-
np.float16,
49-
np.float32,
50-
np.float64,
51-
)
46+
# np.float_ was removed in NumPy 2.0
47+
float_types = [np.float16, np.float32, np.float64]
48+
try:
49+
float_types.insert(0, np.float_)
50+
except AttributeError:
51+
# NumPy 2.0+
52+
pass
53+
FLOAT_TYPES += tuple(float_types)
5254
except ImportError:
5355
np = None
5456

0 commit comments

Comments
 (0)