@@ -51,9 +51,7 @@ def detect_type(
5151 if is_financial :
5252 return "financial"
5353
54- has_cogs = any (
55- s in company_tags and _has_recent_data (facts , s ) for s in industrial_signals
56- )
54+ has_cogs = any (s in company_tags and _has_recent_data (facts , s ) for s in industrial_signals )
5755
5856 if has_cogs :
5957 return "industrial"
@@ -106,45 +104,28 @@ def get_filing_dates( # noqa: PLR0912
106104 if not start or not end or start == end :
107105 continue
108106 try :
109- days = (
110- datetime .strptime (end , "%Y-%m-%d" )
111- - datetime .strptime (start , "%Y-%m-%d" )
112- ).days
107+ days = (datetime .strptime (end , "%Y-%m-%d" ) - datetime .strptime (start , "%Y-%m-%d" )).days
113108 except (ValueError , TypeError ):
114109 continue
115110
116111 if frequency == "annual" :
117112 if form in ANNUAL_PERIOD_FORMS and 300 <= days <= 400 :
118113 filing_dates .add (end )
119- elif (
120- include_preliminary
121- and form in PRELIMINARY_FORMS
122- and 300 <= days <= 400
123- ):
114+ elif include_preliminary and form in PRELIMINARY_FORMS and 300 <= days <= 400 :
124115 preliminary_candidates .add (end )
125116 else :
126117 if form in QUARTERLY_FORMS and 60 <= days <= 135 :
127118 filing_dates .add (end )
128- if form in SEMI_ANNUAL_FORMS and (
129- 60 <= days <= 135
130- or 150 <= days <= 200
131- or 240 <= days <= 310
132- ):
119+ if form in SEMI_ANNUAL_FORMS and (60 <= days <= 135 or 150 <= days <= 200 or 240 <= days <= 310 ):
133120 filing_dates .add (end )
134- if (
135- include_preliminary
136- and form in PRELIMINARY_FORMS
137- and 60 <= days <= 135
138- ):
121+ if include_preliminary and form in PRELIMINARY_FORMS and 60 <= days <= 135 :
139122 preliminary_candidates .add (end )
140123
141124 if include_preliminary :
142125 filing_dates |= preliminary_candidates - filing_dates
143126
144127 if frequency != "annual" and filing_dates :
145- canonical_annual = get_filing_dates (
146- facts , "annual" , include_preliminary = include_preliminary
147- )
128+ canonical_annual = get_filing_dates (facts , "annual" , include_preliminary = include_preliminary )
148129 interim_dates = filing_dates - canonical_annual
149130
150131 # Discontinuity guard: if interim reporting has lapsed — the most
@@ -157,19 +138,15 @@ def get_filing_dates( # noqa: PLR0912
157138 latest_interim = max (interim_dates )
158139 try :
159140 lapse = (
160- datetime .strptime (latest_annual , "%Y-%m-%d" )
161- - datetime .strptime (latest_interim , "%Y-%m-%d" )
141+ datetime .strptime (latest_annual , "%Y-%m-%d" ) - datetime .strptime (latest_interim , "%Y-%m-%d" )
162142 ).days
163143 except (ValueError , TypeError ):
164144 lapse = 0
165145 if lapse > 460 :
166146 return set ()
167147
168148 # Fold a fiscal year-end into the quarterly series only when that
169- # fiscal year actually has at least one interim period. Foreign
170- # private issuers (6-K filers) often report annual results for many
171- # years but interim results for only a few; without this guard those
172- # annual-only years would surface as phantom standalone Q4/H2 rows.
149+ # fiscal year actually has at least one interim period.
173150 sorted_annual = sorted (canonical_annual )
174151 for i , annual_end in enumerate (sorted_annual ):
175152 fy_start = sorted_annual [i - 1 ] if i else ""
@@ -247,11 +224,7 @@ def get_filing_dates( # noqa: PLR0912
247224
248225 for entries in assets_data .get ("units" , {}).values ():
249226 for entry in entries :
250- if (
251- entry .get ("form" , "" ) in assets_forms
252- and entry .get ("end" ) == earliest
253- and not entry .get ("start" )
254- ):
227+ if entry .get ("form" , "" ) in assets_forms and entry .get ("end" ) == earliest and not entry .get ("start" ):
255228 has_assets = True
256229 break
257230
@@ -312,40 +285,23 @@ def get_fiscal_meta( # noqa: PLR0912
312285 if end not in best_quarterly or filed < best_quarterly [end ][0 ]:
313286 best_quarterly [end ] = (filed , fy , fp )
314287 elif form in SEMI_ANNUAL_FORMS :
315- # A 6-K can carry quarterly, semi-annual, or full-year
316- # periods. Classify by the period's duration so
317- # quarterly 6-K reporting is not collapsed to
318- # semi-annual. The 6-K fy field is unreliable for
319- # foreign private issuers (comparatives carry the
320- # filing-context year), so align the *fiscal* year and
321- # quarter to the company's fiscal year-end and prefer
322- # the SEC-reported fiscal period (fp) for the label.
288+ # A 6-K can carry quarterly, semi-annual, or full-year periods.
323289 start = entry .get ("start" , "" )
324290 days = None
325291 if start and start != end :
326292 try :
327- days = (
328- datetime .strptime (end , "%Y-%m-%d" )
329- - datetime .strptime (start , "%Y-%m-%d" )
330- ).days
293+ days = (datetime .strptime (end , "%Y-%m-%d" ) - datetime .strptime (start , "%Y-%m-%d" )).days
331294 except (ValueError , TypeError ):
332295 days = None
333296 end_month = int (end [5 :7 ])
334- fis_year = (
335- int (end [:4 ]) if end_month <= fye_month else int (end [:4 ]) + 1
336- )
297+ fis_year = int (end [:4 ]) if end_month <= fye_month else int (end [:4 ]) + 1
337298 fis_q = f"Q{ ((end_month - fye_month - 1 ) % 12 ) // 3 + 1 } "
338299 q_label = fp if fp .startswith ("Q" ) else fis_q
339300 if days is not None and 300 <= days <= 400 :
340301 if end not in best_annual or filed < best_annual [end ][0 ]:
341302 best_annual [end ] = (filed , fis_year , "FY" )
342- elif days is not None and (
343- 60 <= days <= 135 or 240 <= days <= 310
344- ):
345- if (
346- end not in best_quarterly
347- or filed < best_quarterly [end ][0 ]
348- ):
303+ elif days is not None and (60 <= days <= 135 or 240 <= days <= 310 ):
304+ if end not in best_quarterly or filed < best_quarterly [end ][0 ]:
349305 best_quarterly [end ] = (filed , fis_year , q_label )
350306 elif days is not None and 150 <= days <= 200 :
351307 if end not in best_semi or filed < best_semi [end ][0 ]:
@@ -357,10 +313,7 @@ def get_fiscal_meta( # noqa: PLR0912
357313 best_instant [end ] = (filed , fis_year , q_label )
358314 elif form in PRELIMINARY_FORMS :
359315 if fy is not None and fp :
360- if (
361- end not in best_preliminary
362- or filed < best_preliminary [end ][0 ]
363- ):
316+ if end not in best_preliminary or filed < best_preliminary [end ][0 ]:
364317 best_preliminary [end ] = (filed , fy , fp )
365318 elif end not in best_preliminary :
366319 month = int (end [5 :7 ])
@@ -431,11 +384,7 @@ def get_fiscal_meta( # noqa: PLR0912
431384 annual_set = set (annual_dates )
432385
433386 for i , date in enumerate (sorted_dates ):
434- if (
435- date in annual_set
436- and result [date ]["fiscal_period" ] in ("Q4" , "H2" )
437- and i > 0
438- ):
387+ if date in annual_set and result [date ]["fiscal_period" ] in ("Q4" , "H2" ) and i > 0 :
439388 prev = sorted_dates [i - 1 ]
440389 prev_meta = result [prev ]
441390 if prev_meta ["fiscal_period" ] in ("Q1" , "Q2" , "Q3" , "H1" ):
@@ -459,7 +408,6 @@ def detect_reporting_currency(facts: dict[str, Any]) -> str:
459408 for ns_facts in facts .values ():
460409 for tag_data in ns_facts .values ():
461410 for unit_key in tag_data .get ("units" , {}):
462-
463411 if unit_key in skip or "/" in unit_key :
464412 continue
465413
0 commit comments