feat(handlers): add built-in double-click plot handlers for common types - #248
Merged
Conversation
- Implemented default handlers for np.ndarray, pd.Series, pd.DataFrame, and xr.DataArray. - Handlers register during kernel bootstrap and can be overridden by users. - Added tests to ensure handlers function correctly and handle edge cases.
- Updated double-click plot handlers to use `ax` for plotting instead of `plt`. - Introduced `_plot_or_notice` function to handle plotting and error messaging. - Added support for non-numeric `pd.Series` and object-dtype arrays to print notices instead of raising errors. - Updated tests to verify behavior for non-numeric data and ensure proper notice printing. - Added `matplotlib` as a required dependency in `pyproject.toml`.
…ort datetime types and improve error handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds built-in double-click plot handlers so that double-clicking a tree node
whose value is a common scientific type opens a matplotlib plot.
Plot handlers (
pdv/default_handlers.py)np.ndarray,pd.Series,pd.DataFrame, andxr.DataArray,registered during kernel bootstrap (
register_defaults()), overridable by users.fig, ax(noplt.gca()ambiguity) and titlesthe axes with the tree path.
np.ndarray1D → line, 2D → imshow + colorbar, 0D/>2D → notice;pd.Series/pd.DataFrame→.plot();xr.DataArray→.plot()(1D line / 2Dpcolormesh / >2D histogram).
Series/DataFrame,object-dtype arrays, …) close the half-built figure and print a
[PDV]noticeinstead of raising — a raised exception would reach the renderer as an opaque
internal.error. The finalplt.show()is likewise guarded, so abackend-level failure degrades to a notice rather than escaping into
dispatch_handler.matplotlib & numpy dependencies
matplotlibis now a declared core dependency ofpdv-python(>=3.10.5).The floor is set by the dependency sweep: matplotlib 3.10.0 has a
Path.__deepcopy__infinite-recursion bug that breakspandas.plot(), and3.10.5 is the first release with Python 3.14 wheels.
numpy(>=2.2) is now also a core dependency. matplotlib already pullsnumpy in transitively, and
checksum.py/serialization.pyimport itdirectly — declaring it explicitly guarantees the
>=2.2floor the PDV coderelies on instead of whatever matplotlib's transitive resolution would pick.
The
dataoptional extra is consequently nowpandas-only; existingpdv-python[data]installs are unaffected since numpy still arrives via core.xarray checksum support (
pdv/checksum.py)tree_checksum()now content-hashesxr.DataArrayandxr.Datasetnodes(
KIND_DATAARRAY/KIND_DATASET) instead of falling back torepr(): dims,dtype, shape, raw values, coords, and attrs are all fed into the digest. Shared
Dataset coords are hashed once rather than once per
data_var.buffer-protocol path alongside the plain numeric dtypes, rather than the slow
repr(tolist())fallback.Test plan
pytest pdv-python/tests/— 482 passed, 2 skipped.pdv-python/scripts/sweep-deps.sh— all green (19/19 cells, exit 0:Python 3.10–3.14 × extras combos × highest/lowest-direct resolution; install +
pytest pass in every cell). Re-run after the numpy core-dependency change — the
lowest-direct cells now floor
numpyat2.2as a direct dependency.the
xr.DataArrayhistogram fallback, and suppression of the overwrite warning onre-registration.