Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bde9f36

Browse files
committed
fix: add compatibility for NumPy bool_ type in variable explorer
This update introduces a new function, _get_type_name, to ensure that the type name for NumPy's bool_ is consistently returned as 'bool_' across different Python versions, particularly for Python 3.13. The variable type retrieval in _get_variable_dict_entry has been updated to use this new function.
1 parent e069c12 commit bde9f36

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ repos:
1111
hooks:
1212
- id: flake8
1313
name: flake8
14-
entry: poetry run flake8 -j auto
14+
entry: mise exec -- poetry run flake8 -j auto
1515
language: system
1616
types: [python]
1717

1818
- id: isort
1919
name: isort
20-
entry: poetry run isort
20+
entry: mise exec -- poetry run isort
2121
language: system
2222
types: [python]
2323
args: ["--filter-files"]

deepnote_toolkit/variable_explorer.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,27 @@ def _to_int(x):
407407
return int(x) if x else None
408408

409409

410+
def _get_type_name(v):
411+
"""
412+
Get the normalized type name for a variable with backwards compatibility.
413+
414+
In Python 3.13, NumPy's bool_ type may report as 'bool' instead of 'bool_'.
415+
This function ensures we always return 'bool_' for NumPy bool types to maintain
416+
compatibility with older Python versions.
417+
"""
418+
# Check for NumPy bool_ type first (most reliable check)
419+
# This handles the case where Python 3.13 reports np.bool_ as 'bool'
420+
try:
421+
if np is not None and isinstance(v, np.bool_):
422+
return "bool_"
423+
except (AttributeError, TypeError):
424+
# If numpy types change or there's an issue with the comparison
425+
pass
426+
427+
# Fall back to standard type name
428+
return type(v).__name__
429+
430+
410431
def _get_variable_dict_entry(var_name, v):
411432
try:
412433
shape = _get_shape(v)
@@ -415,7 +436,7 @@ def _get_variable_dict_entry(var_name, v):
415436
underlying_data_type = _get_underlying_data_type(v)
416437
var_result = {
417438
"varName": var_name,
418-
"varType": type(v).__name__,
439+
"varType": _get_type_name(v),
419440
"varSize": _to_int(_get_size(v)),
420441
"varShape": shape,
421442
"varContent": _get_content(v),

0 commit comments

Comments
 (0)