From fac2bd450fac5e0b69ca33f11c931f8b1b0b79fa Mon Sep 17 00:00:00 2001 From: Wei-Lun Li Date: Sun, 15 Nov 2026 19:40:37 +0000 Subject: [PATCH] fix(famafrench): select the 'Not Reqd' tables when all_data_items_required=False (#7823) get_international_portfolio filtered the frames and their metadata with different conditions when all_data_items_required is False. The frames kept the tables without "Not Reqd" in the description, which are the "Required" tables, and the metadata kept descriptions ending with "Not Reqd", which the ex-dividend files never do because their descriptions end with " - Ex-Dividends". So with dividends=True the call returned the "All 4 Data Items Required" returns under the "Not Reqd" description, and with dividends=False the metadata list was empty and transform_data raised IndexError. The documented example obb.famafrench.country_portfolio_returns(frequency="annual", measure="local", country="japan", dividends=False, all_data_items_required=False) fails with "[Unexpected Error] -> IndexError -> list index out of range". Filter both lists on "Not Reqd" in the description. Co-authored-by: dlee-bq Co-authored-by: Danglewood <85772166+deeleeramone@users.noreply.github.com> --- .../openbb_famafrench/utils/helpers.py | 10 ++---- .../famafrench/tests/test_helpers.py | 35 +++++++++++++++++++ 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/openbb_platform/providers/famafrench/openbb_famafrench/utils/helpers.py b/openbb_platform/providers/famafrench/openbb_famafrench/utils/helpers.py index 414b7786d70..7afa4eceb79 100644 --- a/openbb_platform/providers/famafrench/openbb_famafrench/utils/helpers.py +++ b/openbb_platform/providers/famafrench/openbb_famafrench/utils/helpers.py @@ -754,15 +754,9 @@ def get_international_portfolio( if all_data_items_required is False and measure != "ratios": dfs = [ - df - for df, meta in zip(dfs, dfs_meta) - if "Not Reqd" not in meta["description"] - ] - dfs_meta = [ - meta - for meta in dfs_meta - if meta.get("description", "").endswith("Not Reqd") + df for df, meta in zip(dfs, dfs_meta) if "Not Reqd" in meta["description"] ] + dfs_meta = [meta for meta in dfs_meta if "Not Reqd" in meta["description"]] elif all_data_items_required is True: dfs = [ df for df, meta in zip(dfs, dfs_meta) if "Required" in meta["description"] diff --git a/openbb_platform/providers/famafrench/tests/test_helpers.py b/openbb_platform/providers/famafrench/tests/test_helpers.py index 9d9b67c7e2b..4a587d4edd3 100644 --- a/openbb_platform/providers/famafrench/tests/test_helpers.py +++ b/openbb_platform/providers/famafrench/tests/test_helpers.py @@ -5,6 +5,7 @@ import io import zipfile import pytest +from pandas import DataFrame from openbb_famafrench.utils import helpers @@ -646,6 +647,40 @@ def test_get_international_portfolio_invalid_measure(monkeypatch): helpers.get_international_portfolio(country="japan", measure="bogus") +@pytest.mark.parametrize("suffix", ["", " - Ex-Dividends"]) +def test_get_international_portfolio_all_data_items_not_required(monkeypatch, suffix): + """all_data_items_required=False returns the 'Not Reqd' table with its metadata.""" + tables = [ + ("Value-Weight Local Returns All 4 Data Items Not Reqd", 1.0), + ("Value-Weight Local Returns All 4 Data Items Required", 2.0), + ] + dataframes = [DataFrame({"mkt": [value]}) for _, value in tables] + metadata = [ + {"frequency": "annual", "description": description + suffix} + for description, _ in tables + ] + monkeypatch.setattr(helpers, "get_international_portfolio_data", lambda *a, **k: "") + monkeypatch.setattr(helpers, "read_dat_file", lambda data: []) + monkeypatch.setattr( + helpers, + "process_international_portfolio_data", + lambda *a, **k: (dataframes, metadata), + ) + + dfs, dfs_meta = helpers.get_international_portfolio( + country="japan", + measure="local", + frequency="annual", + dividends=not suffix, + all_data_items_required=False, + ) + + assert [df["mkt"].iloc[0] for df in dfs] == [1.0] + assert [meta["description"] for meta in dfs_meta] == [ + "Value-Weight Local Returns All 4 Data Items Not Reqd" + suffix + ] + + def test_get_international_portfolio_ratios_monthly(monkeypatch): """The 'ratios' measure with monthly frequency raises ValueError.""" monkeypatch.setattr(helpers, "get_international_portfolio_data", lambda *a, **k: "")