Skip to content

Fix ValueError when addplot column is all NaN#697

Open
wavebyrd wants to merge 864 commits intomatplotlib:masterfrom
wavebyrd:fix-nan-addplot-columns
Open

Fix ValueError when addplot column is all NaN#697
wavebyrd wants to merge 864 commits intomatplotlib:masterfrom
wavebyrd:fix-nan-addplot-columns

Conversation

@wavebyrd
Copy link

Summary

When all values in an addplot column are NaN, _addplot_columns filters
out NaN values into yd, which becomes an empty list. Calling
np.nanmax() / np.nanmin() on that empty list raises:

ValueError: zero-size array to reduction operation maximum which has no identity

This adds a length check before the nanmax/nanmin calls. When there is
no real data, secondary_y auto-detection is skipped and the column is
plotted on the primary y-axis. matplotlib already handles all-NaN series
gracefully in the actual plot/scatter/bar calls, so nothing else needs
to change.

Reproduction

import numpy as np
import pandas as pd
import mplfinance as mpf

# (generate OHLC DataFrame `df`)
df["signal"] = np.nan
ap = mpf.make_addplot(df["signal"])
mpf.plot(df, type="candle", addplot=ap)  # ValueError before fix

Test plan

  • Verified the reproduction script from Bug Report: Errors occur for NaN columns. #672 runs without error
  • Verified normal addplot data (non-NaN) still works
  • Verified partial NaN addplot data still works
  • Verified multiple addplots with one all-NaN column still works

Fixes #672

add input requirement

checkout based on input reference

test cat _version.py file

test publish

use publish v1 (instead of release/v1), and p3.x instead of p3.9

apparently @release/v1 is needed (not just @v1)

now try twine

publishTestPyPI and publishPyPI workflows
GitHub Actions workflows to deploy package to PyPI and TestPyPI
add status badge for mplfinance checks
Minor Changes to README, to Workflow, and change Dev Status from alpha to beta
Adding edgecolors and linewidths **for `type=scatter`**
Support `marketcolors` kwarg in `make_addplot()`
DrChandrakant and others added 29 commits June 12, 2023 18:51
As Per Suggestion All Exam Update
- Used OHLCV Data Only
- Calculation Within Notebook
- Detail Description Calculation
- Details mplfinance function used
add scratch work from issue436 and stackoverflow 75737197
move indicator examples into indicator directory
Style Enhancements, and add styles from Chandrakant
API for adding labels: `mpf.make_addplot(..., label="myLabel")`
some clarification on fork/clone workflow.
regenerate price-movements notebook, and other cleanup
When all values in an addplot column are NaN, the filtered array `yd`
is empty. Calling np.nanmax() or np.nanmin() on an empty array raises
ValueError. Guard against this by checking len(yd) before computing
min/max, and default to the primary y-axis when there is no real data.

Fixes matplotlib#672
@rcomer
Copy link
Member

rcomer commented Mar 13, 2026

This account has been blocked from the Matplotlib organisation for automating PRs matplotlib/matplotlib#31296 (comment)

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.

Bug Report: Errors occur for NaN columns.