unsupported operand type(s) for -: 'str' and 'float' at line 263 of financials.py
Issue Type
- [x ] Data Quality Issue (incorrect financial values, missing data)
- [ ] 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: (e.g., 5.4.0)
Python Version: 3.10.19
Operating System: Windows 11
Bug Description
What you expected to happen: A successful calculation
What actually happened: operating_cf is being passed as a string instead of float to line 263 of financials.py
Error message (if any):
TypeError: unsupported operand type(s) for -: 'str' and 'float'
Paste any error messages here
## Reproduction
**Company/Ticker:** (e.g., AAPL)
**Time Period:** (e.g., 2020-2023, Q4 2023)
**Relevant Forms:** (e.g., 10-K, 10-Q, 8-K)
**Minimal code to reproduce:**
from edgar import Company, set_identity import pandas as pd pd.set_option('display.max_columns', 4) set_identity("XXXXXXXXXXXXXX") company_ticker = "MSFT" # Example: Apple Inc. company = Company(company_ticker) financials = company.get_financials() metrics = financials.get_financial_metrics()
## 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.*
Thanks for the detailed bug report @miruddfan! I've reproduced and triaged this issue.
Classification: CRITICAL BUG
This is a critical bug that blocks core functionality and indicates a data type handling issue. Classifying for immediate point release 5.6.1.
Why critical:
- ✅ Core functionality blocked:
get_financial_metrics()cannot complete - ✅ Data accuracy concern: Type safety violation (string returned instead of numeric)
- ✅ No workaround available
- ✅ Affects fundamental use case for standardized financial data access
Root cause identified:
The helper method _get_standardized_concept_value() (line 113 in financials.py) returns the raw string value when numeric conversion fails, instead of returning None. This violates the type contract and causes arithmetic operations downstream to fail.
# Current broken code (line 113)
except (ValueError, TypeError):
return value # ❌ Returns string on conversion failure
# Should be:
except (ValueError, TypeError):
return None # ✅ Respect type contract
Timeline: Fix in progress, targeting 4-6 hours for point release v5.6.1 to PyPI.
Tracking: Beads issue edgartools-l3yz created with P0 priority, ROADMAP updated for point release planning.
Will keep you updated on progress!
Fixed in commit f0886207.
Root cause: _get_standardized_concept_value() returned empty string when a pattern matched a row with no value (e.g., 'Adjustments to reconcile...' row), causing TypeError in arithmetic operations.
Fix:
- Skip empty/NA values and continue to next pattern
- Improved operating cash flow patterns to prioritize totals over adjustment headers
Thanks for reporting @miruddfan!