edgartools icon indicating copy to clipboard operation
edgartools copied to clipboard

Notes often not being parsed

Open mpreiss9 opened this issue 3 weeks ago • 2 comments

Issue Type

  • [ ] Data Quality Issue (incorrect financial values, missing data)
  • [ X] XBRL Parsing Issue (statement rendering, concept mapping)
  • [ ] Filing Access Issue (download failures, attachment problems)
  • [ ] Performance Issue (slow operations, memory problems)
  • [ ] Compatibility Issue (platform/dependency conflicts)
  • [ ] Documentation Issue (unclear instructions, missing examples)

Environment

EdgarTools Version: 6.0.0 Python Version: 3.15 Operating System: macos Pandas: 3.1.1

Bug Description

When Notes contain tables of data under yearly column headings, I would expect this to get parsed to produce a proper dataframe What actually happened: This happens inconsistently. On some notes all the entire note with text and financial data is stuffed into the value field as a string. The behavior is inconsistent even for the same ticker in different years. For example, COST Leases note in FY 2021 is correctly parsed but the other years aren't

Error message (if any):

Paste any error messages here

Reproduction

Company/Ticker: (e.g., COST) Time Period: (e.g., any recent filing) Compare with 2021 which parses at at least some notes properly Relevant Forms: 10-K

Minimal code to reproduce:

Minimal repro: edgartools XBRL.notes() -> note.to_dataframe()

Problem: for some filings, a note's DATED column (e.g. '2021-08-29 (FY)')
contains the whole note as one big TEXT string instead of a column of
numbers, while the other year columns are empty.

This script does NOT do any post-processing. It runs the last 10 filings,
prints each filing's fiscal year, and for each note dumps ONLY the
date-like columns (labelled), showing a numeric/string/null tally and the
raw cell contents — so text-stuffed-where-numbers-should-be is obvious.

Run:  python repro_edgar_notes.py
"""
import importlib.metadata
import re

import pandas as pd
from edgar import Company, set_identity

# ---------------------------------------------------------------------------
# Fill these in to reproduce your exact case
# ---------------------------------------------------------------------------
set_identity("Your Name [email protected]")  # REQUIRED by SEC

TICKER = "COST"        # ticker that reproduces it
FORM = "10-K"          # form
COUNT = 10             # how many most-recent filings to run
ONLY_TITLE = "Leases"  # only print this note
# ---------------------------------------------------------------------------

print("edgartools", importlib.metadata.version("edgartools"))
print("pandas    ", importlib.metadata.version("pandas"))

DATE_RE = re.compile(r"\d{4}-\d{2}-\d{2}")  # matches '2021-08-29 (FY)'
CUT = 120          # min chars to call a string "suspicious"
NEWLINES = 2       # min newlines to call a string "suspicious"
MAX_ROWS = 20      # max rows to dump per date column


def tally(col):
    n_null = n_num = n_str = 0
    for v in col:
        if pd.isna(v):
            n_null += 1
        elif isinstance(v, (int, float)) and not isinstance(v, bool):
            n_num += 1
        else:
            n_str += 1
    return n_num, n_str, n_null


company = Company(TICKER)
filings = company.get_filings(form=FORM).latest(COUNT)

for fi, filing in enumerate(filings):
    xbrl = filing.xbrl()
    if xbrl is None:
        print(f"\n[{fi}] skipping: no XBRL")
        continue

    # Fiscal year of this filing, printed so we can see which years are affected
    fiscal_year = xbrl.entity_info.get("fiscal_year")

    print("\n" + "#" * 90)
    print(f"# FILING {fi}: fiscal_year={fiscal_year}   period_of_report={filing.report_date}")
    print("#" * 90)

    for i, note in enumerate(xbrl.notes()):
        if getattr(note, "canonical_type", None):
            continue  # skip primary statements (BS/IS/CF)
        title = note.role_or_type.split("/")[-1]
        if ONLY_TITLE and ONLY_TITLE not in title:
            continue

        df = note.to_dataframe()
        print("\n" + "=" * 90)
        print(f"    [{i}] note   : {title}")
        print(f"         shape  : {df.shape}")
        print(f"         columns: {list(df.columns)}")

        # Only inspect columns whose name looks like a date, e.g. '2021-08-29 (FY)'
        date_cols = [c for c in df.columns if DATE_RE.search(str(c))]
        if not date_cols:
            print("         (no date-like columns found)")
            continue

        for c in date_cols:
            col = df[c]
            n_num, n_str, n_null = tally(col)
            print(f"\n         COLUMN {c!r}   dtype={col.dtype}   "
                  f"numeric={n_num}  string={n_str}  null={n_null}")
            for row_no, (idx, val) in enumerate(col.items()):
                if row_no >= MAX_ROWS:
                    print(f"            ... ({len(col) - MAX_ROWS} more rows)")
                    break
                if pd.isna(val):
                    print(f"            [{idx}] <NA>")
                elif isinstance(val, str) and (len(val) > CUT or val.count("\n") > NEWLINES):
                    print(f"            [{idx}] !!! STUFFED TEXT "
                          f"({len(val)} chars, {val.count(chr(10)) + 1} lines):")
                    for ln in val.splitlines():
                        print("                    | " + ln)
                else:
                    s = repr(val)
                    print(f"            [{idx}] {s[:77]}{'...' if len(s) > 77 else ''}")
                    

Additional Context

Add any other context about the problem here. Screenshots, related issues, etc.


This issue will be handled using EdgarTools' systematic issue resolution workflow. A reproduction test will be created to verify the fix.

mpreiss9 avatar Nov 12 '26 20:11 mpreiss9

Thanks for the detailed repro script, it made this quick to pin down. I reproduced it on 6.1.0 and the cause is that xbrl.notes() isn't where the numbers live.

In XBRL each note is filed as several roles. The note itself ("Leases") and its tables role ("Leases (Tables)") are text blocks, so every fact in them is a block of HTML, and to_dataframe() hands you that text in the period column. The numeric tables are filed as separate "(Details)" roles, and those are classified as disclosures, not notes, so xbrl.notes() never returns them.

2021 looked right by accident. That year COST's detail roles were titled without the "(Details)" suffix ("Leases, Future Minimum Payments"), so two of them were misclassified as notes and showed up in your loop. From 2022 on they carry the suffix and drop out. That misclassification is a bug on my side (one 2021 role even lands as a cover page), and I'm tracking it separately.

The way to get the numbers is through the note's details, which groups the roles the way the filing's own R-file menu does:

from edgar import find

tenk = find("0000909832-24-000049").obj()   # COST 10-K, FY2024
leases = tenk.notes["Leases"]
for detail in leases.details:
    print(detail.role_or_type.split("/")[-1])
    df = detail.to_dataframe()

For FY2024 that gives four tables, and "Components of Lease Expense" comes back numeric: operating lease cost $284M, $309M and $297M for FY2024, 2023 and 2022. leases.text gives you the narrative, and xbrl.disclosures() lists every detail role if you'd rather filter yourself.

FY2021 is the exception until the classification fix lands: tenk.notes["Leases"].details comes back empty for that filing, because the detail roles are filed as notes of their own. Use tenk.notes["Leases, Future Minimum Payments"] and tenk.notes["Leases, Supplemental Cash Flow Information"] directly, and the balance sheet table is in xbrl.disclosures(). Components of Lease Expense is the one that ends up as a cover page, so for 2021 it's only in the "Leases" note's text for now.

I'll leave this open until the 2021 classification is fixed. I'd also like to_dataframe() on a text-block note to say what it is rather than quietly returning a wall of text.

dgunning avatar Nov 13 '26 20:11 dgunning

Quick update: the 2021 fix is up in #1961.

The cause turned out to be one step earlier than I said. SEC's own FilingSummary.xml for that filing files the lease detail tables under the wrong menu headings (Components of Lease Expense under Cover, two others under Notes), and I was taking that menu at its word. I now override it when a role's content says it's a detail table: it has amounts and no text block.

Once that's merged and released, tenk.notes["Leases"].details returns all four tables for FY2021 as it does for later years, so you won't need the workaround from my last comment. On FY2021, Components of Lease Expense comes back with operating lease cost of $296M and $252M for FY2021 and FY2020.

I checked the change against 111 10-Ks from 37 companies to make sure it doesn't move anything else, and it only touches those Costco roles. The to_dataframe() change for text-block notes is a separate piece of work I'll follow up on.

dgunning avatar Nov 13 '26 21:11 dgunning