OpenBB-finance/OpenBB · error · ValueError

No data is left after dropping NaN values. Try setting `drop

Error message

No data is left after dropping NaN values. Try setting `dropnan = False`, or use the `frequency` parameter on request.

What it means

After aligning the data, the FRED charting view drops NaN rows when dropna=True (the default); if the remaining frame is empty or has fewer than 2 rows, nothing can be plotted and this ValueError is raised. The message points at the two levers: disabling dropna or requesting a transformed/aligned frequency so the series overlap.

Source

Thrown at openbb_platform/extensions/economy/openbb_economy/economy_views.py:82

        else:
            df_ta = basemodel_to_df(kwargs["obbject_item"], index="date")  # type: ignore

        # Check for unsupported external data injection.
        if allow_unsafe is False and data_cols:
            for data_col in data_cols:
                if data_col not in columns:
                    raise RuntimeError(
                        f"Column '{data_col}' was not found in the original data."
                        + " External data injection is not supported unless `allow_unsafe = True`."
                    )

        # Align the data so each column has the same index and length.
        if dropnan:
            df_ta = df_ta.dropna(how="any")

        if df_ta.empty or len(df_ta) < 2:
            raise ValueError(
                "No data is left after dropping NaN values. Try setting `dropnan = False`,"
                + " or use the `frequency` parameter on request."
            )

        columns = df_ta.columns.to_list()

        metadata = kwargs["extra"].get("results_metadata", {})  # type: ignore

        # Check if the request was transformed by the FRED API.
        params = kwargs["extra_params"] if kwargs.get("extra_params") else {}
        has_params = hasattr(params, "transform") and params.transform is not None  # type: ignore

        # Get a unique list of all units of measurement in the DataFrame.
        y_units = list({metadata.get(col).get("units") for col in columns if col in metadata})  # type: ignore
        if has_params is True and not y_units:
            y_units = [ytitle_dict.get(params.transform)]  # type: ignore

        if normalize or (

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Set dropnan=False in the charting kwargs so rows with partial NaNs are kept.
  2. Request data with a matching frequency/transform on the FRED request (e.g. transform='pch', annual aggregation) so indexes align.
  3. Pre-align your injected data with join/how='inner' or forward-fill before passing it in.
  4. Verify each series is non-empty: check res.to_df().dropna(how='all') before charting.

Example fix

# before
fig = obb.economy.fred.series(['GDP','DGS10'], provider='fred').charting.fred()  # misaligned dates -> all NaN

# after
fig = obb.economy.fred.series(['GDP','DGS10'], provider='fred').charting.fred(dropnan=False)
# or align via transform:
fig = obb.economy.fred.series(['GDP','DGS10'], provider='fred', transform='a').charting.fred()
Defensive patterns

Strategy: validation

Validate before calling

df = res.to_df()
aligned = df.dropna(how='any') if dropnan else df
if len(aligned) < 2:
    # fall back: keep partial rows
    aligned = df.dropna(how='all')
assert len(aligned) >= 2, 'no overlapping dates across series'

Type guard

def has_overlapping_rows(df, min_rows: int = 2) -> bool:
    """True when at least `min_rows` survive an inner alignment."""
    return len(df.dropna(how='any')) >= min_rows

Try / catch

try:
    fig = res.charting.fred()
except ValueError as e:
    if 'No data is left after dropping NaN' in str(e):
        fig = res.charting.fred(dropnan=False)
    else:
        raise

Prevention

When it happens

Trigger: Plotting multiple FRED series with mismatched publication dates (annual vs daily) where dropna(how='any') removes every row; a single series that is all-NaN after alignment; charting with dropnan=True on sparse quarterly data.

Common situations: Comparing series with different frequencies (GDP quarterly vs CPI monthly), series with leading NaNs from different start dates, or providers returning nulls for recent periods.

Related errors


AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14). Data as JSON: /api/errors/dabb80b8b7a8936a. Report an issue: GitHub.