Datasets:
Download tests/conftest.py from ZipLime/industry-classification: direct link, hf CLI and curl.
- Browser
- Download file 3.03 kB
-
https://huggingface.co/datasets/ZipLime/industry-classification/resolve/main/tests/conftest.py
- Command line
-
hf download hf://datasets/ZipLime/industry-classification/tests/conftest.py
-
curl -L -o conftest.py https://huggingface.co/datasets/ZipLime/industry-classification/resolve/main/tests/conftest.py
3.03 kB
| from __future__ import annotations | |
| import sys | |
| from datetime import UTC, date, datetime | |
| from pathlib import Path | |
| import polars as pl | |
| import pytest | |
| ROOT = Path(__file__).resolve().parents[1] | |
| if str(ROOT) not in sys.path: | |
| sys.path.insert(0, str(ROOT)) | |
| def statement(cik, sic, day, *, source="xbrl", ref="acc-1", dated=True): | |
| return { | |
| "cik": cik, "sic": sic, "stated_on": day, | |
| "knowledge_time": datetime.combine(day, datetime.min.time(), tzinfo=UTC), | |
| "source": source, "source_ref": ref, "is_dated": dated, | |
| "inserted_at": datetime.now(UTC), | |
| } | |
| def observations() -> pl.DataFrame: | |
| """A de-SPAC, a steady company, and a filer EDGAR only knows about today. | |
| Filer 1 is the case the point-in-time columns exist for: it filed as a | |
| blank check, merged with a car maker and was reclassified. A dataset that | |
| stated only today's code would put an automotive sector on its 2020 | |
| filings, when it was an empty shell. | |
| """ | |
| rows = [ | |
| statement("0000000001", "6770", date(2020, 3, 2), ref="a1"), | |
| statement("0000000001", "6770", date(2020, 8, 2), ref="a2"), | |
| statement("0000000001", "3711", date(2021, 5, 2), ref="a3"), | |
| statement("0000000001", "3711", date(2024, 5, 2), ref="a4"), | |
| statement("0000000002", "2834", date(2012, 1, 5), ref="b1"), | |
| statement("0000000002", "2834", date(2023, 1, 5), ref="b2"), | |
| statement("0000000003", "6022", date(2026, 10, 1), source="submissions", | |
| ref="CIK0000000003.json", dated=False), | |
| ] | |
| return pl.DataFrame(rows) | |
| def tickers() -> pl.DataFrame: | |
| """Ticker spans as the security master publishes them.""" | |
| return pl.DataFrame([ | |
| {"cik": "0000000001", "ticker": "SPAC", "valid_from": date(2020, 3, 2), | |
| "valid_to": date(2021, 2, 1), "is_current": False}, | |
| {"cik": "0000000001", "ticker": "CARZ", "valid_from": date(2021, 5, 2), | |
| "valid_to": date(2024, 5, 2), "is_current": True}, | |
| {"cik": "0000000002", "ticker": "PILL", "valid_from": date(2012, 1, 5), | |
| "valid_to": date(2023, 1, 5), "is_current": True}, | |
| # Delisted in 2007: the only code EDGAR holds for it is today's. | |
| {"cik": "0000000003", "ticker": "GONE", "valid_from": date(2006, 4, 1), | |
| "valid_to": date(2007, 9, 1), "is_current": False}, | |
| # A filer nothing knows a code for at all. | |
| {"cik": "0000000004", "ticker": "HUH", "valid_from": date(2011, 1, 1), | |
| "valid_to": date(2012, 1, 1), "is_current": False}, | |
| ]) | |
| def directory() -> pl.DataFrame: | |
| return pl.DataFrame([ | |
| {"cik": f"000000000{n}", "name": name, "primary_ticker": ticker, | |
| "all_tickers": ticker, "exchange": "NYSE", "is_active": active, | |
| "first_seen": date(2006, 1, 1)} | |
| for n, name, ticker, active in ( | |
| (1, "Car Co", "CARZ", True), (2, "Pill Co", "PILL", True), | |
| (3, "Gone Co", "GONE", False), (4, "Huh Co", "HUH", False), | |
| ) | |
| ]) | |