s-ttp commited on
Commit
ee01cfc
·
verified ·
1 Parent(s): b6d55b9

Guidance basis label: only guidance rows with typed values (a trigger may cite a plain metric claim)

Browse files
engine/catalog.py CHANGED
@@ -576,11 +576,14 @@ def render_guidance(m, mode="value_only"):
576
  def guidance_basis_label(cat, cid):
577
  """'GAAP' / 'adjusted' when a guidance row has a sibling of the same concept on another basis with a different
578
  value (the basis then decides which figure is meant); None when the basis does not change the figure."""
579
- v = (cat.get(cid).value or {}) if cat.get(cid) is not None else {}
 
 
580
  if not v.get("concept"):
581
  return None
582
  sib = {(x.get("accounting_basis"), x.get("low"), x.get("high")) for x in
583
- ((c.value or {}) for k, c in cat.items() if k.startswith("GUIDANCE_")) if x.get("concept") == v["concept"]}
 
584
  if len({(lo, hi) for _b, lo, hi in sib}) > 1 and len({b for b, _lo, _hi in sib}) > 1:
585
  return {"GAAP": "GAAP", "ADJUSTED": "adjusted"}.get(v.get("accounting_basis"))
586
  return None
 
576
  def guidance_basis_label(cat, cid):
577
  """'GAAP' / 'adjusted' when a guidance row has a sibling of the same concept on another basis with a different
578
  value (the basis then decides which figure is meant); None when the basis does not change the figure."""
579
+ from collections.abc import Mapping
580
+ c0 = cat.get(cid) if str(cid or "").startswith("GUIDANCE_") else None # only a guidance row has a basis
581
+ v = c0.value if c0 is not None and isinstance(c0.value, Mapping) else {}
582
  if not v.get("concept"):
583
  return None
584
  sib = {(x.get("accounting_basis"), x.get("low"), x.get("high")) for x in
585
+ (c.value for k, c in cat.items() if k.startswith("GUIDANCE_") and isinstance(c.value, Mapping))
586
+ if x.get("concept") == v["concept"]}
587
  if len({(lo, hi) for _b, lo, hi in sib}) > 1 and len({b for b, _lo, _hi in sib}) > 1:
588
  return {"GAAP": "GAAP", "ADJUSTED": "adjusted"}.get(v.get("accounting_basis"))
589
  return None
engine/tests/test_spgi_relations.py CHANGED
@@ -1239,6 +1239,11 @@ def test_9_trigger_names_its_guidance_basis_and_composite_labels_its_inputs():
1239
  "GUIDANCE_3": _C({"concept": "REVENUE_GROWTH", "accounting_basis": "ADJUSTED", "low": 0.059, "high": 0.079})}
1240
  assert C.guidance_basis_label(cat, "GUIDANCE_9") == "GAAP" and C.guidance_basis_label(cat, "GUIDANCE_10") == "adjusted"
1241
  assert C.guidance_basis_label(cat, "GUIDANCE_2") is None # same figure on both bases
 
 
 
 
 
1242
  lab = RM._method_basis({"multiple_basis": "TRAILING_ADJUSTED", "raw_input_basis": "NTM adjusted EPS (x)"})
1243
  assert "next-12-month adjusted EPS" in lab and "trailing basis" in lab and not lab.startswith(" trailing")
1244
 
 
1239
  "GUIDANCE_3": _C({"concept": "REVENUE_GROWTH", "accounting_basis": "ADJUSTED", "low": 0.059, "high": 0.079})}
1240
  assert C.guidance_basis_label(cat, "GUIDANCE_9") == "GAAP" and C.guidance_basis_label(cat, "GUIDANCE_10") == "adjusted"
1241
  assert C.guidance_basis_label(cat, "GUIDANCE_2") is None # same figure on both bases
1242
+ # live f(1790537766): a trigger whose source is an ordinary metric claim (a float), not a guidance row
1243
+ cat["FORECAST_REVENUE_GROWTH"] = _C(0.068)
1244
+ cat["GUIDANCE_X"] = _C(0.05)
1245
+ assert C.guidance_basis_label(cat, "FORECAST_REVENUE_GROWTH") is None and C.guidance_basis_label(cat, "GUIDANCE_X") is None
1246
+ assert C.guidance_basis_label(cat, "GUIDANCE_9") == "GAAP"
1247
  lab = RM._method_basis({"multiple_basis": "TRAILING_ADJUSTED", "raw_input_basis": "NTM adjusted EPS (x)"})
1248
  assert "next-12-month adjusted EPS" in lab and "trailing basis" in lab and not lab.startswith(" trailing")
1249