Skip to content

Accept NumPy scalar positions and counts in sample_colorscale - #5900

Open
xhl123XHL352 wants to merge 1 commit into
plotly:mainfrom
xhl123XHL352:xhl/accept-numpy-scalar-color-samples
Open

xhl123XHL352 wants to merge 1 commit into
plotly:mainfrom
xhl123XHL352:xhl/accept-numpy-scalar-color-samples

Conversation

@xhl123XHL352

@xhl123XHL352 xhl123XHL352 commented Nov 24, 2026 •

Copy link
Copy Markdown

Link to issue

Minimal reproduction

Description of change

sample_colorscale raises TypeError when passed a numpy.float32 position or a numpy.int32 sample count. Recognize real and integral scalars so NumPy numeric scalars follow the same paths as Python floats and integers.

Demo

import numpy as np
from plotly.colors import sample_colorscale

sample_colorscale('Viridis', np.float32(0.625))

The call returns ['rgb(45, 174, 127)'].

Testing strategy

The five NumPy regression cases failed on the base revision and passed with the fix. Ran pytest -q tests/test_core/test_colors tests/test_plotly_utils/colors tests/test_optional/test_px/test_colors.py (36 passed).

The modified Python files pass checks and formatting with the repository's pinned Ruff 0.11.12.

Additional information

Prepared and verified with assistance from OpenAI Codex.

Guidelines

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant