Skip to content

Commit d1fa7e5

Browse files
authored
Use pandas type checking for numeric dtype detection in Altair backend
Replace np.issubdtype() with pandas.api.types.is_numeric_dtype() to fix compatibility with pandas 3.0's new StringDtype. NumPy's np.issubdtype() cannot handle pandas ExtensionDtype objects, particularly the new StringDtype introduced as default in pandas 3.0. This caused TypeError when checking if color columns were numeric: "Cannot interpret '<StringDtype(storage='python', na_value=nan)>' as a data type" Using pandas' is_numeric_dtype() provides several benefits: - Correctly handles all pandas dtypes (native NumPy and extension types) - Works with numeric extension dtypes (Int64, Float64, Decimal, etc.) - Compatible with both pandas 2.x and 3.x - More semantically clear - checks if data is numeric rather than checking dtype inheritance hierarchy
1 parent ba82fa5 commit d1fa7e5

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mesa/visualization/backends/altair_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def draw_agents(
276276
vmin = kwargs.pop("vmin", None)
277277
vmax = kwargs.pop("vmax", None)
278278

279-
color_is_numeric = np.issubdtype(df["original_color"].dtype, np.number)
279+
color_is_numeric = pd.api.types.is_numeric_dtype(df["original_color"])
280280
if color_is_numeric:
281281
color_min = vmin if vmin is not None else df["original_color"].min()
282282
color_max = vmax if vmax is not None else df["original_color"].max()

0 commit comments

Comments
 (0)