Datasets:
Update the industry classification
Browse files- data/by_ticker/part-00000.parquet +1 -1
- data/classification/part-00000.parquet +1 -1
- data/naics_map/part-00000.parquet +1 -1
- data/observations/part-00000.parquet +1 -1
- data/sic_codes/part-00000.parquet +1 -1
- data/spans/part-00000.parquet +1 -1
- data/taxonomy/part-00000.parquet +1 -1
- jobs/run.py +7 -1
- manifest.json +2 -2
- recipe/sources.py +33 -7
- tests/test_sources.py +14 -18
data/by_ticker/part-00000.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 727024
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:549f85cfe3ef4025adb81dbe9f2c5b75a6d7befdd9d0b46aa8353115ec67baaf
|
| 3 |
size 727024
|
data/classification/part-00000.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 830399
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:43772ae97083bd4586d02bc44b18eb16033d1cdfeb30fe3e20b4ef39e4d8daec
|
| 3 |
size 830399
|
data/naics_map/part-00000.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 67201
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:eb8a74e0bdb486e698d99925da16818ba7772ee662935db6dcfbb8e12c727217
|
| 3 |
size 67201
|
data/observations/part-00000.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 6255799
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:75da0ea036cb36c572ad2ebba6b8997b273465d49bb052ad53155a1e1e6ca7c2
|
| 3 |
size 6255799
|
data/sic_codes/part-00000.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 29383
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c9005bb8f4f2f496d1e8cdb6d1be4272220f4575d432f7497ce406e7fb67a957
|
| 3 |
size 29383
|
data/spans/part-00000.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 270249
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5acee064ee42b65f13d97166246b25e44ac39e34b27ce592d1ffb1a1c0520735
|
| 3 |
size 270249
|
data/taxonomy/part-00000.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 6420
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b02de6ba1db8afb9bac035f6200ed6c0ae28dcdfe1b9583101a4828b68a1fafa
|
| 3 |
size 6420
|
jobs/run.py
CHANGED
|
@@ -48,7 +48,13 @@ def restore_repository(repo_id: str, token: str | None, workspace: Path) -> Path
|
|
| 48 |
# Only the recipe and tests are needed: every table is rebuilt from
|
| 49 |
# the sources each run, so restoring the data would download tens of
|
| 50 |
# megabytes to overwrite them.
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
)
|
| 53 |
log(f"restored {repo_id} into {workspace}")
|
| 54 |
except RepositoryNotFoundError:
|
|
|
|
| 48 |
# Only the recipe and tests are needed: every table is rebuilt from
|
| 49 |
# the sources each run, so restoring the data would download tens of
|
| 50 |
# megabytes to overwrite them.
|
| 51 |
+
# LICENSE and NOTICE have no extension, so they need naming: the
|
| 52 |
+
# tests read NOTICE, and a restore that skipped it failed the job
|
| 53 |
+
# before anything was fetched.
|
| 54 |
+
allow_patterns=[
|
| 55 |
+
"recipe/**", "tests/**", "jobs/**",
|
| 56 |
+
"*.md", "*.json", "*.toml", "LICENSE", "NOTICE",
|
| 57 |
+
],
|
| 58 |
)
|
| 59 |
log(f"restored {repo_id} into {workspace}")
|
| 60 |
except RepositoryNotFoundError:
|
manifest.json
CHANGED
|
@@ -163,7 +163,7 @@
|
|
| 163 |
"max_statement": "2026-10-13",
|
| 164 |
"min_statement": "2009-04-15"
|
| 165 |
},
|
| 166 |
-
"generated_at": "2026-10-
|
| 167 |
"industries": {
|
| 168 |
"CONC_AUTO": {
|
| 169 |
"sector": "CONC",
|
|
@@ -548,7 +548,7 @@
|
|
| 548 |
"source": {
|
| 549 |
"build_version": "1.0.0",
|
| 550 |
"package_version": "1.0.0",
|
| 551 |
-
"recipe_hash": "sha256:
|
| 552 |
"taxonomy_version": "1.0.0"
|
| 553 |
}
|
| 554 |
}
|
|
|
|
| 163 |
"max_statement": "2026-10-13",
|
| 164 |
"min_statement": "2009-04-15"
|
| 165 |
},
|
| 166 |
+
"generated_at": "2026-10-13T20:02:11.096197+00:00",
|
| 167 |
"industries": {
|
| 168 |
"CONC_AUTO": {
|
| 169 |
"sector": "CONC",
|
|
|
|
| 548 |
"source": {
|
| 549 |
"build_version": "1.0.0",
|
| 550 |
"package_version": "1.0.0",
|
| 551 |
+
"recipe_hash": "sha256:ed2bf8d7a99d9f87ff829fcb67f9908fa595d4b0586f937a72c1d36478b2eaa6",
|
| 552 |
"taxonomy_version": "1.0.0"
|
| 553 |
}
|
| 554 |
}
|
recipe/sources.py
CHANGED
|
@@ -459,8 +459,38 @@ async def fetch_concordance(cache_dir: Path) -> bytes:
|
|
| 459 |
return payload
|
| 460 |
|
| 461 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 462 |
def parse_concordance(payload: bytes) -> tuple[pl.DataFrame, dict[str, str], list[str]]:
|
| 463 |
-
"""The crosswalk, the major group titles, and the division titles in order.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 464 |
|
| 465 |
One file answers three questions because of how it is laid out: a row with
|
| 466 |
no SIC is a division heading, a two-digit SIC is a major group heading, and
|
|
@@ -469,12 +499,6 @@ def parse_concordance(payload: bytes) -> tuple[pl.DataFrame, dict[str, str], lis
|
|
| 469 |
the agency that maintains the classification rather than being typed in
|
| 470 |
here from a manual.
|
| 471 |
"""
|
| 472 |
-
import io
|
| 473 |
-
|
| 474 |
-
frame = pl.read_excel(io.BytesIO(payload), has_header=True, infer_schema_length=0)
|
| 475 |
-
if frame.width < 5:
|
| 476 |
-
raise RuntimeError(f"concordance has {frame.width} columns, expected 5")
|
| 477 |
-
frame.columns = ["sic", "part", "title", "naics", "naics_title"][: frame.width]
|
| 478 |
frame = frame.with_columns(pl.col("sic").str.strip_chars())
|
| 479 |
|
| 480 |
divisions = [
|
|
@@ -531,8 +555,10 @@ __all__ = [
|
|
| 531 |
"from_fundamental_filings",
|
| 532 |
"issuers",
|
| 533 |
"parse_concordance",
|
|
|
|
| 534 |
"parse_sic_list",
|
| 535 |
"read_bulk_sic",
|
|
|
|
| 536 |
"sibling_frame",
|
| 537 |
"sibling_path",
|
| 538 |
"submissions_snapshot",
|
|
|
|
| 459 |
return payload
|
| 460 |
|
| 461 |
|
| 462 |
+
CONCORDANCE_COLUMNS = ("sic", "part", "title", "naics", "naics_title")
|
| 463 |
+
|
| 464 |
+
|
| 465 |
+
def read_concordance_sheet(payload: bytes) -> pl.DataFrame:
|
| 466 |
+
"""The workbook's single sheet, every cell a string.
|
| 467 |
+
|
| 468 |
+
A 2008-vintage .xls, which only a BIFF-capable reader opens; polars
|
| 469 |
+
delegates to one. Kept apart from the parsing below so that the parsing
|
| 470 |
+
can be tested without a spreadsheet writer in the loop -- the first
|
| 471 |
+
version built a workbook in its fixtures and passed locally only because
|
| 472 |
+
`xlsxwriter` happened to be installed, then failed in the job.
|
| 473 |
+
"""
|
| 474 |
+
import io
|
| 475 |
+
|
| 476 |
+
frame = pl.read_excel(io.BytesIO(payload), has_header=True, infer_schema_length=0)
|
| 477 |
+
if frame.width < len(CONCORDANCE_COLUMNS):
|
| 478 |
+
raise RuntimeError(
|
| 479 |
+
f"concordance has {frame.width} columns, expected {len(CONCORDANCE_COLUMNS)}"
|
| 480 |
+
)
|
| 481 |
+
frame.columns = list(CONCORDANCE_COLUMNS)[: frame.width]
|
| 482 |
+
return frame
|
| 483 |
+
|
| 484 |
+
|
| 485 |
def parse_concordance(payload: bytes) -> tuple[pl.DataFrame, dict[str, str], list[str]]:
|
| 486 |
+
"""The crosswalk, the major group titles, and the division titles in order."""
|
| 487 |
+
return parse_concordance_frame(read_concordance_sheet(payload))
|
| 488 |
+
|
| 489 |
+
|
| 490 |
+
def parse_concordance_frame(
|
| 491 |
+
frame: pl.DataFrame,
|
| 492 |
+
) -> tuple[pl.DataFrame, dict[str, str], list[str]]:
|
| 493 |
+
"""Separate the hierarchy from the crosswalk.
|
| 494 |
|
| 495 |
One file answers three questions because of how it is laid out: a row with
|
| 496 |
no SIC is a division heading, a two-digit SIC is a major group heading, and
|
|
|
|
| 499 |
the agency that maintains the classification rather than being typed in
|
| 500 |
here from a manual.
|
| 501 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 502 |
frame = frame.with_columns(pl.col("sic").str.strip_chars())
|
| 503 |
|
| 504 |
divisions = [
|
|
|
|
| 555 |
"from_fundamental_filings",
|
| 556 |
"issuers",
|
| 557 |
"parse_concordance",
|
| 558 |
+
"parse_concordance_frame",
|
| 559 |
"parse_sic_list",
|
| 560 |
"read_bulk_sic",
|
| 561 |
+
"read_concordance_sheet",
|
| 562 |
"sibling_frame",
|
| 563 |
"sibling_path",
|
| 564 |
"submissions_snapshot",
|
tests/test_sources.py
CHANGED
|
@@ -5,7 +5,7 @@ from __future__ import annotations
|
|
| 5 |
import polars as pl
|
| 6 |
|
| 7 |
from recipe.sic import DIVISIONS
|
| 8 |
-
from recipe.sources import
|
| 9 |
|
| 10 |
|
| 11 |
class _FakePage:
|
|
@@ -48,17 +48,21 @@ async def test_sic_list_refuses_a_page_that_lost_its_table():
|
|
| 48 |
raise AssertionError("a three-row page should not have been accepted")
|
| 49 |
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
CONCORDANCE = pl.DataFrame(
|
| 52 |
{
|
| 53 |
-
"
|
| 54 |
-
"
|
| 55 |
-
"
|
| 56 |
"Manufacturing", "Chemicals and allied products", "Pharmaceutical Preparations",
|
| 57 |
". Vaccines", ". Other", "Nonclassifiable establishments",
|
| 58 |
"Nonclassifiable", "Nonclassifiable Establishments",
|
| 59 |
],
|
| 60 |
-
"
|
| 61 |
-
"
|
| 62 |
None, None, "Pharmaceutical Preparation Manufacturing",
|
| 63 |
"Biological Product Manufacturing", "Medicinal and Botanical Manufacturing",
|
| 64 |
None, None, "Unclassified Establishments",
|
|
@@ -67,16 +71,8 @@ CONCORDANCE = pl.DataFrame(
|
|
| 67 |
)
|
| 68 |
|
| 69 |
|
| 70 |
-
def _workbook() -> bytes:
|
| 71 |
-
import io
|
| 72 |
-
|
| 73 |
-
buffer = io.BytesIO()
|
| 74 |
-
CONCORDANCE.write_excel(buffer)
|
| 75 |
-
return buffer.getvalue()
|
| 76 |
-
|
| 77 |
-
|
| 78 |
def test_concordance_separates_hierarchy_from_crosswalk():
|
| 79 |
-
crosswalk, major_groups, divisions =
|
| 80 |
assert divisions == ["Manufacturing", "Nonclassifiable establishments"]
|
| 81 |
assert major_groups["28"] == "Chemicals and allied products"
|
| 82 |
# Supplied here because the Census file never prints a header row for them.
|
|
@@ -85,7 +81,7 @@ def test_concordance_separates_hierarchy_from_crosswalk():
|
|
| 85 |
|
| 86 |
|
| 87 |
def test_a_split_industry_keeps_every_candidate():
|
| 88 |
-
crosswalk, _, _ =
|
| 89 |
split = crosswalk.filter(pl.col("sic") == "2836")
|
| 90 |
assert split.height == 2
|
| 91 |
assert split["is_part"].to_list() == [True, True]
|
|
@@ -104,8 +100,8 @@ def test_division_ranges_are_ordered_and_do_not_overlap():
|
|
| 104 |
previous_high = high
|
| 105 |
|
| 106 |
|
| 107 |
-
def
|
| 108 |
-
_, _, divisions =
|
| 109 |
assert len(set(divisions)) == len(divisions)
|
| 110 |
assert divisions[0] == "Manufacturing"
|
| 111 |
|
|
|
|
| 5 |
import polars as pl
|
| 6 |
|
| 7 |
from recipe.sic import DIVISIONS
|
| 8 |
+
from recipe.sources import parse_concordance_frame
|
| 9 |
|
| 10 |
|
| 11 |
class _FakePage:
|
|
|
|
| 48 |
raise AssertionError("a three-row page should not have been accepted")
|
| 49 |
|
| 50 |
|
| 51 |
+
# The sheet as the reader hands it over: every cell a string, columns already
|
| 52 |
+
# named. Built directly rather than round-tripped through a spreadsheet, so
|
| 53 |
+
# the tests need no Excel writer -- the first version did, and passed here
|
| 54 |
+
# while failing in the job, where `xlsxwriter` is not installed.
|
| 55 |
CONCORDANCE = pl.DataFrame(
|
| 56 |
{
|
| 57 |
+
"sic": [None, "28", "2834", "2836", "2836", None, "99", "9999"],
|
| 58 |
+
"part": [None, None, None, "pt", "pt", None, None, None],
|
| 59 |
+
"title": [
|
| 60 |
"Manufacturing", "Chemicals and allied products", "Pharmaceutical Preparations",
|
| 61 |
". Vaccines", ". Other", "Nonclassifiable establishments",
|
| 62 |
"Nonclassifiable", "Nonclassifiable Establishments",
|
| 63 |
],
|
| 64 |
+
"naics": [None, None, "325412", "325414", "325411", None, None, "99999"],
|
| 65 |
+
"naics_title": [
|
| 66 |
None, None, "Pharmaceutical Preparation Manufacturing",
|
| 67 |
"Biological Product Manufacturing", "Medicinal and Botanical Manufacturing",
|
| 68 |
None, None, "Unclassified Establishments",
|
|
|
|
| 71 |
)
|
| 72 |
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
def test_concordance_separates_hierarchy_from_crosswalk():
|
| 75 |
+
crosswalk, major_groups, divisions = parse_concordance_frame(CONCORDANCE)
|
| 76 |
assert divisions == ["Manufacturing", "Nonclassifiable establishments"]
|
| 77 |
assert major_groups["28"] == "Chemicals and allied products"
|
| 78 |
# Supplied here because the Census file never prints a header row for them.
|
|
|
|
| 81 |
|
| 82 |
|
| 83 |
def test_a_split_industry_keeps_every_candidate():
|
| 84 |
+
crosswalk, _, _ = parse_concordance_frame(CONCORDANCE)
|
| 85 |
split = crosswalk.filter(pl.col("sic") == "2836")
|
| 86 |
assert split.height == 2
|
| 87 |
assert split["is_part"].to_list() == [True, True]
|
|
|
|
| 100 |
previous_high = high
|
| 101 |
|
| 102 |
|
| 103 |
+
def test_concordance_divisions_are_distinct():
|
| 104 |
+
_, _, divisions = parse_concordance_frame(CONCORDANCE)
|
| 105 |
assert len(set(divisions)) == len(divisions)
|
| 106 |
assert divisions[0] == "Manufacturing"
|
| 107 |
|