Skip to content

Commit 5e663ba

Browse files
committed
gnuplotlib works with numpy2
Numpy2 doesn't have np.string_ anymore, so extra code is needed to support both numpy1 and numpy2
1 parent f22737f commit 5e663ba

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

gnuplotlib.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1900,7 +1900,14 @@ def write_element(e):
19001900
labels with spaces in them
19011901
19021902
'''
1903-
if type(e) is np.string_ or type(e) is np.str_:
1903+
1904+
# Numpy 2 broke this (no more np.string_), and this extra
1905+
# code is needed to work with both numpy 2 and numpy 1
1906+
try: is_string = type(e) is np.string_
1907+
except: is_string = False
1908+
try: is_bytes = type(e) is np.bytes_
1909+
except: is_bytes = False
1910+
if is_string or is_bytes or type(e) is np.str_:
19041911
pipe.write(b'"')
19051912
pipe.write(str(e).encode())
19061913
pipe.write(b'"')

0 commit comments

Comments
 (0)